I’m trying to make a row of buttons for ceiling fan control. I just want “off, low, medium, medium-high, high” buttons in a row, and one button at a time lights up to reflect current speed. I think I’ll be able to make the buttons reflect the state, but I’m having issues getting the template to work.
As of right now, with the following code, “off” works correctly, but if any other fan speed is selected, the sensor reports “low”. I must be missing something simple.
living_fan_off:
friendly_name: Living Room Fan Status
value_template: >-
{% if is_state('fan.living_room_ceiling_fan', 'off') %}
off
{% elif state_attr('fan.living_room_ceiling_fan', 'speed'), 'low' %}
low
{% elif state_attr('fan.living_room_ceiling_fan', 'speed'), 'medium' %}
medium
{% elif state_attr('fan.living_room_ceiling_fan', 'speed'), 'medium-high' %}
medium-high
{% elif state_attr('fan.living_room_ceiling_fan', 'speed'), 'high' %}
high
{% else %}
failed
{% endif %}
Maybe there’s an easier way to do this that I’m missing, but any help would be appreciated
Thanks for the suggestion. I just tried that and it made it only report “off”. When it do it with the close parenthesis after ‘speed’ it will report “off” when its off or “low” when its any other speed.
Basically I just have a horiz-stack of 5 buttons to set the fan speed and I want the states to be reflected. I have each card set up as below, and Off and Low are working fine. Is there a way I can just pull the state_attribute from the fan entity itself and use that in the state section of the card?
oh I just realized you were trying to set it up for ‘off’ right? if not
its either off,. or the next condition so:
living_fan_off:
friendly_name: Living Room Fan Status
value_template: >-
{% if is_state('fan.living', 'off') %}
off
{% else %}
{{ state_attr('fan.living', 'speed') }}
{% endif %}