Automation Help - Fan Setting

I have a switch that I’m trying to write automation for and I could use some help.

The switch has four buttons on the front. There is a toggle for the light, and there are high medium and low buttons for the fan. The light toggle is easy and works as expected. The issue I am having is with the fan.

The switch uses local tuya and in the debugger I can see that the high, middle, and low setting for fan control is persistent whether the fan switch is on or off. The way you toggle the fan switch, is to press the speed button of your choice to turn it on, or the currently turned on speed setting to turn it off.

Here are some scenarios that I need to account for.

If the fan setting is off and I select the high speed setting it should turn the fan on too high. Writing the automation to simply look and see if the fan speed setting is changed to high works, but only if the prior speed setting was not already set to high. The automation should account for the fact that the fan is being turned on and the speed setting is set to high.

If I write a condition saying that the fan position also needs to be set to on, the automation does not work as the switch was being turned on at the same time that it was set to high. Essentially I just need a way to see if the new state of the automation trigger is setting equals on and that should fix it.

How can I ride my automation so this will work properly?

Thank you community in advance!

i’m not 100% sure i understand the problem. you said:

is the issue that if the fan was already previously set to high, but is currently off, trying to set it to high does nothing? but if it was not set to high, then you can safely set it to high and it will turn the fan on and change the speed to high properly?

if that’s what you mean, first, are you sure you have the local tuya config for the fan right? here’s someone who had a somewhat similar issue but in reverse: https://www.reddit.com/media?url=https%3A%2F%2Fpreview.redd.it%2Flocal-tuya-fan-speed-control-v0-693k2ns88u7b1.png%3Fwidth%3D495%26format%3Dpng%26auto%3Dwebp%26s%3D64f927f1941e94480970ca47011fb693a487f24d

there’s usually one control for on/off and a separate control(s) to set the speed under the covers… even if it’s presented combined.

that said, if there isn’t, and if my understanding of the problem is right… a hack around you could potentially do is to always set the speed to low, then medium, then to the correct target.

if my understanding of the issue is incorrect, please correct my misunderstanding.
also you said you have it mostly working. when you have code that’s partially there, please post it. it’s much easier for us to understand your intent and tweak it if we can see your code rather than ask us to write it all from scratch and duplicate work you’ve already done.