First time to these forums and relatively new home assistant user, so thank you in advance for your patience.
To explain my set up first up, I have some momentary switches (normally open) connected to some Shelly 1PMs which are connected via MQTT to mosquito - all that is working nicely, and I’ve been able to create an automation based on the relay activation using the UI.
Now, I want to go to “step 2” and get a bit more advanced, but I’m a little stuck as the UI options don’t appear to provide me what I need to do from an automation perspective, which is basically; when the push button is held down for longer than a second, start dimming the globe (90%-80%-70%, etc until the push button is released). Is this possible?
When I think of the UI I think of really basic (if this happens, do this), but no looping conditions which I think would be required for this - e.g some kind of loop that basically fires on push button activation after 1 second, that basically says "while (push button=active) do { dim by 10%; sleep 100ms }.
Is something like that possible, has anyone done anything like this and can guide?
It’s only possible if your Shelly 1PMs can send a button released event. You run the dimming loop until this event is received.
You can’t do this with Lovelace UI buttons because while there is a hold event to trigger the start of the dimming there is no release event to stop it.
So in MQTT explorer, input/0 goes to 1 when the button is pressed, stays as 1 when the button is held, and goes to 0 when it’s released - would this be satisfactory, it’s essentially a state change?
Have a look at the new script options, particularly repeat until
You want to trigger on the button being pressed (button state = ‘on’) and repeat a loop of dimming one step, then delay, until the button is released (button state = ‘off’), or you reach a brightness of 0.
If you get this working it is a short step to being able to reverse the action. i.e. first long press = dimming, release, second long press = brightening, release, third long press = dimming again, etc…
Actually you might want to trigger on the button state being ‘on’ for: at least 1 second. So you can still use short taps for togging the light on/off.