I created a sensor that should show the combined status of two binary sensors, that is working as intended. However , I can´t get the Icon template to behave as I´d like.
It works fine in the template editor:
But if I check the state, wrong icon is showing:
What am I doing wrong?
The sensor:
- platform: template
sensors:
front_door_combined:
friendly_name: "Ytterdörr"
entity_id:
- binary_sensor.1_front_door_lock
- binary_sensor.2_front_door
value_template: >-
{% if not states('binary_sensor.2_front_door') == 'undefined' %}
{% if is_state('binary_sensor.2_front_door', 'off') %}
{% if is_state('binary_sensor.1_front_door_lock', 'off') %}
Låst
{% else %}
Stängd
{% endif %}
{% else %}
Öppen
{% endif %}
{% else %}
Undefined
{% endif %}
icon_template: >-
{% set front_door = states('sensor.front_door_combined') %}
{% if front_door == 'Låst' %}
mdi:cellphone-lock
{% elif front_door == 'Stängd' %}
mdi:door-closed
{% elif front_door == 'Öppen' %}
mdi:door-open
{% else %}
mdi:alert
{% endif %}