If would need to be a condition based action, based on what fan speed is currently selected. In ESPhome you can do if/then/else statements, but I’m not sure if you can do if/elseif/elseif/else or not…
There is likely a way to do this with lambda’s but I’m not skilled in writing those.
ESPhome code: (not complete)
</s> <s>button:</s> <s> - platform: gpio</s> <s> name: Fan Button</s> <s> id: button</s> <s> on_press:</s> <s> then:</s> <s> - if:</s> <s> condition:</s> <s> - switch.is_on: switch_low</s> <s> then:</s> <s> - switch.turn_off: switch_low</s> <s> - switch.turn_on: switch_med</s> <s> Hopefully you get the idea, but I would imagine there is a more elegant way to do this with lambda’s.
Thanks for the quick reply. Unfortunately, I do not quite understand the solution. I have a button and would like to achieve a different state with each press on it. So the speed Slow Medium and Fast or Off. In C++ this would probably be a counter from 0 to 3 and the assignment via a switch-case statement. This should be possible with ESPHome! Only I do not know how…
With the fan domain you can create components that appear as fans in the Home Assistant frontend. A fan can be switched on or off, optionally has a speed between 1 and the maximum supported speed of the fan, and can have an oscillation and direction output.
How is this supposed to help me with my automation in the device? I have read everything and think that this is mainly about the front end. If I’m wrong please show me a solution with the platform gpio so a physical button.
No worries Dave, I used your example further up in this thread to change my fan from 3 buttons and 1 switch to the correct way with fan speeds. RF remote fan control
The fan declaration does not exist for me because I did not know it yet. Honestly, I also do not know how to set this with me. I would like to switch only three solid state relays. Show you my code so far. The switches represent the relays. The push button is connected to D5.
Wow thanks for doing the work and rewriting the program. That’s how it works already. Thank you very much. One question for understanding…
Let’s say I have a device with three relays so no fan or something like that. Would I have to solve the task in the same way? I don’t understand why this is so complicated.
The rewrite was a mash up of yours and @sparkydave’s.
I’m not sure I understand your question, can I suggest you keep looking into ESPHome as that’s the only way you’ll understand it. Take this script/program/sketch for example and look into why it does what is does.
Yes that’s true I still have a lot to learn. Unfortunately, there are not so many examples of automation with esphome. If you have a source, please send it to me. I thank you again for your help.