Help wanted with flow intended to turn lights off and on based on sun elevation

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 off
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}]

I think I see, RBE looks at the absolute value of the change. I thought my RBEs would compare the new value 0 to the old value 1, and only fire if 0 - 1 >= 1. But in fact it fires if abs(0 - 1) >= 1.

My fix was to add a switch on each branch that only passes through if the value is 1. Then I cleaned it up to use booleans instead of 0 and 1.

[{"id":"6f67016bc0ee1044","type":"tab","label":"porch lights (copy)","disabled":false,"info":"","env":[]},{"id":"ea016844fbd77eb3","type":"api-current-state","z":"6f67016bc0ee1044","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":130,"y":420,"wires":[["e055fe80beda560b","bf0350ccff2b89cc"]]},{"id":"315f910feec3e65a","type":"inject","z":"6f67016bc0ee1044","name":"","props":[],"repeat":"60","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":130,"y":260,"wires":[["ea016844fbd77eb3"]]},{"id":"d145daab6ee10592","type":"rbe","z":"6f67016bc0ee1044","name":"time to turn off porch lights","func":"rbe","gap":"1","start":"","inout":"in","septopics":true,"property":"payload","topi":"topic","x":540,"y":500,"wires":[["57cd77bb3b607fdf"]]},{"id":"e055fe80beda560b","type":"function","z":"6f67016bc0ee1044","name":"sun high enough","func":"msg.payload = (msg.data.attributes.elevation >= -35.07)\nreturn msg","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":320,"y":500,"wires":[["d145daab6ee10592"]]},{"id":"bf0350ccff2b89cc","type":"function","z":"6f67016bc0ee1044","name":"sun low enough","func":"msg.payload = (msg.data.attributes.elevation < -35.07)\nreturn msg","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":320,"y":320,"wires":[["c5a46c17bf5e9e4f"]]},{"id":"c5a46c17bf5e9e4f","type":"rbe","z":"6f67016bc0ee1044","name":"time to turn on porch lights","func":"rbe","gap":"1","start":"","inout":"in","septopics":true,"property":"payload","topi":"topic","x":540,"y":320,"wires":[["a5ab52bd869fab0a"]]},{"id":"bd7bdb8dc7daaec2","type":"api-call-service","z":"6f67016bc0ee1044","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":950,"y":320,"wires":[[]]},{"id":"79226da3b8532425","type":"api-call-service","z":"6f67016bc0ee1044","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":950,"y":500,"wires":[[]]},{"id":"2d3cd7c7c1ec2774","type":"debug","z":"6f67016bc0ee1044","name":"","active":true,"tosidebar":true,"console":true,"tostatus":false,"complete":"\"Turn off porch lights \" & msg.payload","targetType":"jsonata","statusVal":"","statusType":"auto","x":930,"y":560,"wires":[]},{"id":"180541878fd134f8","type":"debug","z":"6f67016bc0ee1044","name":"","active":true,"tosidebar":true,"console":true,"tostatus":false,"complete":"\"Turn on porch lights \" & msg.payload","targetType":"jsonata","statusVal":"","statusType":"auto","x":930,"y":380,"wires":[]},{"id":"0ed98d2fc6372b58","type":"api-call-service","z":"6f67016bc0ee1044","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":950,"y":260,"wires":[[]]},{"id":"72695ef434559d19","type":"api-call-service","z":"6f67016bc0ee1044","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":950,"y":440,"wires":[[]]},{"id":"a5ab52bd869fab0a","type":"switch","z":"6f67016bc0ee1044","name":"true?","property":"payload","propertyType":"msg","rules":[{"t":"true"}],"checkall":"true","repair":false,"outputs":1,"x":730,"y":320,"wires":[["0ed98d2fc6372b58","bd7bdb8dc7daaec2","180541878fd134f8"]]},{"id":"57cd77bb3b607fdf","type":"switch","z":"6f67016bc0ee1044","name":"true?","property":"payload","propertyType":"msg","rules":[{"t":"true"}],"checkall":"true","repair":false,"outputs":1,"x":730,"y":500,"wires":[["72695ef434559d19","79226da3b8532425","2d3cd7c7c1ec2774"]]},{"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}]

I'm not into Home assistant.

When the RBE is unblocked, turns off the lights.

Ok, I think I get what you mean, but not exactly clearly explained.

If the 0 (which is if the sun is below the horizon) goes to 1 if the sun is more than 2 degrees above the horizon.

RBE that blocks until its input changes by >=1....

From what I read it will only ever be 0 or 1. What the > qualification?

Check what you said here:

emits 1 if the sun is more than 2 degrees above the horizon, otherwise 0.

That is a big problem for me as it reads there are only 2 outputs you will see.
0 or 1.
emits 1 if the sun is MORE than 2 degrees above the horizon, otherwise 0

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.