Equal / recurring notification messages based on similar settings in different rooms - how to approach best

Dear Home Assistant Community,

my smart home is growing and growing and more and more sensors are finding their way to my home. One think I could not figure out directly although by googling is the following:

Imagine on automations which are equal but differ by a room. For instance, I have five rooms, each with a temperature and humidity sensor. I want to achieve a notification for each room if the humidity in the room is above 65%, in the end it is something like the following:

“Humidity in is above 65%, open the window and leave some fresh air in”

Another automation could be if temperate falls below a certain degree in a room, that also a message could be dropped. Motion sensors in each room switching off the light after a certain amount of time without action maybe another idea, so I can imagine of enough use cases.

But in the end I don’t want to write the same automation for each room / sensor again, as it will be redundant in many parts. So what would be the best approach for that?? Maybe someone has similar automations and can share some examples?

I combine them in one automation and tgen use the trigger object to determine which entity caused the change. E.g.

This automation notifies me when a window has been open for more than x minutes (where x depends on the time of the year) and the message will be
“The window in the livingroom has been open for 5 minutes. Please close.”

This can be “easily” done in one automation as well. Create a binary sensor for each room that will be on if there is motion and off if there’s no motion for x minutes and give it a menaingful name. Then in the automation you trigger whenever one of these binary sensors changes to ‘off’ and turn off the respective room light by uaing the name of rhe binary sensor to get the name of the lights to turn off.

Hi @Burningstone,

thanks for the tipps and insights to your configuration. This was very helpful, especially the hint to the motion sensors. I guess this will also be the key for my window automations.

As I don’t have any window sensors (yet), I’m using temperature sensors combined with a certain below value for doing this (and here it is a mixture between real zigbee temperature sensors and climate sensors. A message like “Current temperature bathroom is open, please close it”, seems not to be that beatiful, so I guess the trick will be to define a binary sensor named “Window bathroom” which then takes into account the bathroom temperature".

Mmh… I’m getting an error and I cannot see why…

- id: notify_on_window_left_open
  alias: "Benachrichtigung wenn ein Fenster oder eine Türe zu lange offen ist"
  mode: parallel
    - platform: state
        - binary_sensor.window_bathroom_middle
        - binary_sensor.window_bathroom_attic
        - binary_sensor.window_nele
        - binary_sensor.window_niclas
        - binary_sensor.window_livingroom
        - binary_sensor.window_basement
        - binary_sensor.window_bedroom
      to: 'on'
      for: "00:01:00"
    - service: notify.mobile_app_xiaomi_redmi_note_9_pro_daniel
        title: "Fenster zu lange geöffnet"
        message:  >
          {{ state_attr(trigger.to_state.entity_id, 'friendly_name') }}
          ist noch immer geöffnet. Bitte schliessen.

Here is the exeption from the log, does anyone has an idea?

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 353, in async_render
    render_result = compiled.render(kwargs)
  File "/usr/local/lib/python3.8/site-packages/jinja2/environment.py", line 1090, in render
  File "/usr/local/lib/python3.8/site-packages/jinja2/environment.py", line 832, in handle_exception
  File "/usr/local/lib/python3.8/site-packages/jinja2/_compat.py", line 28, in reraise
    raise value.with_traceback(tb)
  File "<template>", line 1, in top-level template code
  File "/usr/local/lib/python3.8/site-packages/jinja2/sandbox.py", line 407, in getattr
    value = getattr(obj, attribute)
jinja2.exceptions.UndefinedError: 'trigger' is undefined

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 188, in async_prepare_call_from_config
    service_data.update(template.render_complex(config[conf], variables))
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 93, in render_complex
    return {
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 94, in <dictcomp>
    render_complex(key, variables): render_complex(item, variables)
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 98, in render_complex
    return value.async_render(variables)
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 355, in async_render
    raise TemplateError(err) from err
homeassistant.exceptions.TemplateError: UndefinedError: 'trigger' is undefined

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 250, in _async_step
    await getattr(
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 429, in _async_call_service_step
    domain, service_name, service_data = service.async_prepare_call_from_config(
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 190, in async_prepare_call_from_config
    raise HomeAssistantError(f"Error rendering data template: {ex}") from ex
homeassistant.exceptions.HomeAssistantError: Error rendering data template: UndefinedError: 'trigger' is undefined

Did you trigger it manually? If so, then it is normal that you get an error, because there’s no trigger.

Damn… yes sure… these template things do not work correctly when testing them from the auomation hitlist. Thx.