Turn off HDMI connected TV when leaving WIFI + presence dashboard

This flow does monitor if a user is present at home or not based on WIFI. It discovers presence changes and makes it available on a URL as webpage (/presence). Presence state is published on a MQTT topic. If the user leaves home with the phone and gets disconnected from the WIFI the attached TV gets turned off over HDMI CEC. All tested with a Nexus5, Raspberry Pi and a old Philips LCD TV.

Attached are two flows. Both have to be inserted separate. This pafe allows only to attach one flow. The second flow for the HTTP dashboard can be found here: https://gist.github.com/ludwigm/2a99462a4c32ac12b48b

Prerequisites:

Future possible extensions:

  • Maybe use Bluetooth LE
  • Switch of lamps like the Philips Hue
[{"id":"ba386057.845d3","type":"mqtt-broker","broker":"localhost","port":"1883"},{"id":"337ff4b7.cc800c","type":"ping","name":"Check Nexus5 (WIFI)","host":"192.168.178.21","timer":"10","x":153,"y":101,"z":"79c218da.863de8","wires":[["8cc363f7.733ca"]]},{"id":"8cc363f7.733ca","type":"function","name":"Discover state change","func":"\n\nvar prevState = context.prevState || false;\n\n//console.log(\"prev: \" + prevState)\n//console.log(\"actual: \" + msg.payload)\n\nif(msg.payload == false && prevState == true){\n\tvar msg2 = { payload:\"Went out (WIFI)\"};\n\tcontext.prevState = false;\n\tcontext.global.state = \"Nexus5 is out\"\n\treturn msg2;\n} else if(msg.payload > 0 && prevState == false) {\n\tvar msg2 = { payload:\"Came home (WIFI)\"};\n\tcontext.prevState = true;\n\tcontext.global.state = \"Nexus5 is at home\"\n\treturn msg2;\n} else {\n\t//console.log(\"no action\")\n}\n\n","outputs":1,"x":272,"y":199,"z":"79c218da.863de8","wires":[["819a5bdd.7e65a8","213295ae.decd6a","ce8abfe3.31754"]]},{"id":"819a5bdd.7e65a8","type":"debug","name":"","active":true,"console":false,"complete":false,"x":580,"y":322,"z":"79c218da.863de8","wires":[]},{"id":"213295ae.decd6a","type":"switch","name":"Forward on leave","property":"payload","rules":[{"t":"eq","v":"Went out (WIFI)"}],"checkall":"true","outputs":1,"x":341,"y":382,"z":"79c218da.863de8","wires":[["2f424fc4.d0bdb"]]},{"id":"ce8abfe3.31754","type":"mqtt out","name":"","topic":"/nexus5/presence","broker":"ba386057.845d3","x":599,"y":244,"z":"79c218da.863de8","wires":[]},{"id":"2f424fc4.d0bdb","type":"change","action":"replace","property":"payload","from":"","to":"","reg":false,"name":"Remove payload","x":577,"y":381,"z":"79c218da.863de8","wires":[["37df717f.c8208e"]]},{"id":"37df717f.c8208e","type":"exec","command":"echo \"tx 10 36\" | cec-client -s","append":"","useSpawn":"","name":"Turn off connected TV","x":805,"y":381,"z":"79c218da.863de8","wires":[["995e9290.66a17"],["995e9290.66a17"],["995e9290.66a17"]]},{"id":"995e9290.66a17","type":"debug","name":"","active":false,"console":"false","complete":"false","x":826,"y":475,"z":"79c218da.863de8","wires":[]}]

Flow Info

Created 11 years, 4 months ago
Updated 10 years ago
Rating: not yet rated

Owner

Actions

Rate:

Node Types

Core
  • change (x1)
  • debug (x2)
  • exec (x1)
  • function (x1)
  • mqtt out (x1)
  • mqtt-broker (x1)
  • switch (x1)
Other
  • ping (x1)

Tags

  • RPi
  • Pi
  • MQTT
  • Monitor
  • HTTP
  • Presence
  • HDMI
Copy this flow JSON to your clipboard and then import into Node-RED using the Import From > Clipboard (Ctrl-I) menu option