Quantcast
Channel: OpenEnergyMonitor aggregator
Viewing all articles
Browse latest Browse all 328

mharizanov: Presence detection using phone’s WiFi and Node-RED

$
0
0

Nathan tweeted a cool idea couple months ago, use static IP lease for your phone, ping it every minute to see if it responds, and if the ping times out that most probably means that the phone and his owner are not at home:

nathan_tweet

I found ~15 minutes to implement this today in Node-RED, couldn’t be any easier.

Since I always carry my phone with me, this is pretty reliable method of determining my presence at home.

I only needed to ensure that my phone receives a static IP lease, pretty trivial task for most modern wifi routers, you just need to find out you phone’s MAC address. I have WiFi on my phone always on.

Here is just how easy this is to do with Node-RED:

presence_flow

The ping node is set to ping the fixed internal IP address of my Nexus 5 phone every 60 seconds.

Just to be on the sure side, I extended the criteria to three consecutive ping fails:

presence_flow_analyze_results

Finally, that data is fed to emonCMS for home automation and self-quantification purposes:

presence_emoncms

Here is the flow code, you may need to check my previous post for the emonCMS sender part:

[{"id":"ba386057.845d3","type":"mqtt-broker","broker":"localhost","port":"1883"},{"id":"344b04c2.cbb4fc","type":"ping","name":"Ping Nexus 5","host":"192.168.1.80","timer":"60","x":105,"y":160,"z":"127c7a58.ed8386","wires":[["680c5308.97f3ac"]]},{"id":"c7248577.38db78","type":"debug","name":"","active":false,"complete":"false","x":543,"y":248,"z":"127c7a58.ed8386","wires":[]},{"id":"680c5308.97f3ac","type":"function","name":"Analyze Result","func":"// anything stored in context is kept available for next time we get called\ncontext.gotping = context.gotping || 1;\ncontext.pingfails = context.pingfails || 0;\n\n\nif(msg.payload) {\ncontext.gotping = 1;\ncontext.pingfails = 0;\n} \nelse\n{\ncontext.pingfails +=1;\nif(context.pingfails>3) context.gotping=0;\n}\n\nmsg.payload=context.gotping;\n\nreturn msg;","outputs":1,"x":309,"y":183,"z":"127c7a58.ed8386","wires":[["c7248577.38db78","cfb3d65b.304c28"]]},{"id":"cfb3d65b.304c28","type":"mqtt out","name":"Nexus5 presence","topic":"presence/nexus5","broker":"ba386057.845d3","x":546,"y":161,"z":"127c7a58.ed8386","wires":[]},{"id":"74d54a29.8b2ab4","type":"mqtt in","name":"Nexus5 presence","topic":"presence/nexus5","broker":"ba386057.845d3","x":127,"y":276,"z":"127c7a58.ed8386","wires":[["919ef3bc.6e611"]]},{"id":"919ef3bc.6e611","type":"mqtt out","name":"Send to Emoncms","topic":"home/emoncms/out/12","broker":"ba386057.845d3","x":357,"y":276,"z":"127c7a58.ed8386","wires":[]}]

From practical aspect, I will probably use this approach to check my and wife’s presence at home and if both of us are absent for say more than 30 minutes, I could turn down the heating a degree or two.

Update 1: Here is how the presence report looks so far, 1 means I am at home, 0 means I am out:

Presence report

Presence report

WiFi accounted for only 5% of my total battery usage that day:

Battery usage report on Android, pretty heavily used the phone to read news/browse that day

Battery usage report on Android, pretty heavily used the phone to read news/browse that day

(352)

Viewing all articles
Browse latest Browse all 328

Trending Articles