There are sensors on doors and windows in every room. Although the names of these are in the form of “door” or “window”, I separate them according to their room names.
I have prepared an automation for all sensors in the system on a single automation as follows. It works smoothly.
But I want to get the name of the room in the warning title or message content and I just couldn’t do it. Can I access this information from device information or what route should I follow.
I would be very glad if you can forward with the sample.
thanks in advance.
alias: Security - Door and Window Sensors
description: ''
trigger:
- platform: state
entity_id: binary_sensor.kapi
- platform: state
entity_id: binary_sensor.hareket_sensoru_mutfak
condition: []
action:
- service: notify.notify
data:
title: Güvenlik Sistemi
message: >-
{% if trigger.to_state.attributes.device_class == 'motion' %} {% set
true_value='hareket algılandı' %}{% set false_value='temiz' %} {% elif
trigger.to_state.attributes.device_class == 'opening' %} {% set
true_value='açık' %}{% set false_value='kapalı' %} {% endif %} {{
trigger.to_state.name }}{%- if trigger.to_state.state == 'on' %}
{{true_value}} !!!{% elif trigger.to_state.state == 'off' %}
{{false_value}}.{% else %}{{ trigger.to_state.state }} {% endif -%}
mode: single
Is there an easier and healthier way as below, or will it be added?
In case of a change in room name etc., it seems more healthy to manage from one place.
In order to use this template in an automation’s action
{{ trigger.to_state.attributes.room }}
the two binary_sensors in the automation’s trigger
trigger:
- platform: state
entity_id: binary_sensor.kapi
- platform: state
entity_id: binary_sensor.hareket_sensoru_mutfak
must have room attributes. You must create the room attribute and assign it a value.
To create the room attribute for each binary_sensor, you can use Configuration > Customization or define it in the customize section of your configuration.yaml file as described here: