Skip to content

Instantly share code, notes, and snippets.

@walthowd
Created January 17, 2020 17:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save walthowd/5ab5eaf4cd5f55626d2d7152ad10fcaf to your computer and use it in GitHub Desktop.
Save walthowd/5ab5eaf4cd5f55626d2d7152ad10fcaf to your computer and use it in GitHub Desktop.
[{"id":"67a58f4e.b7b7b","type":"api-current-state","z":"d0bc1d69.23ea1","name":"Stop if light is off","server":"e2a02faf.48099","outputs":2,"halt_if":"off","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"","state_type":"str","state_location":"light_state","override_payload":"msg","entity_location":"light_entity","override_data":"msg","x":1330,"y":200,"wires":[["b2a4c831.860878"],[]]},{"id":"edb29bb1.8b6968","type":"stoptimer","z":"d0bc1d69.23ea1","duration":"4","units":"Hour","payloadtype":"num","payloadval":"0","name":"","x":1362.750015258789,"y":349.33340525627136,"wires":[["841866bf.40f4b8"],["841866bf.40f4b8"]]},{"id":"31bcaab.2f29356","type":"change","z":"d0bc1d69.23ea1","name":"Setup payload.entity_id","rules":[{"t":"delete","p":"payload","pt":"msg"},{"t":"move","p":"data.entity_id","pt":"msg","to":"payload.entity_id","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":330,"y":200,"wires":[["d69d9808.ed5c28","bc399547.4e9bf8"]]},{"id":"be0e5e3c.b15ab","type":"function","z":"d0bc1d69.23ea1","name":"Check manual override","func":"entity_id = msg.payload.entity_id;\nmanual_override = flow.get(entity_id + \"_manual_override\");\nmsg.manual_override = manual_override;\n \nif(manual_override) {\n return [msg, null];\n} else {\n return [null, msg];\n}","outputs":2,"noerr":0,"x":1090,"y":200,"wires":[[],["67a58f4e.b7b7b"]]},{"id":"cd0a1863.422208","type":"function","z":"d0bc1d69.23ea1","name":"Set manual override to true","func":"entity_id = msg.payload.entity_id;\nflow.set(entity_id + \"_manual_override\", true);\n\nmsg.manual_override = entity_id + \"_manual_override\";\nreturn msg;","outputs":1,"noerr":0,"x":1090.6666870117188,"y":352.6666421890259,"wires":[["edb29bb1.8b6968","bce46a8a.19bdd8"]]},{"id":"841866bf.40f4b8","type":"function","z":"d0bc1d69.23ea1","name":"Set manual override to false","func":"entity_id = msg.payload.entity_id;\n\nflow.set(entity_id + \"_manual_override\", false);\n\nreturn msg;","outputs":1,"noerr":0,"x":1609.0000228881836,"y":342.6667242050171,"wires":[[]]},{"id":"bc399547.4e9bf8","type":"switch","z":"d0bc1d69.23ea1","name":"Check user_id is Node-RED","property":"data.context.user_id","propertyType":"msg","rules":[{"t":"eq","v":"84b0def504e245bdb7047e883f20d45c","vt":"str"},{"t":"neq","v":"84b0def504e245bdb7047e883f20d45c","vt":"str"}],"checkall":"false","repair":false,"outputs":2,"x":780,"y":200,"wires":[["be0e5e3c.b15ab"],["aa34559d.4941b8"]],"outputLabels":["Node-RED user","Different user"]},{"id":"aa34559d.4941b8","type":"switch","z":"d0bc1d69.23ea1","name":"Changed more or less then 60 sec ago","property":"data.timeSinceChangedMs","propertyType":"msg","rules":[{"t":"gte","v":"60000","vt":"num"},{"t":"lt","v":"60000","vt":"num"}],"checkall":"true","repair":false,"outputs":2,"x":884.9999694824219,"y":286.6666488647461,"wires":[["be0e5e3c.b15ab"],["cd0a1863.422208"]]},{"id":"bce46a8a.19bdd8","type":"looptimer","z":"d0bc1d69.23ea1","duration":"30","units":"Second","maxloops":"999","maxtimeout":"4","maxtimeoutunits":"Hour","name":"","x":1030,"y":420,"wires":[["5be11ced.4327d4"],[]]},{"id":"5be11ced.4327d4","type":"switch","z":"d0bc1d69.23ea1","name":"Manual override false?","property":"manual_override","propertyType":"flow","rules":[{"t":"false"}],"checkall":"true","repair":false,"outputs":1,"x":1340,"y":420,"wires":[["a96284ab.551ed8"]]},{"id":"a96284ab.551ed8","type":"change","z":"d0bc1d69.23ea1","name":"Stop loop/timers","rules":[{"t":"set","p":"payload","pt":"msg","to":"stop","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":910,"y":540,"wires":[["edb29bb1.8b6968","bce46a8a.19bdd8"]]},{"id":"d69d9808.ed5c28","type":"delay","z":"d0bc1d69.23ea1","name":"","pauseType":"rate","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"12","rateUnits":"hour","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":true,"x":460,"y":120,"wires":[["a96284ab.551ed8","b2a4c831.860878"]]},{"id":"a5f7b8a8.57f948","type":"comment","z":"d0bc1d69.23ea1","name":"Always send the message through the first time","info":"","x":560,"y":80,"wires":[]},{"id":"b2a4c831.860878","type":"delay","z":"d0bc1d69.23ea1","name":"","pauseType":"rate","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":true,"x":1390,"y":120,"wires":[[]]},{"id":"a9aa1fff.9feb4","type":"comment","z":"d0bc1d69.23ea1","name":"See which user changed the light","info":"","x":790,"y":160,"wires":[]},{"id":"e2a02faf.48099","type":"server","z":"","name":"Home Assistant","legacy":false,"hassio":false,"rejectUnauthorizedCerts":false,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment