Area of a trigger

I have an automation to look if it’s outside hotter/colder than inside.
I would like to make in generic as possible to be able to use it for all rooms.

I tested in the developer tools, but it looks like the trigger don’t work as axpected.
e.g
{{ area_name('sensor.thermostat_kuche_simon_temperature')}} {{floor_name('sensor.thermostat_kuche_simon_temperature')}}

result: Küche 1. Stock
Perfect!

Okay thought let’s implement it:

data:
  message: >-
    Fenster auf! - Draußen ist es Wärmer als in {{
    area_name('trigger.entity_id')}} {{floor_name('trigger.entity_id')}} 
action: notify.matrix_harms_vorhop

Result:
Fenster auf! - Draußen ist es Wärmer als in None None

Why?

The complete automation:

alias: Test - Temperatur indoor vs outdoor
description: ""
triggers:
  - entity_id:
      - sensor.thermostat_kuche_simon_temperature
    id: kaelter
    trigger: numeric_state
    for:
      hours: 0
      minutes: 5
      seconds: 0
    below: sensor.ems_esp_boiler_outdoortemp
  - entity_id:
      - sensor.thermostat_kuche_simon_temperature
    id: waermer
    trigger: numeric_state
    for:
      hours: 0
      minutes: 5
      seconds: 0
    above: sensor.ems_esp_boiler_outdoortemp
  - entity_id:
      - sensor.schlafzimmer_shellytrv_simon_temperature
    id: kaelter
    trigger: numeric_state
    for:
      hours: 0
      minutes: 5
      seconds: 0
    below: sensor.ems_esp_boiler_outdoortemp
  - entity_id:
      - sensor.schlafzimmer_shellytrv_simon_temperature
    id: waermer
    trigger: numeric_state
    for:
      hours: 0
      minutes: 5
      seconds: 0
    above: sensor.ems_esp_boiler_outdoortemp
