I'm new to Node-Red and I think there is something about flows or RBEs that I don't understand, and need some help figuring out.
As the subject suggests, I expect this flow to turn the lights off when the sun goes above a certain elevation, and turn the lights on when it goes below a certain elevation.
The flow takes the sun elevation from Home Assistant and has two branches. One branch
- emits 1 if the sun is more than 2 degrees above the horizon, otherwise 0.
- RBE that blocks until its input changes by >= 1
- When the RBE is unblocked, turns off the lights.
The other branch is essential the opposite (emit 0 if the sun is more than 2 degrees above the horizon, etc.)
What I don't understand is why both RBEs are unblocked when the sun angle goes above or below 2 degrees. The RBE to turn off the lights unblocks first, then within a minute the RBE to turn on the lights unblocks.
I realize I could solve my problem using different nodes, or add additional conditions as a workaround, but I would like to use this approach to improve my understanding of how Node-Red works.
Help much appreciated!
Sun high enough: msg.payload = (msg.data.attributes.elevation < 2) ? 0 : 1 ; return msg
Sun low enough: msg.payload = (msg.data.attributes.elevation < 2) ? 1 : 0; return msg
Time to turn on is identical to time to turn off
[{"id":"ffcb335e31d2af25","type":"tab","label":"porch lights","disabled":false,"info":"","env":[]},{"id":"0546f401381a7a7d","type":"api-current-state","z":"ffcb335e31d2af25","name":"sunny","server":"40b9c6f0.6c8aa8","version":2,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"sun.sun","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":110,"y":380,"wires":[["158f6ee2262519c2","b4d38ba15f6c227f"]]},{"id":"cd446268a66ea995","type":"inject","z":"ffcb335e31d2af25","name":"","props":[],"repeat":"60","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":90,"y":300,"wires":[["0546f401381a7a7d"]]},{"id":"3e8776772d257585","type":"rbe","z":"ffcb335e31d2af25","name":"time to turn off porch lights","func":"deadbandEq","gap":"1","start":"","inout":"in","septopics":true,"property":"payload","topi":"topic","x":600,"y":440,"wires":[["c59e89f8eb2daa94","4b07464633da9a57","c9245080926ce7d5"]]},{"id":"158f6ee2262519c2","type":"function","z":"ffcb335e31d2af25","name":"sun high enough","func":"msg.payload = (msg.data.attributes.elevation < 2) ? 0 : 1\nreturn msg","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":340,"y":440,"wires":[["3e8776772d257585"]]},{"id":"b4d38ba15f6c227f","type":"function","z":"ffcb335e31d2af25","name":"sun low enough","func":"msg.payload = (msg.data.attributes.elevation < 2) ? 1 : 0\nreturn msg","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":340,"y":320,"wires":[["175f6b27a79e992b"]]},{"id":"175f6b27a79e992b","type":"rbe","z":"ffcb335e31d2af25","name":"time to turn on porch lights","func":"deadbandEq","gap":"1","start":"","inout":"in","septopics":true,"property":"payload","topi":"topic","x":600,"y":320,"wires":[["d8b88d55d844d41b","38b681aaacf7980f","36ae0d17461682e2"]]},{"id":"38b681aaacf7980f","type":"api-call-service","z":"ffcb335e31d2af25","name":"turn on back porch","server":"40b9c6f0.6c8aa8","version":3,"debugenabled":false,"service_domain":"homeassistant","service":"turn_on","entityId":"switch.z_wave_plus_700_series_on_off_switch","data":"","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":910,"y":320,"wires":[[]]},{"id":"4b07464633da9a57","type":"api-call-service","z":"ffcb335e31d2af25","name":"turn off back porch","server":"40b9c6f0.6c8aa8","version":3,"debugenabled":false,"service_domain":"homeassistant","service":"turn_off","entityId":"switch.z_wave_plus_700_series_on_off_switch","data":"","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":890,"y":500,"wires":[[]]},{"id":"c59e89f8eb2daa94","type":"debug","z":"ffcb335e31d2af25","name":"","active":true,"tosidebar":true,"console":true,"tostatus":false,"complete":"\"Turn off porch lights\"","targetType":"jsonata","statusVal":"","statusType":"auto","x":830,"y":560,"wires":[]},{"id":"d8b88d55d844d41b","type":"debug","z":"ffcb335e31d2af25","name":"","active":true,"tosidebar":true,"console":true,"tostatus":false,"complete":"\"Turn on porch lights\"","targetType":"jsonata","statusVal":"","statusType":"auto","x":830,"y":380,"wires":[]},{"id":"36ae0d17461682e2","type":"api-call-service","z":"ffcb335e31d2af25","name":"turn on front porch","server":"40b9c6f0.6c8aa8","version":3,"debugenabled":false,"service_domain":"homeassistant","service":"turn_on","entityId":"light.red_series_dimmer","data":"","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":910,"y":260,"wires":[[]]},{"id":"c9245080926ce7d5","type":"api-call-service","z":"ffcb335e31d2af25","name":"turn off front porch","server":"40b9c6f0.6c8aa8","version":3,"debugenabled":false,"service_domain":"homeassistant","service":"turn_off","entityId":"light.red_series_dimmer","data":"","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":890,"y":440,"wires":[[]]},{"id":"40b9c6f0.6c8aa8","type":"server","name":"Home Assistant","version":2,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":30}]