UNPKG

node-red-contrib-home-assistant-websocket

Version:
1 lines 5.97 kB
[{"id":"3a2face9747195a7","type":"group","z":"776c027950fc8c3f","name":"Trigger: state node - respond to state changes","style":{"label":true,"color":"#000000"},"nodes":["320b22abb5a9ea96","da88972398c7ed97","c2d9f44ffe436dcc","2144de490d4257d7","94ceadbce4b45cdf","79b056d9779ec8f1","360fe19e1e203539","247cbab5f584ea63","0509fc220ff7735e","8fc293f5015dd3d5"],"x":34,"y":1359,"w":872,"h":302},{"id":"320b22abb5a9ea96","type":"inject","z":"776c027950fc8c3f","g":"3a2face9747195a7","name":"Testing","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\t \"entity_id\": \"sensor.time_utc\",\t \"old_state\": {\"state\": \"16:49\"},\t \"new_state\": {\"state\": \"16:50\"}\t}","payloadType":"jsonata","x":130,"y":1400,"wires":[["da88972398c7ed97"]]},{"id":"da88972398c7ed97","type":"trigger-state","z":"776c027950fc8c3f","g":"3a2face9747195a7","name":"Actions around sunset","server":"","version":4,"inputs":1,"outputs":3,"exposeAsEntityConfig":"","entityId":"sensor.time_utc","entityIdType":"exact","debugEnabled":false,"constraints":[{"targetType":"this_entity","targetValue":"","propertyType":"current_state","propertyValue":"new_state.state","comparatorType":"includes","comparatorValueDatatype":"jsonata","comparatorValue":"(\t/* UTC sunrise & sunset to 5 mins, month average (London UK) */\t/* Jan-Dec, Feb-Nov, Mar-Oct, Apr-Sep, May-Aug, Jun-Jly */\t $times:=[[\"07:55\", \"16:20\"],\t [\"07:15\", \"16:45\"],\t [\"06:00\", \"17:35\"],\t [\"05:15\", \"18:30\"],\t [\"04:30\", \"19:30\"],\t [\"04:05\", \"20:05\"]];\t\t/* get this month (Jan=0), lookup sun-times table, return sun rise-set for this month */\t $mtable:=[0..11].$min([$, $abs($-11)]);\t $mindex:=$now('[M]').$number()-1;\t\t/* get sunset and build array of condition test-times around this */\t $sunset:=($times[$mtable[$mindex]])[1];\t $h:=$number($substringBefore($sunset, \":\"));\t $m:=$number($substringAfter($sunset, \":\"));\t\t/* for span period mins, generate array of times and select every nth */\t $span:=60;\t $nth:=5;\t\t $t:=$h*60+$m-$span;\t ([$t..$t+$span*2])#$i.(\t $h:=$floor($/60);\t $m:=$%60;\t $i%$nth=0 ? $formatInteger($h,'99') & \":\" & $formatInteger($m, '99');\t )\t)"}],"customOutputs":[{"messageType":"custom","messageValue":"(\t $sunset:=$entities('sensor.sun_next_setting').state;\t $togo:= ($toMillis($sunset)-$millis())/60000~>$floor();\t $toset:= $togo < 180 ? $togo : $togo-1440;\t $x:= $toset-25;\t $pc:= $x<0 and $x>-55 ? $min([$abs($x)*2, 100]) : null;\t\t {\"topic\": \"Minutes to Sunset\",\t \"payload\": $toset,\t \"time\": $entities('sensor.time').state,\t \"sunset\": $sunset,\t \"percent\": $pc\t }\t)","messageValueType":"jsonata","comparatorPropertyType":"always","comparatorPropertyValue":"","comparatorType":"is","comparatorValue":"","comparatorValueDataType":"jsonata"}],"outputInitially":false,"stateType":"str","enableInput":true,"x":300,"y":1440,"wires":[["c2d9f44ffe436dcc"],[],["2144de490d4257d7","247cbab5f584ea63"]]},{"id":"c2d9f44ffe436dcc","type":"debug","z":"776c027950fc8c3f","g":"3a2face9747195a7","name":"Every 5 mins around sunset","active":false,"tosidebar":true,"console":false,"tostatus":true,"complete":"true","targetType":"full","statusVal":"payload","statusType":"auto","x":580,"y":1400,"wires":[]},{"id":"2144de490d4257d7","type":"switch","z":"776c027950fc8c3f","g":"3a2face9747195a7","name":"Sunset Actions","property":"payload","propertyType":"msg","rules":[{"t":"btwn","v":"0","vt":"num","v2":"4","v2t":"num"},{"t":"btwn","v":"10","vt":"num","v2":"14","v2t":"num"},{"t":"btwn","v":"0","vt":"num","v2":"-30","v2t":"num"},{"t":"else"}],"checkall":"false","repair":false,"outputs":4,"x":540,"y":1480,"wires":[["94ceadbce4b45cdf"],["79b056d9779ec8f1"],["360fe19e1e203539"],[]]},{"id":"94ceadbce4b45cdf","type":"debug","z":"776c027950fc8c3f","g":"3a2face9747195a7","name":"At Sunset","active":false,"tosidebar":false,"console":false,"tostatus":true,"complete":"true","targetType":"full","statusVal":"payload","statusType":"auto","x":780,"y":1440,"wires":[]},{"id":"79b056d9779ec8f1","type":"debug","z":"776c027950fc8c3f","g":"3a2face9747195a7","name":"Just Before","active":false,"tosidebar":false,"console":false,"tostatus":true,"complete":"true","targetType":"full","statusVal":"payload","statusType":"auto","x":790,"y":1500,"wires":[]},{"id":"360fe19e1e203539","type":"debug","z":"776c027950fc8c3f","g":"3a2face9747195a7","name":"Just After","active":false,"tosidebar":false,"console":false,"tostatus":true,"complete":"true","targetType":"full","statusVal":"payload","statusType":"auto","x":780,"y":1560,"wires":[]},{"id":"247cbab5f584ea63","type":"change","z":"776c027950fc8c3f","g":"3a2face9747195a7","name":"Brightness 0-100% over 50 min","rules":[{"t":"set","p":"payload","pt":"msg","to":"{\t \"domain\": \"homeassistant\",\t \"service\": \"turn_on\",\t \"target\": {\t \"entity_id\": [\"light.front_door\", \"switch.hall_light\"]\t },\t \"data\": {\t \"brightness_pct\": percent\t }\t}","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":310,"y":1620,"wires":[["8fc293f5015dd3d5"]]},{"id":"0509fc220ff7735e","type":"api-call-service","z":"776c027950fc8c3f","g":"3a2face9747195a7","name":"","server":"","version":5,"debugenabled":false,"domain":"homeassistant","service":"turn_on","areaId":[],"deviceId":[],"entityId":[],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":760,"y":1620,"wires":[[]]},{"id":"8fc293f5015dd3d5","type":"switch","z":"776c027950fc8c3f","g":"3a2face9747195a7","name":"Not null","property":"payload.data.brightness_pct","propertyType":"msg","rules":[{"t":"nnull"}],"checkall":"true","repair":false,"outputs":1,"x":540,"y":1620,"wires":[["0509fc220ff7735e"]]}]