Multi-input flows, node-red or something else?

I’m trying to figure out the best way to implement a bunch of automations that need to read the state of multiple sensors and if Node Red is a good option.

I’ve done several flows that are based on a single input or state and it is quite easy. However it isn’t clicking how to do something like:

  • Trigger on change of any of:
    • Lux Sensor 1
    • Lux Sensor 2
    • Sunset/Sunrise
  • If Average Lux is less than 50 OR (after sunset AND before sunrise) then do X

Another example

  • Trigger on change of any of:
    • Door 1
    • Door 2
    • Humidity Sensor
  • If door 1 or door 2 open turn off switch
  • If humidity < 65 turn off switch
  • If door 1 and door 2 closed for at least 5 minutes and humidity > 65 turn on switch

I’m mostly struggling with the single-input nature of nodes which makes me unsure how to do something like averaging two inputs.

Also it seems like a lot of duplication as I need an events:state and current state node for each sensor I want to trigger and perform logic on.

Here’s different ways for the first one

[{"id":"21ba280c.c2cbb8","type":"server-state-changed","z":"ffbd7f06.4a014","name":"","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"sensor.lux1, sensor.lux2","entityidfiltertype":"substring","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":false,"for":0,"forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"x":342,"y":2000,"wires":[["94c2b057.3c74b"]]},{"id":"bdf11369.b07be","type":"eztimer","z":"ffbd7f06.4a014","name":"","debug":false,"autoname":"sunset","tag":"eztimer","suspended":false,"sendEventsOnSuspend":false,"timerType":"2","startupMessage":false,"ontype":"1","ontimesun":"sunset","ontimetod":"17:00","onpropertytype":"msg","onproperty":"payload","onvaluetype":"num","onvalue":1,"onoffset":0,"onrandomoffset":0,"onsuppressrepeats":false,"offtype":"1","offtimesun":"sunrise","offtimetod":"dusk","offduration":"00:01:00","offpropertytype":"msg","offproperty":"payload","offvaluetype":"num","offvalue":0,"offoffset":0,"offrandomoffset":0,"offsuppressrepeats":false,"mon":true,"tue":true,"wed":true,"thu":true,"fri":true,"sat":true,"sun":true,"x":850,"y":2048,"wires":[["53f879a0.122168"]]},{"id":"53f879a0.122168","type":"debug","z":"ffbd7f06.4a014","name":"do X","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":994,"y":2000,"wires":[]},{"id":"b3e665d8.f05e48","type":"switch","z":"ffbd7f06.4a014","name":"average < 50","property":"(lux1 + lux2) / 2 < 50","propertyType":"jsonata","rules":[{"t":"true"}],"checkall":"true","repair":false,"outputs":1,"x":838,"y":2000,"wires":[["53f879a0.122168"]]},{"id":"94c2b057.3c74b","type":"api-current-state","z":"ffbd7f06.4a014","name":"lux1","version":1,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"sensor.lux1","state_type":"num","state_location":"payload","override_payload":"msg","entity_location":"","override_data":"none","blockInputOverrides":false,"x":562,"y":2000,"wires":[["eeb72793.390c28"]]},{"id":"eeb72793.390c28","type":"api-current-state","z":"ffbd7f06.4a014","name":"lux2","version":1,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"sensor.lux2","state_type":"num","state_location":"payload","override_payload":"msg","entity_location":"","override_data":"none","blockInputOverrides":false,"x":690,"y":2000,"wires":[["b3e665d8.f05e48"]]}]

