Node-red-contrib-homekit-bridged: [FEATURE] Location based homekit responses

Created on 21 May 2019  路  8Comments  路  Source: NRCHKB/node-red-contrib-homekit-bridged

I have an Apple Tv 3rd gen which thankfully still allows remote access when off my network but I am unable to create automations via the Homekit App.
I am aware that I need a 4th gen TV, homepod or ipad to do so ... and its probably a good idea to upgrade ... but that being said ...

Has anyone come across a way for a service/nodered node to track your iphone/mac location then change the state of specific homekit services automatically?
ex. If I am the last person to leave the house then the security system will set to away and turn off my lights.

Setting scenes are handy and work well but sometimes one tends to be lazy and just wants it to happen by itself. Bad I know but hey, why not!?

Possible solutions:

  • Not being on the network could be a trigger I guess. If my phones dhcp lease expires then it assumes that Im not home which would activate the automatic sequence.
  • Have a homekit service which queries phones location

Thanks!

enhancement

Most helpful comment

@TristanMW - thought I'd share since I saw this just now.

I actually ran into some issues with the bt-presence node as it doesn't send EVERY PING. I wanted to see all of the pings from all of my pis... I've moved to using an exec command and checking whether it runs successfully. It's the same l2ping as the node uses, but moved to the exec node.

The command looks like:

sudo l2ping -c 1 -t 3 11:99:33:44:22:11

This lives in the exec code. I watch the 3rd output (return codes) of the exec node. If this returns 0 the ping was successful, if it returns 1 the ping timed out.

Example:

