Decide based on multiple device states

I’m new to HA and Node-RED, coming from Hubitat and webCoRE. I’m learning Node-RED so I can eventually port my simpler Hubitat and more complex webCoRE automations to HA.

I have a Hubitat automation that controls the lights in the garage. It does this:

  • When any of (Entry Door, Garage Door 1, Garage Door 2) are opened, turn on the lights.
  • When all of the doors are closed, wait 5 minutes, then turn off the lights.

This is how I have reproduced this in Node-RED:


The problem is that I don’t know how to express “when all of the doors are closed”. This flow will trigger the timer (and turn out the lights) after any door closes. So, for example, if you leave one or both garage doors open and then open and close the entry door, the lights will go out when the timer expires. I want them to stay on so long as the garage door is open. I feel like I should be able to use “current state” nodes for this, but I don’t know how to tie them together to express “entry door is open OR garage door 1 is open OR garage door 2 is open”.

I imagine this must be a common problem, but I’ve searched around for a while and haven’t found a solution. Maybe I’m just too new at this to recognize any solution I’ve found. :slight_smile:

[{"id":"5468a997.a24678","type":"trigger-state","z":"b248babf.5a9058","name":"","server":"","version":0,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityid":"sensor.door1, sensor.door2, sensor.door3","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.door3","propertyType":"current_state","comparatorType":"is","comparatorValueDatatype":"str","comparatorValue":"closed","propertyValue":"new_state.state"}],"outputs":2,"customoutputs":[],"outputinitially":false,"state_type":"str","x":264,"y":128,"wires":[["10dcdb46.4e6ed5"],["87183233.962d6"]]},{"id":"d23107fd.39d6b8","type":"api-call-service","z":"b248babf.5a9058","name":"","server":"","version":3,"debugenabled":false,"service_domain":"light","service":"turn_off","entityId":"light.garage","data":"","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":778,"y":128,"wires":[[]]},{"id":"87183233.962d6","type":"change","z":"b248babf.5a9058","name":"reset","rules":[{"t":"set","p":"reset","pt":"msg","to":"true","tot":"bool"},{"t":"set","p":"payload","pt":"msg","to":"{\"service\": \"turn_on\"}","tot":"json"}],"action":"","property":"","from":"","to":"","reg":false,"x":562,"y":176,"wires":[["d23107fd.39d6b8","10dcdb46.4e6ed5"]]},{"id":"10dcdb46.4e6ed5","type":"delay","z":"b248babf.5a9058","name":"","pauseType":"delay","timeout":"5","timeoutUnits":"minutes","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":572,"y":128,"wires":[["d23107fd.39d6b8"]]}]
1 Like

Thank you, that does the trick. It would not have occurred to me to try it this way.

(BTW, I would mark your post as the solution, but the checkbox isn’t showing up for me under the “three dots” menu.)

Alternative option, create a group. Check state of group. Groups also give you the option to define if all entity’s determine the state or only one.

all_door_locks:
  name: All Door Locks
  all: true
  entities:
    - lock.front_door_lock
    - lock.garage_door_lock
    - lock.mb_door_lock