You wouldnt beleive it. I tried almost that same code last night! the difference being the .attributes.speed part but sadly it did the same thing… I will try your code when I get home.
I had a look at the state of the fan when it goes to medium speed and instead of the state being medium it is on.
So I thought easy fix and tried the code below. By changing medium to on.
- id: '1536982795485'
alias: Fan2
trigger:
- entity_id: light.sonoff21
platform: state
action:
service: homeassistant.turn_on
entity_id: fan.pat_ceiling_fan
data_template:
speed: >
{% if states.fan.pat_ceiling_fan.state == 'off' %}
low
{% elif states.fan.pat_ceiling_fan.state == 'low' %}
medium
{% elif states.fan.pat_ceiling_fan.state == 'on' %}
high
{% elif states.fan.pat_ceiling_fan.state == 'high' %}
off
{% endif %}
But now it goes from low to high and the state is always ‘on’ not the speed. Is there a way to set the state from the automations code e.g. (code below). That way the state would not go to ‘on’ and then the if statement would work.
{% elif states.fan.pat_ceiling_fan.state == 'low' %}
states.fan.pat_ceiling_fan.state == 'medium'
medium
{% elif states.fan.pat_ceiling_fan.state == 'medium' %}
states.fan.pat_ceiling_fan.state == 'high'
high
The state will always be on or off. That’s why the if statement when looking at the state wasn’t working. You have to look at the speed attribute to compare.
I put the code above in my setup (using my details of course) and it worked exactly the way you want it to as far as my understanding of what you want…
I do this with a 4ch sonoff but am moving to the exact switch and ifan as you are trying to use ordered all gear this morning. I accomplish this by calling scenes which select the correct input and ensure others are switched off. If you can’t get it to work feel free to have a look at my github
Yeah it does concern me about lack of certification but that would drive prices up and lets face it that is their most attractive feature. I was contemplating using the Xiaomi wall switch but its design is based around UK wall plate dimensions and they don’t do anything more then a 2 gang switch. Certified wall plates are really expensive in Australia to the point it would make the project unfeasible.
finity, your code works!! but only once until I reload hass then it works again.Looking at the mqtt messages in MQTT.fx once it has completed one cycle its get stuck on fan speed 0 .
They look a bit nicer I think they seem to have the ctick logo hard to know I think you should be able to check a website for ctick approval is legit. I have already just purchased enough T1 to cover all my outlets.
Code below works but obviously you cant turn off the fan. So it must have something to do with how it passes the off state. Looking at the responses once you go from medium to high the state is always high unless you manually change the state.