Closed Fabaderheld closed 1 year ago
on_press is not the best choice for operations. you don't know if it will result in swipe, multi- or longpress. That's why I handle the relays in release. And why it should not do without wifi? Works always with or without HA.
and why you do a turn_on when wifi is connected, and otherwise toggle? So if connected you can not turn off the light? Or what is your idea behind?
Let me elaborate:
Two things are basis for this settings.
In case of a power outage I don't want the let's to turn on so I set the relays to ALWAYS_OFF
If HA is unavailable or the wifi is down I still want a safety net to turn the lights on.
So when the switch powers on I have to turn on the relay once, after that HA takes over. That's the wifi connected condition.
If HA and/or Wifi is down. It toggles the relay to to control the lights that way.
Ok, the allways off is a personal matter of opinion. I prefere to get into the last known state. If there is non known, then off. (but perhaps this is a good thing to make a substitution for the default of relais)
I'm not sure if my english is too bad to get it but, the switch works with or without ha for the relay. So you can always toggle the lights with the default behaviour of my code. But it's all in the "handle_release" Script.
But I'm not able to understand, why you will differ between connected and not connected in the on_touch. In your code, the panel will allways only turn_on the relay if HA is online and connected. If it toggle to off then this is only my code on release. (what will do its work anyway)
ah... one moment... I think now I get it... slowly :-D
You use smart bulbs and don't want to switch your relay in general. :-D That point was missing in the explanation ;) So you've set toggle_relay_1_on_touch to false in your yaml?
But anyways you should use release and not press for any touch logic to prevent toggle on long, multi or swipe.
And your variant only works with the 1-way switch. You have to check the touch position to check, which of the 3 relays you have to toggle/turn_on)
yes I forgot to mention I'm using smart bulbs.
yeah the code might need a little bit more polish. At the moment of writing it I only had the 1-way switch, and all my test cases seem to work (for me at least).
So I work on it, and maybe resubmit it. Thanks for your imput.
regards
Faba
Now when I understand the Idea behind I like it. ;) I'll take a look tomorrow if I can integrate it.
I think I'd do a substitution to activate this behaviour, if relais are decoupled.
Good to know, I only have the 2- and 3-ways ;)
Since I installed all my switches yesterday I figured out that this code is not working with 2 and 3 way switches, so I'll definitely work on it again or wait for what you come up with
I've added some conditions so in case Home Assistant or Wifi goes down, the switch will fallback to toggle the relay so the light stays controllable, improving the WAF.