I’m new to Node-Red and coding in general. I’m working on a flow to adjust house lighting based on three states. I’ve discovered the “Events: State” node is capable of identifying two of the three values that will influence the lighting scene. These two states, sun.above_horizon and a numeric value (10-1000) representing outdoor illuminance A third event, {“service”: “turn_on”} and {“service”: “turn_off”} are created by a “schedex” node on a different flow. I managed to figure out how the “LinkOut” and “LinkIn” nodes are used to pass a message between flows and wish to use this message in the flow I’m working on.
Here’s what I’m trying to achieve;
-
Lighting will be adjusted according to an illuminance value received from the associated “Event: State” node ("Illuminance Changed ?). I’ve already figured out how to adjust lighting based on certain values this node passes along. Everything from the “Calculated Weather Conditions” node onward works the way I want it to.
-
The illuminance value is to be passed along to the “Calculated Weather Conditions” node only if;
- it changes (Which I see can be controlled within the associated node) and;
- if sun.Above_Horizon is true and;
- if the last “schedex” message was {“service”: “turn_off”}
I also want the flow to initialize the appropriate nodes on start up. I believe those would be “Is The Sun Up ?” and “Scheduled State”
Here’s a diagram of the flow;
My flow thus far is;
[{"id":"104f5561.9d35eb","type":"tab","label":"Weather Influenced Lights","disabled":false,"info":""},{"id":"1f87083e.0f5d78","type":"comment","z":"104f5561.9d35eb","name":"Adjust living area lights according to exterior illuminance","info":"","x":260,"y":80,"wires":[]},{"id":"6d0263b8.4e368c","type":"switch","z":"104f5561.9d35eb","name":"Calculated Weather Condition","property":"payload","propertyType":"msg","rules":[{"t":"gt","v":"7500","vt":"str"},{"t":"eq","v":"7500","vt":"str"},{"t":"eq","v":"2500","vt":"str"},{"t":"eq","v":"1000","vt":"str"},{"t":"eq","v":"200","vt":"str"}],"checkall":"false","repair":false,"outputs":5,"x":970,"y":320,"wires":[["56a08a26.91f174","516d16b4.3ba988"],["58755e2b.b202f","2b145a78.134316"],["b2314bb0.aee4e8","8cc829eb.9684b8"],["95c0faf3.d57c38","21d971a9.debade"],["55b4eb4d.b01134","f45de23c.cd309"]],"outputLabels":["Clear Skies","Partly sunny, partly cloudy, mostly sunny, or hazy","Mostly cloudy","Cloudy, fog, rain, sleet, snow, flurries, chance of flurries, chance of rain, chancesleet, chance of snow, or chance ot tstorms","Thunder Storms"]},{"id":"fcb874e.a14c888","type":"api-call-service","z":"104f5561.9d35eb","name":"Livingroom Pots - On","server":"fcf9b76b.256a88","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"","data":"{\"entity_id\":\"light.living_room_pots\",\"brightness_pct\":35}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1580,"y":560,"wires":[[]]},{"id":"facc6c86.76263","type":"api-call-service","z":"104f5561.9d35eb","name":"Floor Lamp - On","server":"fcf9b76b.256a88","version":1,"debugenabled":false,"service_domain":"switch","service":"turn_on","entityId":"switch.floor_lamp","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1560,"y":440,"wires":[[]]},{"id":"ac15cf37.42701","type":"api-call-service","z":"104f5561.9d35eb","name":"Floor Lamp - Off","server":"fcf9b76b.256a88","version":1,"debugenabled":false,"service_domain":"switch","service":"turn_off","entityId":"switch.floor_lamp","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1560,"y":360,"wires":[[]]},{"id":"c9391b9c.4462d8","type":"api-call-service","z":"104f5561.9d35eb","name":"Couch Lamp - On","server":"fcf9b76b.256a88","version":1,"debugenabled":false,"service_domain":"switch","service":"turn_on","entityId":"switch.couch_lamp","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1570,"y":500,"wires":[[]]},{"id":"6d85f03d.ec83d","type":"api-call-service","z":"104f5561.9d35eb","name":"Side Table Lamp - On","server":"fcf9b76b.256a88","version":1,"debugenabled":false,"service_domain":"switch","service":"turn_on","entityId":"switch.side_table","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1580,"y":620,"wires":[[]]},{"id":"db76bc64.1e71c","type":"api-call-service","z":"104f5561.9d35eb","name":"Living Room Pots - Off","server":"fcf9b76b.256a88","version":1,"debugenabled":false,"service_domain":"light","service":"turn_off","entityId":"light.living_room_pots","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1580,"y":240,"wires":[[]]},{"id":"777b9494.6e058c","type":"api-call-service","z":"104f5561.9d35eb","name":"Side Table - Off","server":"fcf9b76b.256a88","version":1,"debugenabled":false,"service_domain":"switch","service":"turn_off","entityId":"switch.side_table","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1560,"y":180,"wires":[[]]},{"id":"f1e8dc33.9ffff","type":"api-call-service","z":"104f5561.9d35eb","name":"Couch Lamp - Off","server":"fcf9b76b.256a88","version":1,"debugenabled":false,"service_domain":"switch","service":"turn_off","entityId":"switch.couch_lamp","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1570,"y":300,"wires":[[]]},{"id":"55b4eb4d.b01134","type":"debug","z":"104f5561.9d35eb","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1270,"y":700,"wires":[]},{"id":"95c0faf3.d57c38","type":"debug","z":"104f5561.9d35eb","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1270,"y":660,"wires":[]},{"id":"b2314bb0.aee4e8","type":"debug","z":"104f5561.9d35eb","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1270,"y":620,"wires":[]},{"id":"58755e2b.b202f","type":"debug","z":"104f5561.9d35eb","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1270,"y":580,"wires":[]},{"id":"56a08a26.91f174","type":"debug","z":"104f5561.9d35eb","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1270,"y":540,"wires":[]},{"id":"516d16b4.3ba988","type":"link out","z":"104f5561.9d35eb","name":"No Lighting Required","links":["1b2c5cb0.3dfd23"],"x":1155,"y":240,"wires":[]},{"id":"1b2c5cb0.3dfd23","type":"link in","z":"104f5561.9d35eb","name":"Lights Off","links":["516d16b4.3ba988"],"x":1255,"y":240,"wires":[["777b9494.6e058c","db76bc64.1e71c","f1e8dc33.9ffff","ac15cf37.42701"]]},{"id":"2b145a78.134316","type":"link out","z":"104f5561.9d35eb","name":"Set Marginal Lighting","links":["677ffa47.c18eb4"],"x":1175,"y":280,"wires":[]},{"id":"677ffa47.c18eb4","type":"link in","z":"104f5561.9d35eb","name":"Minimal Lighting","links":["2b145a78.134316"],"x":1275,"y":280,"wires":[["fcb874e.a14c888","777b9494.6e058c","f1e8dc33.9ffff","ac15cf37.42701"]]},{"id":"21d971a9.debade","type":"link out","z":"104f5561.9d35eb","name":"Set Modest Lighting","links":["cdd29600.a4fd78"],"x":1175,"y":360,"wires":[]},{"id":"4dc45310.d46f8c","type":"link in","z":"104f5561.9d35eb","name":"Minimal Lighting","links":["8cc829eb.9684b8"],"x":1295,"y":320,"wires":[["fcb874e.a14c888","6d85f03d.ec83d","f1e8dc33.9ffff","ac15cf37.42701"]]},{"id":"8cc829eb.9684b8","type":"link out","z":"104f5561.9d35eb","name":"Set Minimal Lighting","links":["4dc45310.d46f8c"],"x":1195,"y":320,"wires":[]},{"id":"f45de23c.cd309","type":"link out","z":"104f5561.9d35eb","name":"Set Full Lighting","links":["9f486f64.a5f3"],"x":1155,"y":400,"wires":[]},{"id":"9f486f64.a5f3","type":"link in","z":"104f5561.9d35eb","name":"Full Lighting","links":["f45de23c.cd309"],"x":1255,"y":400,"wires":[["facc6c86.76263","c9391b9c.4462d8","fcb874e.a14c888","6d85f03d.ec83d"]]},{"id":"cdd29600.a4fd78","type":"link in","z":"104f5561.9d35eb","name":"Modest Lighting","links":["21d971a9.debade"],"x":1275,"y":360,"wires":[["f1e8dc33.9ffff","facc6c86.76263","fcb874e.a14c888","6d85f03d.ec83d"]]},{"id":"e1fe60c9.15829","type":"link in","z":"104f5561.9d35eb","name":"House Lights State","links":["cbc1de01.1214e"],"x":255,"y":420,"wires":[["7d271a1d.f48fb4"]]},{"id":"7d271a1d.f48fb4","type":"change","z":"104f5561.9d35eb","name":"Schedule State","rules":[{"t":"set","p":"payload","pt":"msg","to":"ScheduleStatus","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":440,"y":420,"wires":[["7d66b9c5.065278"]]},{"id":"7d66b9c5.065278","type":"debug","z":"104f5561.9d35eb","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":670,"y":420,"wires":[]},{"id":"4ee001ad.3c29e","type":"function","z":"104f5561.9d35eb","name":"House Lights Off - Continue","func":"//######################################################\n//# Allow if lights not turned on by House Lght Schedule\n//######################################################\nif (flow.get(\"ScheduleStatus\") == {\"service\": \"turn_off\"}){\n return msg;\n}else{\n return msg\n}","outputs":1,"noerr":0,"initialize":"// Code added here will be run once\n// whenever the node is deployed.\nif (flow.get(\"ScheduleStatus\") === undefined) {\n flow.set(\"ScheduleStatus\",{\"service\": \"turn_off\"});\n return msg;\n}","finalize":"","x":420,"y":320,"wires":[["a9db6196.937c2","195a81d9.a373ee"]],"inputLabels":["Current Illuminance - Weather Based"],"outputLabels":["House Lights Schedule Off"]},{"id":"a9db6196.937c2","type":"debug","z":"104f5561.9d35eb","name":"","active":true,"tosidebar":true,"console":true,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"flow","statusType":"msg","x":680,"y":240,"wires":[]},{"id":"3258efba.381c1","type":"debug","z":"104f5561.9d35eb","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":910,"y":240,"wires":[]},{"id":"195a81d9.a373ee","type":"rbe","z":"104f5561.9d35eb","name":"Pass Along Update","func":"rbe","gap":"","start":"","inout":"out","property":"payload","x":690,"y":320,"wires":[["6d0263b8.4e368c","3258efba.381c1"]]},{"id":"13a8ed4e.bfa373","type":"server-state-changed","z":"104f5561.9d35eb","name":"Is The Sun-up ?","server":"fcf9b76b.256a88","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"sun.sun","entityidfiltertype":"exact","outputinitially":true,"state_type":"str","haltifstate":"above_horizon","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"for":0,"forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"x":140,"y":160,"wires":[["b1cdad9b.f37b4"],["d4d94f14.806ed","cce120dc.9059c"]],"outputLabels":["Yes","No"]},{"id":"b1cdad9b.f37b4","type":"debug","z":"104f5561.9d35eb","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":390,"y":140,"wires":[]},{"id":"d4d94f14.806ed","type":"debug","z":"104f5561.9d35eb","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":390,"y":180,"wires":[]},{"id":"c5482bf8.f97cd8","type":"server-state-changed","z":"104f5561.9d35eb","name":"Illuminance Changed ?","server":"fcf9b76b.256a88","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"sensor.estimated_illuminance","entityidfiltertype":"exact","outputinitially":true,"state_type":"str","haltifstate":"$entity().state != $prevEntity().state","halt_if_type":"jsonata","halt_if_compare":"jsonata","outputs":2,"output_only_on_state_change":true,"for":0,"forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"x":160,"y":240,"wires":[["e87296d7.44dda8"],["b2dfc4b4.2fc808"]],"outputLabels":["Yes","No"]},{"id":"e87296d7.44dda8","type":"debug","z":"104f5561.9d35eb","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":390,"y":220,"wires":[]},{"id":"b2dfc4b4.2fc808","type":"debug","z":"104f5561.9d35eb","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":390,"y":260,"wires":[]},{"id":"cce120dc.9059c","type":"function","z":"104f5561.9d35eb","name":"","func":"\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":450,"y":580,"wires":[[]]},{"id":"fcf9b76b.256a88","type":"server","name":"Home Assistant","legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]
The same message was posted over on the Node-Red forums however readers tell me there’s not many users on that forum who use HA. Any assistance that you could offer would be greatly appreciated.
Regards, Robert