Automation CONDITION variables [Solved]

In the action part of an automation, I can use {{ trigger.to_state.attributes.friendly_name }} in the message part of a notification.
If the automation contains one ore more conditions, how can I use the name (or other info) of this condition to be used in the message to be sent?

My automation, which does not work as the platform time does not has the to_state:

alias: Deur/poort open Informatie
description: Controlleert op een tijdstip, of er nog deuren of poorten open staan
trigger:
  - platform: time
    at: "09:11:00"
condition:
  - type: is_open
    condition: device
    device_id: 3fd1069bead2701e31388937010a1568
    entity_id: ccfb0b293558795247ab02051f43f471
    domain: binary_sensor
    enabled: false
action:
  - service: notify.mail_to_<my name>
    metadata: {}
    data:
      title: Deur open van ID={{ trigger.id }}
      message: De {{ trigger.to_state.attributes.friendly_name }} is nog open
    enabled: true
mode: single

You know which device it is, you don’t need a template. Just use the name in text for whatever this refers to:

    device_id: 3fd1069bead2701e31388937010a1568
    entity_id: ccfb0b293558795247ab02051f43f471

Also you should consider not using device ids. See: Why and how to avoid device_ids in automations and scripts

I will change it to the name of the device.

How can I get the info from the section “Condition:” into the message?

You don’t need to. You know what device it is.

Ah, now I understand your first reply.

I understand, I was not clear enough. In the future, several devices will be put in the condition section. Like the example below.

conditions:
  - condition: or
    conditions:
      - condition: state
        entity_id: "P01_Door garden"
        state: "open"
      - condition: state
        entity_id: "P02_Door Shed"
        state: "open"
      - condition: state
        entity_id: "P03_Door Garage"
        state: "open"

In the mail message, I want the have the intity_id (or other info) from the door, which is open at the time given in the trigger section. For example, the email message should be “Deur open van P01_Door garden”.

I tried something like {{ condition.state.attributes.friendly_name }}, but that does not work.

This is not an entity id: entity_id: "P01_Door garden" nor are the others. The entity id will be like binary_sensor.something look in developer tools → states

No you can’t get that information from the conditions.

Create a group of your doors then use this in the message:

{{ expand('binary_sensor.group_of_doors')|selectattr('state','eq','on')|map(attribute='name')|list|join(', ') }}
1 Like

Thanks for the clarification.

I never used groups, but this evening I will learn something.

And you can simplify your conditions to only one:

conditions:
  - condition: state
    entity_id: binary_sensor.group_of_doors
    state: "on"

I also just noticed all your condition states are wrong as well. Binary sensors only have the state on or off despite what is shown in the frontend.

Works very well!
The full yaml is now:

alias: Deur/poort open Informatie
description: Controlleert op een tijdstip, of er nog deuren of poorten open staan
trigger:
  - platform: time
    at: "17:27:00"
condition:
  - condition: state
    entity_id: binary_sensor.alle_deuren
    state: "on"
action:
  - service: notify.mail_to_<me>
    metadata: {}
    data:
      title: Deur is open
      message: >-
        De volgende deur is nog open {{
        expand('binary_sensor.alle_deuren')|selectattr('state','eq','on')|map(attribute='name')|list|join(',
        ') }}
    enabled: true
mode: single

Where can I find the explaination if the line in the message?

Here: Templating - Home Assistant

And Here: Jinja — Jinja Documentation (3.1.x)

1 Like

Thanks. That is more than one evening to read… :wink:
I am happy to see, that Jinja has a data pass-through to Python :slight_smile: