I am using the following to set the state and hopefully the corresponding icon for the garage_door sensor:
template:
sensor:
- name: "garage_door"
state: >
{% if is_state('binary_sensor.gduppin', 'off') and is_state('binary_sensor.gddownpin', 'on') %}
Closed
{% endif %}
{% if is_state('binary_sensor.gduppin', 'on') and is_state('binary_sensor.gddownpin', 'on') %}
Moving
{% endif %}
{% if is_state('binary_sensor.gduppin', 'on') and is_state('binary_sensor.gddownpin', 'off') %}
Open
{% endif %}
icon: >
{% if is_state('sensor.garage_door', "Open") %}
mdi:garage-open-variant
{% endif %}
{% if is_state('sensor.garage_door', "Moving") %}
mdi:garage-alert-variant
{% endif %}
{% if is_state('sensor.garage_door', "Closed") %}
mdi:garage-variant
{% endif %}
The state template works fine, showing the proper value on the dashboard and updating as soon as the binary inputs change, but the icon displayed is always the garage-open-variant. It does not change regardless of the state. I tried changing the order of the icon template tests thinking it may just default to the first choice but that is not the case. I also tried with single quotes rather than double. That also had no affect.
Any suggestions greatly appreciated.
Hi and thanks for the quick response.
I am only reporting the status of the door at this point, not controlling it. So I thought a template sensor would avoid the control icon that a cover template would create on the dashboard.
I made the changes you suggested but nothing has changed. The door state still reports just fine but the icon is always the same (mdi:garage-open-variant).
I discovered this kinda buggy thing too. If you’re using a template sensor in this new style (as encouraged in the docs here), it doesn’t work. The “old” way does work as I found out.