Automation: Send message with all conditions which are true?

Tags: #<Tag:0x00007f328443f6f8>

Hi all, hope you are doing well!

I want to send myself a message when everyone has left the house but there are still doors/windows open. The following works, but I would like to include a list in the message of exactly which doors/windows are still open. Any suggestions on how to achieve that? Any help is greatly appreciated!

- alias: Melding Let Op
  description: ''
  trigger:
  - platform: state
    entity_id: input_boolean.presence_anyone
    to: 'off'
  condition:
  - condition: or
    conditions:
    - type: is_open
      condition: device
      device_id: 35c79f7e483dc4f101edff12257142b4
      entity_id: binary_sensor.woonkamer_deursensor_schuifpui_contact
      domain: binary_sensor
    - type: is_open
      condition: device
      device_id: 37293db8c2d0767a739de54ba7062e0c
      entity_id: binary_sensor.hal_deursensor_voordeur_contact
      domain: binary_sensor
    - type: is_open
      condition: device
      device_id: 20e84c9298aa620d82c9d55f083a4ff8
      entity_id: binary_sensor.garage_deursensor_garage_1_contact
      domain: binary_sensor
    - type: is_open
      condition: device
      device_id: 157fbc1687147b89754c4a1bad5203ab
      entity_id: binary_sensor.garage_deursensor_garage_2_contact
      domain: binary_sensor
    - type: is_open
      condition: device
      device_id: 13f252f32f60aec9a34b4d4024accc14
      entity_id: binary_sensor.badkamer_raamsensor_badkamer_contact
      domain: binary_sensor
  action:
  - service: notify.telegram
    data:
      message: '*LET OP:* Het huis is niet helemaal afgesloten!'
  mode: single
1 Like

Create a group containing your five contact sensors:

#group
  contact_sensors:
    entity_id:
    - binary_sensor.woonkamer_deursensor_schuifpui_contact
    - binary_sensor.hal_deursensor_voordeur_contact
    - binary_sensor.garage_deursensor_garage_1_contact
    - binary_sensor.garage_deursensor_garage_2_contact
    - binary_sensor.badkamer_raamsensor_badkamer_contact

Modify your existing automation to look like this:

- alias: Melding Let Op
  description: ''
  trigger:
  - platform: state
    entity_id: input_boolean.presence_anyone
    to: 'off'
  action:
  - variables:
      active: >
        {{ expand('group.contact_sensors') 
            | selectattr('state', 'eq', 'on')
            | map(attribute='name') | list }}
  - condition: template
    value_template: "{{ active | count > 0 }}"
  - service: notify.telegram
    data:
      message: '*LET OP:* Het huis is niet helemaal afgesloten! {{ active }}'
  mode: single

It will not send a notification if all contact sensors are off.

To test it, open a door and then manually execute the automation: Configuration > Automations > Melding Let op > Execute

OK, that sounds like a possible solution, thanks! :slight_smile: I will try this!