UNPKG

node-red-contrib-home-assistant-websocket

Version:
1 lines 5.99 kB
[{"id":"35b892e153bb5bc0","type":"group","z":"776c027950fc8c3f","name":"Events: state node - respond to state changes","style":{"label":true,"color":"#000000"},"nodes":["445466367c412014","e27b6ee2807af2eb","4583560d5089575d","24ed76ccd4da5975","266eadf86abd6481","27857c0c670e452b","e2ba71699db68b1a","1d9b8adce4f77e4e","a9b23a3911f5ef89"],"x":34,"y":919,"w":592,"h":342},{"id":"445466367c412014","type":"comment","z":"776c027950fc8c3f","g":"35b892e153bb5bc0","name":"3a - JSONata builds conditional test value","info":"","x":220,"y":960,"wires":[]},{"id":"e27b6ee2807af2eb","type":"server-state-changed","z":"776c027950fc8c3f","g":"35b892e153bb5bc0","name":"Switch was on for less than 3 minutes","server":"","version":5,"outputs":2,"exposeAsEntityConfig":"","entityId":"switch\\.[a-z][0-9]","entityIdType":"regex","outputInitially":false,"stateType":"str","ifState":"(\t $new:=$entity();\t $old:=$prevEntity();\t $mins:=($toMillis($new.last_changed)-$toMillis($old.last_changed))/60000~>$round(0);\t $new.state=\"off\" and $old.state=\"on\" and $mins<3\t)","ifStateType":"jsonata","ifStateOperator":"jsonata","outputOnlyOnStateChange":false,"for":"0","forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"\"Device \" & $entity().attributes.friendly_name & \" has been on for less than 3 minutes\"","valueType":"jsonata"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":230,"y":1140,"wires":[["4583560d5089575d"],[]]},{"id":"4583560d5089575d","type":"debug","z":"776c027950fc8c3f","g":"35b892e153bb5bc0","name":"Flow trigger","active":true,"tosidebar":false,"console":false,"tostatus":true,"complete":"topic","targetType":"msg","statusVal":"payload","statusType":"auto","x":490,"y":1140,"wires":[]},{"id":"24ed76ccd4da5975","type":"server-state-changed","z":"776c027950fc8c3f","g":"35b892e153bb5bc0","name":"Motion between dawn and dusk","server":"","version":5,"outputs":2,"exposeAsEntityConfig":"","entityId":"motion","entityIdType":"substring","outputInitially":false,"stateType":"str","ifState":"(\t $ismotion:= $entity().state=\"on\";\t\t $dawn:=$entities('sensor.sun_next_dawn').state;\t $dusk:=$entities('sensor.sun_next_dusk').state;\t $date:=$entities('sensor.date_time_utc').state~>$substringBefore(\",\");\t\t $isdawn:= $date=$substringBefore($dawn,\"T\");\t $isdusk:= $date!=$substringBefore($dusk,\"T\");\t \t $ismotion and ($isdawn or $isdusk)\t)","ifStateType":"jsonata","ifStateOperator":"jsonata","outputOnlyOnStateChange":true,"for":"0","forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"(\t $ismotion:= $entity().state=\"on\";\t\t $dawn:=$entities('sensor.sun_next_dawn').state;\t $dusk:=$entities('sensor.sun_next_dusk').state;\t $date:=$entities('sensor.date_time_utc').state~>$substringBefore(\",\");\t\t $isdawn:= $date=$substringBefore($dawn,\"T\");\t $isdusk:= $date!=$substringBefore($dusk,\"T\");\t \t $fire:= $ismotion and ($isdawn or $isdusk);\t\t {\"motion\": $ismotion,\t \"dawn\": $dawn,\t \"dusk\": $dusk,\t \"date\": $date,\t \"isdawn\": $isdawn,\t \"isdusk\": $isdusk,\t \"fire\": $fire\t }\t)","valueType":"jsonata"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":210,"y":1220,"wires":[["266eadf86abd6481"],[]]},{"id":"266eadf86abd6481","type":"debug","z":"776c027950fc8c3f","g":"35b892e153bb5bc0","name":"Dawn or Dusk","active":false,"tosidebar":false,"console":false,"tostatus":true,"complete":"true","targetType":"full","statusVal":"payload.isdawn ? \"Before Dawn\" : payload.isdusk ? \"After Dusk\"","statusType":"jsonata","x":500,"y":1220,"wires":[]},{"id":"27857c0c670e452b","type":"server-state-changed","z":"776c027950fc8c3f","g":"35b892e153bb5bc0","name":"","server":"","version":5,"outputs":2,"exposeAsEntityConfig":"","entityId":"motion","entityIdType":"substring","outputInitially":false,"stateType":"str","ifState":"(\t $time:=$entities('sensor.time').state;\t $append([\"on\"], $time<\"08:30\" or $time>\"17:30\" ? [\"off\"]);\t) ","ifStateType":"jsonata","ifStateOperator":"includes","outputOnlyOnStateChange":true,"for":"0","forType":"num","forUnits":"seconds","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":240,"y":1020,"wires":[["1d9b8adce4f77e4e"],["e2ba71699db68b1a"]]},{"id":"e2ba71699db68b1a","type":"debug","z":"776c027950fc8c3f","g":"35b892e153bb5bc0","name":"Condition false","active":false,"tosidebar":false,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":500,"y":1040,"wires":[]},{"id":"1d9b8adce4f77e4e","type":"debug","z":"776c027950fc8c3f","g":"35b892e153bb5bc0","name":"Condition true","active":false,"tosidebar":false,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload=\"on\" ? \"Motion at \" & $now('[H]:[m]') : \"end\"","statusType":"jsonata","x":500,"y":980,"wires":[]},{"id":"a9b23a3911f5ef89","type":"comment","z":"776c027950fc8c3f","g":"35b892e153bb5bc0","name":"3b - JSONata builds conditional Boolean","info":"","x":220,"y":1100,"wires":[]}]