For each window I create sensor template which show the state open/tilt/closed. This works fine.
Now, I´d like to create an similar template which shows that all windows closed, if they are all closed.
template.yaml
sensor:
- name: "Alle Fenster"
state: >
{% if is_state('binary_sensor.fenster_eltern_offen', 'on') and
is_state('binary_sensor.fenster_ankleide_offen', 'on') and
is_state('binary_sensor.fenster_bad_og_offen', 'on') %}
geschlossen
{% endif %}
icon: >
{% if is_state('binary_sensor.fenster_eltern_offen', 'on') and
is_state('binary_sensor.fenster_ankleide_offen', 'on') and
is_state('binary_sensor.fenster_bad_og_offen', 'on') %}
mdi:window-closed-variant
{% endif %}
with the above code there is no content in the entity, see below.
If the type of the sensor is set right and your locale is set right, you should get translated texts for all entities (Dutch in my case). Don’t you? Creating entities for everything ou wat translated is not maintainable in the long run.
Greate a group helper in the helpers section of the settings and add the window or door sensors. In the configuration options, tell if it is a door or a window to get the right icons and translations. The door or window group should show translations for open and closed, even though in developer options, the real values of the sensor are on / off. 0 and 1 are not values that should be used for door/windows sensors., even kf they are called binary_sensors.
What you do here, is taking all binary_sensors, select if they have device_class definied, if so, take only the device_class “window”, where the state is ‘on’ and display the names as a list.
You can as well use it a little more “displayable”, with something like this:
{%- for entity in states.binary_sensor | selectattr('attributes.device_class', 'defined') | selectattr('attributes.device_class', 'search', 'window') | selectattr('state', 'eq', 'on') | list -%}
{{ entity.attributes.friendly_name }}{% if not(loop.last) %}, {% endif %}
{% endfor %}
No need for a group, just make sure, your actual window sensors have the correct device class, and future additions do to.
if I understand correct the code it search and displays the open window?! Isn´t it?
I just want to show in dash, “all windows closed”. thats it
The problem with groups is, it´s activated if one of the members state “on”. the binary window sensors are state “on” when windos is closed…
I need to invert the sensor. May I need to configure the group I a yaml?
Thanks Petro,
but with your code it just send me the name.
Im my case, if I open the garage I receive the notification:
“Garagentor links” (only the name of the entity)
I would like to receive the state as well.
“Gargentor links offen”
Garagentor links geschlossen"