In Home Assistant, I have an Inovelli blue smart fan switch (fan.living_room_fan_switch) and a fan (fan.living_room_fan). The fan is controlled by a Bond bridge and has six speeds.
I use Node Red to map fan switch button presses to specific fan speeds, which works well. When I control the fan via the physical switch, the fan.living_room_fan entity (Bond device) displays the right information:
But it is not reflected in the fan.living_room_fan_switch_fan entity (Inovelli switch):
I’d like to be able to control the fan by either clicking the physical switch, or by clicking on the fan entity in HA and selecting one of six speeds or off (like I can do with the Bond fan entity fan.living_room_fan). In either case, I’d like the Inovelli switch fan entity (fan.living_room_fan_switch_fan) to reflect the state of the fan. My attempt at this is below but it is not working. Could you please help me debug?
- platform: template
fans:
living_room_fan:
friendly_name: "Living Room Fan"
value_template: "{{ states('fan.living_room_fan') }}"
turn_on:
- service: fan.turn_on
target:
entity_id: fan.living_room_fan
turn_off:
- service: fan.turn_off
target:
entity_id: fan.living_room_fan
percentage_template: >
{{ state_attr('fan.living_room_fan', 'percentage') }}
speed_count: 6
set_percentage:
- service: fan.set_percentage
target:
entity_id: fan.living_room_fan
data:
percentage: "{{ percentage }}"
preset_modes:
- 'off'
- '1'
- '2'
- '3'
- '4'
- '5'
- '6'
preset_mode_template: > # syncs fan speed with fan entity in ha (control fan speed with switch)
{% if is_state('fan.living_room_fan', 'on') %}
{% set speed = state_attr('fan.living_room_fan', 'percentage') %}
{% if speed == 100 %}
6
{% elif speed == 83 %}
5
{% elif speed == 67 %}
4
{% elif speed == 50 %}
3
{% elif speed == 33 %}
2
{% elif speed == 16 %}
1
{% else %}
off
{% endif %}
{% else %}
off
{% endif %}
set_preset_mode: # syncs fan entity in ha with fan speed (control fan speed in ha)
- service: fan.set_percentage
target:
entity_id: fan.living_room_fan
data:
percentage: >
{% if preset_mode == '6' %}
100
{% elif preset_mode == '5' %}
83
{% elif preset_mode == '4' %}
67
{% elif preset_mode == '3' %}
50
{% elif preset_mode == '2' %}
33
{% elif preset_mode == '1' %}
16
{% else %}
0
{% endif %}