This seems to possibly be related to upgrading to the .8 release, but I can’t be certain. I have a 2-speed attic/whole house/ventilation fan that I setup with 2 relays to run it at ‘high’ speed (100%) and ‘low’ speed (50%) using a Shelly Plus 2PM (I would have used ESPHome, but alas, the Shelly Plus don’t seem to have an ESPHome config that also allows you to also use them as a BT Proxy, which I also want).
I setup a template fan a month or two ago to manage all of this and did a fair bit of testing through every possible scenario (both on my bench and installed) to make sure it all worked exactly as intended, as I particularly didn’t want it to turn on both relays simultaneously. Everything seemed to work fine at the time (this would have been back on the .6 release I believe). Fast-forward to now, and we finally get some weather where it makes sense to use, and while the fan/relays function as-intended, whenever I go from 50% to 100% speed it shows 0% speed but also ‘on’ yet is actually running at 100%. I’ve played around with the template a bit trying to get it to work again, but no luck.
- platform: template
fans:
attic_fan:
friendly_name: "Attic fan"
unique_id: attic_fan
value_template: >
{% if ((states('switch.attic_fan_low') == "on") or (states('switch.attic_fan_high') == "on")) %}
on
{% else %}
off
{% endif %}
percentage_template: >
{% if states('switch.switch.attic_fan_high') == "on" %}
100
{% elif states('switch.attic_fan_low') == "on" %}
50
{% else %}
0
{% endif %}
turn_on:
if:
- condition: template
value_template: >-
{{ ((states |
selectattr('entity_id','in',state_attr('binary_sensor.screen_windows','entity_id'))
| selectattr('state','eq','on') | list | count | int) >2) }}
then:
- action: switch.turn_off
target:
entity_id: switch.attic_fan_low
- action: switch.turn_on
target:
entity_id: switch.attic_fan_high
turn_off:
- service: switch.turn_off
target:
entity_id: switch.attic_fan_low, switch.attic_fan_high
set_percentage:
if:
- condition: template
value_template: >-
{{ ((states |
selectattr('entity_id','in',state_attr('binary_sensor.screen_windows','entity_id'))
| selectattr('state','eq','on') | list | count | int) >2) }}
then:
- action: "switch.turn_{{ iif(percentage == 50, 'on' , 'off') }}"
target:
entity_id: switch.attic_fan_low
- action: "switch.turn_{{ iif(percentage == 100, 'on', 'off') }}"
target:
entity_id: switch.attic_fan_high
speed_count: 2
I tried adding some short delays into the set_percentage sequence and updated to the new action instead of service call with no change. I also changed the order of the actions in set_percentage thinking that there was a momentary period where both relays were off, but this also didn’t change anything. Also, in case it isn’t obvious, the if-thens are to make sure it only is operable if at least 2 windows are open.
What am I missing?