conditions: []
actions:
  - alias: Test mehr als 2 Fenster
    if:
      - condition: template
        value_template: |-
          {{ area_entities(area_name('trigger.entity_id'))
            | select('match', 'binary_sensor.*fenster*') | list | count > 1 }}
    then:
      - action: matrix.send_message
        metadata: {}
        data:
          target: "!kieWnhLSTvrErkkdlP:matrix.org"
          message: Mehr als 1 Fenster
  - choose:
      - conditions:
          - condition: trigger
            id:
              - kaelter
        sequence:
          - if:
              - condition: state
                entity_id: input_text.vorhop_weather_forecast
                state: warm
            then:
              - alias: Genau ein Fenster vorhanden? - warm
                if:
                  - condition: template
                    value_template: |-
                      {{ area_entities(area_name('trigger.entity_id'))
                        | select('match', 'binary_sensor.*fenster*') | list | count == 1 }}
                    alias: Genau ein Fenster vorhanden?
                then:
                  - alias: Fenster geschlossen?
                    if:
                      - condition: template
                        value_template: |2-
                           {{ states((area_entities(area_name('trigger.entity_id'))
                            | select('match', 'binary_sensor.*fenster*') | list)[0]) == "off" }}
                        alias: Fenster geschlossen?
                    then:
                      - data:
                          message: >-
                            Fenster geschlossen halten! - Draußen ist es Wärmer
                            als in {{ area_name('trigger.entity_id')}}
                            {{floor_name('trigger.entity_id')}}
                        action: notify.matrix_harms_vorhop
                    else:
                      - data:
                          message: >-
                            Fenster zu! - Draußen ist es Wärmer als in {{
                            area_name('trigger.entity_id')}}
                            {{floor_name('trigger.entity_id')}}
                        action: notify.matrix_harms_vorhop
                else:
                  - data:
                      message: >-
                        Fenster zu! - Draußen ist es Wärmer als in {{
                        area_name('trigger.entity_id')}}
                        {{floor_name('trigger.entity_id')}}
                    action: notify.matrix_harms_vorhop
            else:
              - alias: Genau ein Fenster vorhanden? - nicht-warm
                if:
                  - condition: template
                    value_template: |-
                      {{ area_entities(area_name('trigger.entity_id'))
                        | select('match', 'binary_sensor.*fenster*') | list | count == 1 }}
                    alias: Genau ein Fenster vorhanden?
                then:
                  - alias: Fenster offen?
                    if:
                      - alias: Fenster offen?
                        condition: template
                        value_template: |2-
                           {{ states((area_entities(area_name('trigger.entity_id'))
                            | select('match', 'binary_sensor.*fenster*') | list)[0]) == "on" }}
                    then:
                      - data:
                          message: >-
                            Fenster offen lassen! - Draußen ist es Wärmer als in
                            {{ area_name('trigger.entity_id')}}
                            {{floor_name('trigger.entity_id')}}
                        action: notify.matrix_harms_vorhop
                    else:
                      - data:
                          message: >-
                            Fenster auf! - Draußen ist es Wärmer als in {{
                            area_name('trigger.entity_id')}}
                            {{floor_name('trigger.entity_id')}}
                        action: notify.matrix_harms_vorhop
                else:
                  - data:
                      message: >-
                        Fenster auf! - Draußen ist es Wärmer als in {{
                        area_name('trigger.entity_id')}}
                        {{floor_name('trigger.entity_id')}}
                    action: notify.matrix_harms_vorhop
      - conditions:
          - condition: trigger
            id:
              - waermer
        sequence:
          - if:
              - condition: state
                entity_id: input_text.vorhop_weather_forecast
                state: warm
            then:
              - alias: Genau ein Fenster vorhanden? - warm
                if:
                  - condition: template
                    value_template: |-
                      {{ area_entities(area_name('trigger.entity_id'))
                        | select('match', 'binary_sensor.*fenster*') | list | count == 1 }}
                    alias: Genau ein Fenster vorhanden?
                then:
                  - alias: Fenster offen?
                    if:
                      - alias: Fenster offen?
                        condition: template
                        value_template: |2-
                           {{ states((area_entities(area_name('trigger.entity_id'))
                            | select('match', 'binary_sensor.*fenster*') | list)[0]) == "on" }}
                    then:
                      - data:
                          message: >-
                            Fenster offen lassen! - Draußen ist es kälter als in
                            {{ area_name('trigger.entity_id')}}
                            {{floor_name('trigger.entity_id')}}  
                        action: notify.matrix_harms_vorhop
                    else:
                      - data:
                          message: >-
                            Fenster auf! - Draußen ist es kälter als in {{
                            area_name('trigger.entity_id')}}
                            {{floor_name('trigger.entity_id')}}  
                        action: notify.matrix_harms_vorhop
                else:
                  - data:
                      message: >-
                        Fenster auf! - Draußen ist es kälter als in {{
                        area_name('trigger.entity_id')}}
                        {{floor_name('trigger.entity_id')}} 
                    action: notify.matrix_harms_vorhop
            else:
              - alias: Genau ein Fenster vorhanden? - nicht-warm
                if:
                  - condition: template
                    value_template: |-
                      {{ area_entities(area_name('trigger.entity_id'))
                        | select('match', 'binary_sensor.*fenster*') | list | count == 1 }}
                    alias: Genau ein Fenster vorhanden?
                then:
                  - alias: Fenster geschlossen?
                    if:
                      - alias: Fenster geschlossen?
                        condition: template
                        value_template: |2-
                           {{ states((area_entities(area_name('trigger.entity_id'))
                            | select('match', 'binary_sensor.*fenster*') | list)[0]) == "off" }}
                    then:
                      - data:
                          message: >-
                            Fenster geschlossen halten! - Draußen ist es kälter
                            als in {{ area_name('trigger.entity_id')}}
                            {{floor_name('trigger.entity_id')}}
                        action: notify.matrix_harms_vorhop
                    else:
                      - data:
                          message: >-
                            Fenster zu! - Draußen ist es kälter als in {{
                            area_name('trigger.entity_id')}}
                            {{floor_name('trigger.entity_id')}}  
                        action: notify.matrix_harms_vorhop
                else:
                  - data:
                      message: >-
                        Fenster zu! - Draußen ist es kälter als in {{
                        area_name('trigger.entity_id')}}
                        {{floor_name('trigger.entity_id')}}
                    action: notify.matrix_harms_vorhop
mode: parallel
max: 10

Remove the single quotes so you are using the variable, not the string “trigger.entity_id”.

area_name('trigger.entity_id') should be area_name(trigger.entity_id)

1 Like

Hmm, will give it a try, but when I test this in the developer tools i get this error:

{{ area_name(sensor.thermostat_kuche_simon_temperature)}} {{floor_name(sensor.thermostat_kuche_simon_temperature)}} 

sensor is undefined

In the Template tool example, you are providing an entity ID string, so it should be wrapped in quotes… but in the automation you are providing a variable that needs to be rendered to produce the desired entity ID string value.

1 Like