How to create automation that checks more than one device status?

Hello,
I would like to create an automation that checks if ALL my doors are closed (binary_sensor.XYZ_contact state to off) and ALL my Rolling Shutter as well closed (cover.rolling_shutter_switch_XYZ are in state closed), and if ALL those are in a desired state, then my input_boolean becomes on.
On the Automations I cannot handle the AND statement. AFAIK it works in OR, also the input_boolean would thange its state already if one door gets closed.
How to accomplish this?

Then I’ve another question. Is then possible to change, in the same automation, not only the input_boolean status, but the icon as well?

I would then use this input_boolean to trigger an alarm system later on.

Thanks a lot!

Simon

No need for an automation and input_boolean, you can use a binary_sensor.

Create a group containing all your doors.

group:
  all_door_entities:
    entities:
      - binary_sensor.door_main
      - binary_sensor.door_livingroom
      - binary_sensor.door_kitchen
      - binary_sensor.door_storageroom
      - binary_sensor.door_dressroom
      - binary_sensor.door_bathroomsmall
      - binary_sensor.door_bedroom
      - binary_sensor.door_bathroomlarge
      - binary_sensor.door_office

Create a binary_sensor that is on, when at least 1 door is open and off otherwise. The icon will be an open door when at least one door is open, otherwise it will be a closed door.

binary_sensor:
  - platform: template
    sensors:
      at_least_one_door_open:
        friendly_name: At least one door open
        value_template: >-
          {{ expand('group.all_door_entities')|selectattr('state','eq','on')|list|count > 0 }}
        device_class: door

Hello @Burningstone,
Thanks for the help. What about the cover.rolling_shutter_switch_000 which are in state open, closed, opening or closing? I need that they are in closed.
Thank you!

or…

  - alias: whatever name
    trigger:
      - platform: state
        entity_id: group.all_door_entities
        to: 'on'
    action:
       ...

will trigger when any of the group items changes to ‘on’. A similar approach can be used for an ‘off’ transition, or, checking for all “closing” or “closed”. The combinations are numerous. The binary_sensor might be an overkill - depends on what the final objective is.

1 Like

Hello @ninjaef,
Thanks you too… I ask you the same:
What about the cover.rolling_shutter_switch_000 which are in state open, closed, opening or closing? I need that they are in closed. So they are different entitiy types in the same group.
Thank you!

Yes, and the clue was in the response…

Modify the automation to cover the states, conditions, triggers you require
“search” tool is a great feature.

Thank you I’ll give it a try :wink:

It works! Now I’ve to play with the automations. Thanks again to both!

Simon

And read the docs on Groups and Automation. There are endless configs that can be created to account for a plethora of scenarios and requirements.
I am not suggesting binary_sensor is not suitable, it is indeed one way to cook the egg, but sometimes chunking up to a higher abstraction level is easier, more flexible, modular, and future proof (or as good as).

EDIT: Sorry, this post was sent at the same time you replied.

Also, when using automations, consider the impact of automation mode (it is described in the docs) which can on occasion yield undesired effects. The default is (when not specified) “single” but this can result in system behaviour that is not necessarily that which is expected or indeed, needed. That said, “single” might be totally suitable in certain use cases…

Yep, all should start from the RTFM approach, really true :slight_smile:
often I’m sure to use the right approach without knowing the thousend ways that egg could be cooked. Sometimes is a little difficult to have an overview about the different alternatives, for which, this forum does a great job.
Thank you @ninjaef !