[{"id":"d12dfd91.9a879","type":"server-state-changed","z":"ffbd7f06.4a014","name":"","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"sensor.lux1, sensor.lux2","entityidfiltertype":"substring","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":false,"for":0,"forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"x":358,"y":1728,"wires":[["9fd140e1.29a6b"]]},{"id":"d346cdbf.12caa","type":"eztimer","z":"ffbd7f06.4a014","name":"","debug":false,"autoname":"sunset","tag":"eztimer","suspended":false,"sendEventsOnSuspend":false,"timerType":"2","startupMessage":false,"ontype":"1","ontimesun":"sunset","ontimetod":"17:00","onpropertytype":"msg","onproperty":"payload","onvaluetype":"num","onvalue":1,"onoffset":0,"onrandomoffset":0,"onsuppressrepeats":false,"offtype":"1","offtimesun":"sunrise","offtimetod":"dusk","offduration":"00:01:00","offpropertytype":"msg","offproperty":"payload","offvaluetype":"num","offvalue":0,"offoffset":0,"offrandomoffset":0,"offsuppressrepeats":false,"mon":true,"tue":true,"wed":true,"thu":true,"fri":true,"sat":true,"sun":true,"x":978,"y":1776,"wires":[["ad2b315e.d2d5b"]]},{"id":"ad2b315e.d2d5b","type":"debug","z":"ffbd7f06.4a014","name":"do X","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1122,"y":1728,"wires":[]},{"id":"4b0e926b.7b948c","type":"function","z":"ffbd7f06.4a014","name":"average","func":"const average = (msg.lux1 + msg.lux2) / 2;\nmsg.payload = average;\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":844,"y":1728,"wires":[["a4bb1e85.98e24"]]},{"id":"a4bb1e85.98e24","type":"switch","z":"ffbd7f06.4a014","name":"","property":"payload","propertyType":"msg","rules":[{"t":"lt","v":"50","vt":"num"}],"checkall":"true","repair":false,"outputs":1,"x":978,"y":1728,"wires":[["ad2b315e.d2d5b"]]},{"id":"9fd140e1.29a6b","type":"api-current-state","z":"ffbd7f06.4a014","name":"lux1","version":1,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"sensor.lux1","state_type":"num","state_location":"lux1","override_payload":"msg","entity_location":"","override_data":"none","blockInputOverrides":false,"x":578,"y":1728,"wires":[["be17227e.41717"]]},{"id":"be17227e.41717","type":"api-current-state","z":"ffbd7f06.4a014","name":"lux2","version":1,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"sensor.lux2","state_type":"num","state_location":"lux2","override_payload":"msg","entity_location":"","override_data":"none","blockInputOverrides":false,"x":706,"y":1728,"wires":[["4b0e926b.7b948c"]]}]

image

[{"id":"df65fb66.fe6098","type":"server-state-changed","z":"ffbd7f06.4a014","name":"","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"sensor.lux1, sensor.lux2","entityidfiltertype":"substring","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":false,"for":0,"forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"x":374,"y":1872,"wires":[["c480151d.ddcd08"]]},{"id":"cb0919a.9ab14e8","type":"eztimer","z":"ffbd7f06.4a014","name":"","debug":false,"autoname":"sunset","tag":"eztimer","suspended":false,"sendEventsOnSuspend":false,"timerType":"2","startupMessage":false,"ontype":"1","ontimesun":"sunset","ontimetod":"17:00","onpropertytype":"msg","onproperty":"payload","onvaluetype":"num","onvalue":1,"onoffset":0,"onrandomoffset":0,"onsuppressrepeats":false,"offtype":"1","offtimesun":"sunrise","offtimetod":"dusk","offduration":"00:01:00","offpropertytype":"msg","offproperty":"payload","offvaluetype":"num","offvalue":0,"offoffset":0,"offrandomoffset":0,"offsuppressrepeats":false,"mon":true,"tue":true,"wed":true,"thu":true,"fri":true,"sat":true,"sun":true,"x":610,"y":1920,"wires":[["46e1872b.2226e8"]]},{"id":"46e1872b.2226e8","type":"debug","z":"ffbd7f06.4a014","name":"do X","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":754,"y":1872,"wires":[]},{"id":"c480151d.ddcd08","type":"function","z":"ffbd7f06.4a014","name":"average","func":"const states = global.get(\"homeassistant\").homeAssistant;\nconst lux1 = Number(states[\"sensor.lux1\"].state);\nconst lux2 = Number(states[\"sensor.lux2\"].state);\nconst average = (lux1 + lux2) / 2;\n\nif(average < 50) {\n    msg.payload = average;\n    return msg;\n}","outputs":1,"noerr":0,"initialize":"","finalize":"","x":604,"y":1872,"wires":[["46e1872b.2226e8"]]}]

Second one

[{"id":"36653373.25ff0c","type":"trigger-state","z":"ffbd7f06.4a014","name":"","exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityid":"sensor.door1, sensor.door2, sensor.humidity","entityidfiltertype":"substring","debugenabled":false,"constraints":[{"targetType":"entity_id","targetValue":"sensor.door1","propertyType":"current_state","comparatorType":"is","comparatorValueDatatype":"str","comparatorValue":"closed","propertyValue":"new_state.state"},{"targetType":"entity_id","targetValue":"sensor.door2","propertyType":"current_state","comparatorType":"is","comparatorValueDatatype":"str","comparatorValue":"closed","propertyValue":"new_state.state"},{"targetType":"entity_id","targetValue":"sensor.humidity","propertyType":"current_state","comparatorType":">=","comparatorValueDatatype":"num","comparatorValue":"65","propertyValue":"new_state.state"}],"outputs":2,"customoutputs":[],"outputinitially":false,"state_type":"str","x":290,"y":2208,"wires":[["3501a613.6bfc1a"],["22307290.ff13be","cb1b7a5c.802358"]]},{"id":"22307290.ff13be","type":"debug","z":"ffbd7f06.4a014","name":"turn off switch","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":640,"y":2256,"wires":[]},{"id":"3501a613.6bfc1a","type":"trigger","z":"ffbd7f06.4a014","name":"","op1":"","op2":"","op1type":"nul","op2type":"pay","duration":"5","extend":false,"overrideDelay":false,"units":"min","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":630,"y":2208,"wires":[["486adfac.78ad3"]]},{"id":"486adfac.78ad3","type":"debug","z":"ffbd7f06.4a014","name":"turn on switch","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":800,"y":2208,"wires":[]},{"id":"cb1b7a5c.802358","type":"change","z":"ffbd7f06.4a014","name":"reset","rules":[{"t":"set","p":"reset","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":450,"y":2256,"wires":[["3501a613.6bfc1a"]]}]
2 Likes

Wow, thanks for the amazing examples, I’ll go grok them and see if I can get a better handle on the how to set up these flows.