Automation help - Window open in rain

I’d like to setup an automation that takes the input from OpenWeatherMap rain, Then sends me a notification that one of my windows is open from a list of 30.

The window sensors are all zigbee and grouped together. the notification works except it doesn’t contain which window is open,

The message line wraps itself after I save the automation regardless if I edit via the GUI or File directly. Im not wrapping it. HA is doing it, So im not sure if thats affecting it.

alias: 'Its Raining Close Windows '
description: Notify if A first Floor Window is optn
trigger:
  - platform: numeric_state
    entity_id: sensor.openweathermap_weather_code
    attribute: attribution
    above: '499'
    below: '532'
condition:
  - condition: state
    entity_id: group.windows
    state: 'on'
action:
  - service: notify.mobile_app_walter_app
    data_template:
      message: >-
        Rain Is Detected ;{% set domain =
        'binary_sensor' %}{% set state = 'on' %} {{ states[domain] |
        selectattr('state','eq', state) | selectattr('attributes.device_class',
        'eq', 'window') | map(attribute='name') | list | join(', ') }}
mode: single

If I understand your post, you are asking how to insert the name of all open windows in your notify message, correct?

I’m not really sure what you are trying to do with the posted code. In HA, what is the entity and the state (or attribute) that will tell you which window is open? To my knowledge there is no group attribute that will tell you which member of the group is on.

Sorry, So from the group of window sensors, Id like the message to contain the name of the specific sensor thats open. (list below)

I was under the impression that you could pull the specific sensor from the group that is triggering it on. Is that not the case?

The individual entites are:


  - entity: binary_sensor.bar_window
  - entity: binary_sensor.coralyn_window_1
  - entity: binary_sensor.coralyn_window_2
  - entity: binary_sensor.dining_room_window_1
  - entity: binary_sensor.dining_room_window_2
  - entity: binary_sensor.kitchen_window_1
  - entity: binary_sensor.kitchen_window_2
  - entity: binary_sensor.living_room_window_1
  - entity: binary_sensor.living_room_window_2
  - entity: binary_sensor.living_room_window_4
  - entity: binary_sensor.pantry_window_1

This is the template you want:

{{ expand('group.windows') | selectattr('state','eq', 'on') | map(attribute='name') | join(', ') }}

Used in the automation:

alias: 'Its Raining Close Windows '
description: Notify if A first Floor Window is optn
trigger:
  - platform: numeric_state
    entity_id: sensor.openweathermap_weather_code
    attribute: attribution
    above: '499'
    below: '532'
condition:
  - condition: state
    entity_id: group.windows
    state: 'on'
action:
  - service: notify.mobile_app_walter_app
    data_template:
      message: >-
        Rain Is Detected. Please close the following windows: {{ expand('group.windows') | selectattr('state','eq', 'on') | map(attribute='name') | join(', ') }}
mode: single

That didnt work either

Paste this into the Template Editor and open a few windows and tell us what it reports.

{{ expand('group.windows') | selectattr('state','eq', 'on') | map(attribute='name') | join(', ') }}

Clearly the template works because it reports all open windows.

I suspect your automation’s trigger is incorrect. You configured the Numeric State Trigger to listen for changes to an attribute called “attribution”.

  - platform: numeric_state
    entity_id: sensor.openweathermap_weather_code
    attribute: attribution  <------------- This
    above: '499'
    below: '532'

That can’t be correct. Why not? Because it’s common to most weather integrations and contains the name of the weather provider.

Screenshot from 2021-04-21 13-43-39

I believe you simply want the trigger to listen to the sensor’s state changes (and not one of its attributes). Therefore remove attribute: attribution from the trigger.

alias: 'Its Raining Close Windows '
id: its_raining_close_windows
description: Notify if A first Floor Window is open
trigger:
  - platform: numeric_state
    entity_id: sensor.openweathermap_weather_code
    above: 499
    below: 532
condition:
  - condition: state
    entity_id: group.windows
    state: 'on'
action:
  - service: notify.mobile_app_walter_app
    data_template:
      message: >-
        Rain Is Detected. Please close the following windows: {{ expand('group.windows') | selectattr('state','eq', 'on') | map(attribute='name') | join(', ') }}
mode: single

NOTE

Due to the way a Numeric State Trigger works, it will trigger only when the weather_code’s value changes from outside of the range to inside the range.

  • From a value below 499 to a higher value but below 532.
  • From a value higher than 532 to a lower value but above 499.

In other words, it only triggers when it crosses one of the two thresholds. It will not trigger if the value changes from 500 to 505 or from 529 to 512. All changes within the range will not trigger the automation.

Looks like I have to put this on hold for a moment.

Something is borked on my install. In the GUI yaml editor, there’s no longer a save button. and if I edit the automation.yaml file directly, Non of my automations load.

See here:

The top of my configuration.yaml looks like this:

# Configure a default setup of Home Assistant (frontend, api, etc)
default_config:
automation: !include automations.yaml
automation old: !include_dir_merge_list automations
binary_sensor: !include binary_sensors.yaml

automations.yaml is solely used by the editor, and I have a variety of hand-written YAML files in the automations folder, arranged into subfolders. The UI editor can’t touch these (which is good).

1 Like