Philips Hue Log File

Description

This flow logs Philips Hue light switch changes. Please follow the instructions to set up this flow to your environment.

Motivation

I use some rules for my light system and some motion detectors. As I arrive at home, my light switches are automatically triggered by my smartphones WiFi logon. Sometimes I ask myself, if the lights were really off during the day or always on, caused by a potential misconfiguration. So I set up my Raspberry Pi to create a log file of light changes.

Maybe it's usefull for you as well... ;)

Setup Instructions

  1. Follow the instructions on https://www.developers.meethue.com/documentation/getting-started to get your Philips Hue API URL.
  2. Inject the api url to the global variable global.settings.hue.url
  3. Set your desired log file name in the node named Write to Lights States Log File
  4. Now you can check when the lights were switched on and off

_ Note: The format of the timestamp is UTC in ISO 8601 compatible format and may not represent your local timezone. _

[{"id":"596ec16a.2048d","type":"subflow","name":"Array Of Booleans to String","info":"","in":[{"x":40,"y":40,"wires":[{"id":"af39cdd0.144f9"}]}],"out":[{"x":440,"y":40,"wires":[{"id":"af39cdd0.144f9","port":0}]}]},{"id":"af39cdd0.144f9","type":"function","z":"596ec16a.2048d","name":"Array Of Booleans to String","func":"let ret = \"\";\n\nfor (const b of msg.payload) {\n    ret += (b === true) ? \"1\" : \"0\";\n}\nmsg.payload = ret;\nreturn msg;","outputs":1,"noerr":0,"x":240,"y":40,"wires":[[]]},{"id":"fdccb947.3480f8","type":"subflow","name":"Get Lights State","info":"","in":[{"x":40,"y":40,"wires":[{"id":"5a751ab7.8f3514"}]}],"out":[{"x":300,"y":40,"wires":[{"id":"5a751ab7.8f3514","port":0}]}]},{"id":"5a751ab7.8f3514","type":"function","z":"fdccb947.3480f8","name":"Get Lights States","func":"let ret = [];\n\nfor (const light in msg.payload) {\n    ret.push(msg.payload[light].state.on);\n}\n\nmsg.payload = ret;\nreturn msg;\n","outputs":1,"noerr":0,"x":170,"y":40,"wires":[[]]},{"id":"ff0ee1c6.69484","type":"tab","label":"Report Home State","disabled":false,"info":"# Report Home State\n\n## Description\n\nThis flow logs Philips Hue light switch changes.\nPlease follow the instructions to set up this flow to your environment.\n\n## Motivation\n\nI use some rules for my light system and some motion detectors.\nAs I arrive at home, my light switches are automatically triggered by my smartphones WiFi logon.\nSometimes I ask myself, if the lights were really off during the day or always on, caused by a potential misconfiguration.\nSo I set up my Raspberry Pi to create a log file of light changes.\n\nMaybe it's usefull for you as well... ;)\n\n## Setup Instructions\n\n1. Follow the instructions on https://www.developers.meethue.com/documentation/getting-started to get your Philips Hue API URL.\n2. Inject the api url to the global variable `global.settings.hue.url`\n3. Set your desired log file name in the node named `Write to Lights States Log File`\n4. Now you can check when the lights were switched on and off\n \n_\n__Note:__\nThe format of the timestamp is UTC in ISO 8601 compatible format and may not represent your local timezone.\n_"},{"id":"43b7079.0cad1f8","type":"inject","z":"ff0ee1c6.69484","name":"","topic":"","payload":"","payloadType":"date","repeat":"5","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":180,"wires":[["a646fed9.c4707"]]},{"id":"72f0c35c.c0d9ac","type":"http request","z":"ff0ee1c6.69484","name":"Get Lights","method":"GET","ret":"obj","url":"","tls":"","x":330,"y":380,"wires":[["44540150.c3bd9"]]},{"id":"5a78994b.8884f8","type":"change","z":"ff0ee1c6.69484","name":"Set Lights URL","rules":[{"t":"set","p":"url","pt":"msg","to":"$globalContext(\"settings.hue.url\") & \"/lights\"","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":160,"y":380,"wires":[["72f0c35c.c0d9ac"]]},{"id":"a9958d2a.8a77e","type":"change","z":"ff0ee1c6.69484","name":"Save Last State","rules":[{"t":"set","p":"lastLightsState","pt":"flow","to":"lightsState","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":160,"y":280,"wires":[["aa099e57.239"]]},{"id":"aa73ebd6.d0e128","type":"change","z":"ff0ee1c6.69484","name":"Set Current State","rules":[{"t":"set","p":"lightsState","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":170,"y":480,"wires":[["1a8479df.871036"]]},{"id":"d7c05f9.56629a","type":"switch","z":"ff0ee1c6.69484","name":"Lights State Changed?","property":"lightsState","propertyType":"flow","rules":[{"t":"neq","v":"lastLightsState","vt":"flow"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":190,"y":580,"wires":[["45d7d2c0.8a203c"],["4f3ce9e2.673078"]],"outputLabels":["yes","no"]},{"id":"feda1399.e1a9b","type":"debug","z":"ff0ee1c6.69484","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1030,"y":660,"wires":[]},{"id":"5cbc9fd3.489b","type":"change","z":"ff0ee1c6.69484","name":"off text","rules":[{"t":"set","p":"payload","pt":"msg","to":"ALL LIGHTS OFF","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":590,"y":580,"wires":[["a93d0be5.e98928"]]},{"id":"4f3ce9e2.673078","type":"change","z":"ff0ee1c6.69484","name":"unchanged text","rules":[{"t":"set","p":"payload","pt":"msg","to":"lights unchanged","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":620,"y":660,"wires":[["feda1399.e1a9b"]]},{"id":"9053e561.d4eeb8","type":"debug","z":"ff0ee1c6.69484","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":870,"y":420,"wires":[]},{"id":"44540150.c3bd9","type":"subflow:fdccb947.3480f8","z":"ff0ee1c6.69484","x":500,"y":380,"wires":[["f4b1114.a61d6f"]]},{"id":"f4b1114.a61d6f","type":"subflow:596ec16a.2048d","z":"ff0ee1c6.69484","name":"Convert to String","x":690,"y":380,"wires":[["9053e561.d4eeb8","6b1950db.6aaa1"]]},{"id":"45d7d2c0.8a203c","type":"switch","z":"ff0ee1c6.69484","name":"Are All Lights Off?","property":"$contains($flowContext(\"lightsState\"), \"1\")","propertyType":"jsonata","rules":[{"t":"false"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":430,"y":580,"wires":[["5cbc9fd3.489b"],["69162fa8.7249d"]],"outputLabels":["yes","no"]},{"id":"69162fa8.7249d","type":"change","z":"ff0ee1c6.69484","name":"changed text","rules":[{"t":"set","p":"payload","pt":"msg","to":"LIGHTS CHANGED","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":610,"y":620,"wires":[["a93d0be5.e98928"]]},{"id":"39631a9d.7dbb46","type":"file","z":"ff0ee1c6.69484","name":"Write to Lights States Log File","filename":"/home/pi/.node-red/logs/lightsstates.log","appendNewline":true,"createDir":true,"overwriteFile":"false","x":1090,"y":580,"wires":[]},{"id":"a93d0be5.e98928","type":"change","z":"ff0ee1c6.69484","name":"Prepend Timestamp","rules":[{"t":"set","p":"payload","pt":"msg","to":"$now() & \" - \" & $flowContext(\"lightsState\") & \" - \" & msg.payload","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":820,"y":580,"wires":[["feda1399.e1a9b","39631a9d.7dbb46"]]},{"id":"89aa4dbb.f9aa","type":"comment","z":"ff0ee1c6.69484","name":"Set `global.settings.hue.url` to your Philips Hue api url: https://www.developers.meethue.com/documentation/getting-started","info":"> To get detailed step by step instructions, open the flow description.","x":440,"y":40,"wires":[],"icon":"node-red/alert.png"},{"id":"5315b9cc.738bd8","type":"comment","z":"ff0ee1c6.69484","name":"Check for changes every ... seconds","info":"","x":170,"y":140,"wires":[]},{"id":"9dcf6fef.1b09f","type":"comment","z":"ff0ee1c6.69484","name":"Save previous light state","info":"","x":130,"y":240,"wires":[]},{"id":"47f0a7ce.a5fec8","type":"comment","z":"ff0ee1c6.69484","name":"Get the current light state","info":"","x":130,"y":340,"wires":[]},{"id":"18a4fbe7.e23ea4","type":"comment","z":"ff0ee1c6.69484","name":"Save current light state","info":"","x":120,"y":440,"wires":[]},{"id":"f0dc5ba3.683aa8","type":"comment","z":"ff0ee1c6.69484","name":"Log light state changes","info":"","x":120,"y":540,"wires":[]},{"id":"f5d529a9.469eb8","type":"comment","z":"ff0ee1c6.69484","name":"⬇ SET FILENAME HERE","info":"> To get detailed step by step instructions, open the flow description.","x":1070,"y":540,"wires":[],"icon":"node-red/node-changed.png"},{"id":"9f60f3be.8913e","type":"change","z":"ff0ee1c6.69484","name":"Set Philips Hue API URL","rules":[],"action":"","property":"","from":"","to":"","reg":false,"x":370,"y":80,"wires":[[]]},{"id":"18d30974.dd7e17","type":"inject","z":"ff0ee1c6.69484","name":"Set Initial Variables","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":true,"onceDelay":0.1,"x":150,"y":80,"wires":[["9f60f3be.8913e"]]},{"id":"4b6ae102.ac9d9","type":"comment","z":"ff0ee1c6.69484","name":"⬅ SET VARIABLE HERE","info":"> To get detailed step by step instructions, open the flow description.","x":590,"y":80,"wires":[],"icon":"node-red/node-changed.png"},{"id":"ca52298c.be1508","type":"link in","z":"ff0ee1c6.69484","name":"Save previous light state","links":["a646fed9.c4707"],"x":55,"y":280,"wires":[["a9958d2a.8a77e"]]},{"id":"ecf7b9a1.4ca168","type":"link in","z":"ff0ee1c6.69484","name":"Get the current light state","links":["aa099e57.239"],"x":55,"y":380,"wires":[["5a78994b.8884f8"]]},{"id":"6e1da50d.f53c4c","type":"link in","z":"ff0ee1c6.69484","name":"Save current light state","links":["6b1950db.6aaa1"],"x":55,"y":480,"wires":[["aa73ebd6.d0e128"]]},{"id":"9a9334da.405dd8","type":"link in","z":"ff0ee1c6.69484","name":"Log light state changes","links":["1a8479df.871036"],"x":55,"y":580,"wires":[["d7c05f9.56629a"]]},{"id":"a646fed9.c4707","type":"link out","z":"ff0ee1c6.69484","name":"","links":["ca52298c.be1508"],"x":235,"y":180,"wires":[]},{"id":"aa099e57.239","type":"link out","z":"ff0ee1c6.69484","name":"","links":["ecf7b9a1.4ca168"],"x":275,"y":280,"wires":[]},{"id":"6b1950db.6aaa1","type":"link out","z":"ff0ee1c6.69484","name":"","links":["6e1da50d.f53c4c"],"x":815,"y":380,"wires":[]},{"id":"1a8479df.871036","type":"link out","z":"ff0ee1c6.69484","name":"","links":["9a9334da.405dd8"],"x":295,"y":480,"wires":[]}]

Flow Info

Created 6 years, 6 months ago
Rating: not yet rated

Owner

Actions

Rate:

Node Types

Core
  • change (x8)
  • comment (x8)
  • debug (x2)
  • file (x1)
  • function (x2)
  • http request (x1)
  • inject (x2)
  • link in (x4)
  • link out (x4)
  • switch (x2)
Other
  • subflow (x2)
  • subflow:596ec16a.2048d (x1)
  • subflow:fdccb947.3480f8 (x1)
  • tab (x1)

Tags

  • hue
  • philipshue
  • logfile
  • log
Copy this flow JSON to your clipboard and then import into Node-RED using the Import From > Clipboard (Ctrl-I) menu option