Include met condition in action notification

Working on an automation that will alert me if a window opens for > 30sec.
It’s binary sensor group that consists of 3 levels of binary sensor groups (room > upstairs/downstairs> all).
It currently shows me which window open (via expand()) in the notification which is great but I’d like to know which condition was met using the friendly, renamed name.

For example:

  1. Outdoor Temperature Is Below 50
  2. It’s raining or is in the forecast to do so

Just to clarify - not looking for help on the conditions themselves, just how to access the ‘met’ condition so that I can include it in the notification.

Post the automation.

I only have the one condition worked out right now but in the action message where it has ‘xyz’ I want it to say “Outdoor Temp Is Below 50” (the alias), if that is the condition met.
I don’t have any attempted code in there since I don’t know where to begin to grab the condition data

alias: Window Opened
description: ""
trigger:
  - platform: state
    entity_id:
      - binary_sensor.all_windows
    to: "on"
    for:
      hours: 0
      minutes: 0
      seconds: 30
condition:
  - condition: numeric_state
    entity_id: sensor.weather_home_outside_temperature
    below: 50
    alias: Outdoor Temp Is Below 50
action:
  - repeat:
      while:
        - condition: state
          entity_id: binary_sensor.all_windows
          state: "on"
      sequence:
        - service: notify.mobile_app_scotts_phone
          data:
            title: A window is open
            message: >-
              These windows need closed because xyz: {{
              expand('binary_sensor.all_windows')
                 | selectattr('state', 'eq', 'on') 
                 | map(attribute='name') 
                 | list 
                 | join (', ')
              }}
        - delay:
            hours: 0
            minutes: 5
            seconds: 0
            milliseconds: 0
mode: single
  • If the single condition is not met, no actions will be executed.

  • If you have multiple conditions logically ANDed then all must be met in order to execute the actions.

  • If you have multiple conditions logically ORed then at least one of them must be met in order to execute the actions. Which one was met is not communicated to the automation’s action.

Thanks. Yeah, understanding the flow isn’t a problem.

This answers my question though, unfortunately :slight_smile:

If it’s a single condition then there’s no reason to communicate it to the action. You know the condition is ‘Outdoor Temp Is Below 50’ so just enter that in message (i.e. hard-code it).

If it’s multiple ORed conditions and you want to know which one then you need to restructure the automation. I can explain what I mean but it would be helpful if you provided an example of the conditions you intend to use.

I appreciate it. Here’s a quick rewrite of it with some random ORed conditions

alias: Window Opened
description: ""
trigger:
  - platform: state
    entity_id:
      - binary_sensor.all_windows
    to: "on"
    for:
      hours: 0
      minutes: 0
      seconds: 30
condition:
  - condition: or
    conditions:
      - condition: numeric_state
        entity_id: sensor.weather_home_outside_temperature
        below: 50
      - condition: device
        device_id: ce5a8de3e151e1e68ad77e941d8af9a3
        domain: alarm_control_panel
        entity_id: alarm_control_panel.home
        type: is_armed_night
      - condition: device
        type: is_on
        device_id: 77d1cb552d033cb713d6ad36cbd00f4c
        entity_id: light.dining_room_light
        domain: light
action:
  - repeat:
      while:
        - condition: state
          entity_id: binary_sensor.all_windows
          state: "on"
      sequence:
        - service: notify.mobile_app_scotts_phone
          data:
            title: A window is open
            message: >-
              These windows need closed because the xyz: {{
              expand('binary_sensor.all_windows')
                 | selectattr('state', 'eq', 'on') 
                 | map(attribute='name') 
                 | list 
                 | join (', ')
              }}
        - delay:
            hours: 0
            minutes: 5
            seconds: 0
            milliseconds: 0
mode: single

I know we are on the same page but just to put it in here -

I want the notification message to say one of these:

  • These windows need closed because the Outdoor Temperature is Below 50: Living Room Window
  • These windows need closed because the Home is Armed Night: Living Room Window
  • These windows need closed because the Dining Room Light is On: Living Room Window
alias: Window Opened
description: ""
trigger:
  - platform: state
    entity_id:
      - binary_sensor.all_windows
    to: "on"
    for:
      seconds: 30
condition: []
action:
  - variables:
      temp_low: "{{ states('sensor.weather_home_outside_temperature') | float(0) < 50 }}"
      security_armed: "{{ is_state('alarm_control_panel.home', 'armed_night') }}"
      light_on: "{{ is_state('light.dining_room_light', 'on') }}"
      msg: >
        {{ 'Outside Temperature is Below 50' if temp_low else
           'Home is Armed Night' if security_armed else
           'Dining Room Light is On' if light_on' else 'zilch' }}
  - condition: "{{ msg != 'zilch' }}"
  - repeat:
      while:
        - condition: state
          entity_id: binary_sensor.all_windows
          state: "on"
      sequence:
        - service: notify.mobile_app_scotts_phone
          data:
            title: A window is open
            message: >-
              These windows need closed because {{ msg }}: {{
              expand('binary_sensor.all_windows')
                 | selectattr('state', 'eq', 'on') 
                 | map(attribute='name') 
                 | list 
                 | join (', ')
              }}
        - delay:
            minutes: 5
mode: single
1 Like

Thank you!
I need to get more comfortable with the templates.

You’re welcome!

If my suggestion has solved the original problem, please consider marking my post above with the Solution tag. It will automatically place a check-mark next to the topic’s title which signals to other users that this topic is resolved. This helps other users find answers to similar questions.

For more information about the Solution tag, refer to guideline 21 in the FAQ.