[{"id":"7347e4e9.0f0204","type":"exec","z":"4cee95c2.1744f4","command":"sudo l2ping -c 1 -t 3 11:99:33:44:22:11","addpay":false,"append":"","useSpawn":"false","timer":"10","oldrc":false,"name":"Garrett Phone","x":1020,"y":620,"wires":[[],[],["5160b966.a4d788"]]},{"id":"d9ffe0ac.d0e5d8","type":"inject","z":"4cee95c2.1744f4","name":"2 minutes","topic":"","payload":"","payloadType":"date","repeat":"120","crontab":"","once":true,"onceDelay":"30","x":830,"y":620,"wires":[["7347e4e9.0f0204"]]},{"id":"5160b966.a4d788","type":"switch","z":"4cee95c2.1744f4","name":"! null","property":"payload.code","propertyType":"msg","rules":[{"t":"nnull"}],"checkall":"true","repair":false,"outputs":1,"x":1190,"y":620,"wires":[["5197a652.8a1698"]]},{"id":"5197a652.8a1698","type":"change","z":"4cee95c2.1744f4","name":"Process","rules":[{"t":"set","p":"topic","pt":"msg","to":"garge/pres/Gp","tot":"str"},{"t":"change","p":"payload.code","pt":"msg","from":"1","fromt":"num","to":"false","tot":"bool"},{"t":"change","p":"payload.code","pt":"msg","from":"0","fromt":"num","to":"true","tot":"bool"},{"t":"move","p":"payload.code","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1340,"y":620,"wires":[["a5541411.70f9f"]]},{"id":"a5541411.70f9f","type":"mqtt out","z":"4cee95c2.1744f4","name":"MQTT","topic":"","qos":"1","retain":"false","broker":"3bf1cb59.207e34","x":1510,"y":620,"wires":[]},{"id":"3bf1cb59.207e34","type":"mqtt-broker","z":"","name":"Shelfie","broker":"10.10.10.10","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthRetain":"false","birthPayload":"","closeTopic":"","closeQos":"0","closeRetain":"false","closePayload":"","willTopic":"","willQos":"0","willRetain":"false","willPayload":""}]

I send it into MQTT to go onto my main node red deployment.

All 8 comments

Yes! This is built in once you have a newer Apple TV or HomePod.

You can ping your phone from node red
You can use homekit to run automations when you come/leave
You can make a dummy switch in your setup and have homekit turn it on/off depending on who is home

I鈥檝e been using various combinations of homekit, Bluetooth ping, and my router api for this - all with great success. There are many ways to skin the cat, pick one that works for you! Feel free to describe your ideal functionality and I could make some recommendations on what鈥檚 worked for me.

I see some ways.

  1. Buy newest Apple TV
  2. Buy Bluetooth Beacons and set it up in home to detect if people are there and connect it with node-red
  3. Make a bash script in node-red to scan who is connected in WiFi network and the you will know :)

Buy Bluetooth Beacons and set it up in home to detect if people are there and connect it with node-red

Or don't buy bluetooth beacons and just use your pi(s) as bluetooth beacons... I use this node

Make a bash script in node-red to scan who is connected in WiFi network

If everyone has static IP addresses you can use the node-red ping node to scan the wifi network.

I use a combination of 1, 2, and 3 for presence detection. Don't want any false negatives turning off all the lights when someone is actually home...

Perfect, thanks a lot @crxporter and @Shaquu !

Buying the new Apple TV sounds like the right way buuuuut bt-presence should like a more exciting way to do things haha.
Should probably look at upgrading in the future though.

Thanks again ...

Let me know if you have questions about setting it up. The only confusing part for me was giving permission so the node can use Bluetooth on the pi.

Have to run this line:

sudo setcap 'cap_net_raw+eip' `which l2ping`

Bump @TristanMW, any progress here?

Yes, managed to get the bt presence node working. Thanks a lot for the assistance

If anyone wants to see my example:
[{"id":"245ad56c.8bafda","type":"inject","z":"94109dfe.a4d55","name":"","topic":"","payload":"","payloadType":"date","repeat":"60","crontab":"","once":true,"onceDelay":0.1,"x":170,"y":520,"wires":[["2fad4e6b.459ed2","dcfbe542.644868"]]},{"id":"2fad4e6b.459ed2","type":"switch","z":"94109dfe.a4d55","name":"","property":"zoewie","propertyType":"global","rules":[{"t":"true"},{"t":"false"}],"checkall":"true","repair":false,"outputs":2,"x":310,"y":560,"wires":[["1bb47a89.1ce1a5"],["8ff3d7a2.89e488"]]},{"id":"dcfbe542.644868","type":"switch","z":"94109dfe.a4d55","name":"","property":"tristan","propertyType":"global","rules":[{"t":"true"},{"t":"false"}],"checkall":"true","repair":false,"outputs":2,"x":310,"y":480,"wires":[["a46f57df.896898"],["2638cd64.5f24c2"]]},{"id":"2638cd64.5f24c2","type":"function","z":"94109dfe.a4d55","name":"Tristan Away","func":"msg.payload = \"Tristan has left home\"\nreturn msg;","outputs":1,"noerr":0,"x":450,"y":500,"wires":[["a88f6f54.1f0d1"]]},{"id":"8ff3d7a2.89e488","type":"function","z":"94109dfe.a4d55","name":"Zoewie Away","func":"msg.payload = \"Zoewie has left home\"\nreturn msg;","outputs":1,"noerr":0,"x":450,"y":580,"wires":[[]]},{"id":"a46f57df.896898","type":"function","z":"94109dfe.a4d55","name":"Tristan Home","func":"msg.payload = \"Tristan is home\"\nreturn msg;","outputs":1,"noerr":0,"x":450,"y":460,"wires":[["a88f6f54.1f0d1"]]},{"id":"1bb47a89.1ce1a5","type":"function","z":"94109dfe.a4d55","name":"Zoewie Home","func":"msg.payload = \"Zoewie is home\"\nreturn msg;","outputs":1,"noerr":0,"x":460,"y":540,"wires":[[]]}]

@TristanMW - thought I'd share since I saw this just now.

I actually ran into some issues with the bt-presence node as it doesn't send EVERY PING. I wanted to see all of the pings from all of my pis... I've moved to using an exec command and checking whether it runs successfully. It's the same l2ping as the node uses, but moved to the exec node.

The command looks like:

sudo l2ping -c 1 -t 3 11:99:33:44:22:11

This lives in the exec code. I watch the 3rd output (return codes) of the exec node. If this returns 0 the ping was successful, if it returns 1 the ping timed out.

Example:

[{"id":"7347e4e9.0f0204","type":"exec","z":"4cee95c2.1744f4","command":"sudo l2ping -c 1 -t 3 11:99:33:44:22:11","addpay":false,"append":"","useSpawn":"false","timer":"10","oldrc":false,"name":"Garrett Phone","x":1020,"y":620,"wires":[[],[],["5160b966.a4d788"]]},{"id":"d9ffe0ac.d0e5d8","type":"inject","z":"4cee95c2.1744f4","name":"2 minutes","topic":"","payload":"","payloadType":"date","repeat":"120","crontab":"","once":true,"onceDelay":"30","x":830,"y":620,"wires":[["7347e4e9.0f0204"]]},{"id":"5160b966.a4d788","type":"switch","z":"4cee95c2.1744f4","name":"! null","property":"payload.code","propertyType":"msg","rules":[{"t":"nnull"}],"checkall":"true","repair":false,"outputs":1,"x":1190,"y":620,"wires":[["5197a652.8a1698"]]},{"id":"5197a652.8a1698","type":"change","z":"4cee95c2.1744f4","name":"Process","rules":[{"t":"set","p":"topic","pt":"msg","to":"garge/pres/Gp","tot":"str"},{"t":"change","p":"payload.code","pt":"msg","from":"1","fromt":"num","to":"false","tot":"bool"},{"t":"change","p":"payload.code","pt":"msg","from":"0","fromt":"num","to":"true","tot":"bool"},{"t":"move","p":"payload.code","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1340,"y":620,"wires":[["a5541411.70f9f"]]},{"id":"a5541411.70f9f","type":"mqtt out","z":"4cee95c2.1744f4","name":"MQTT","topic":"","qos":"1","retain":"false","broker":"3bf1cb59.207e34","x":1510,"y":620,"wires":[]},{"id":"3bf1cb59.207e34","type":"mqtt-broker","z":"","name":"Shelfie","broker":"10.10.10.10","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthRetain":"false","birthPayload":"","closeTopic":"","closeQos":"0","closeRetain":"false","closePayload":"","willTopic":"","willQos":"0","willRetain":"false","willPayload":""}]

I send it into MQTT to go onto my main node red deployment.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Supergiovane picture Supergiovane  路  9Comments

mtjoernelund picture mtjoernelund  路  8Comments

a2sky picture a2sky  路  7Comments

Torben80 picture Torben80  路  8Comments

Shaquu picture Shaquu  路  9Comments