Alternatives for scenes interrupted by updates

EDIT: discussions moved from Gladys Assistant 4.85.0 : widget Photo, navigation dans les graphiques, chauffe-eau & HomeKit - #21 par Will_71 to dedicate a specific topic.


Bravo to everyone for all these new features and improvements :heart_eyes:

I have a remark that almost bothers me with every update: the scenes that have an Wait in progress.
To make it simple, I start the pool pump for a duration that I define and therefore I have a Wait action for X hours. Unfortunately, when an update occurs, my Wait simply skips and if I’m not careful, the pool can run for 8 hours instead of 3 hours :frowning:
Apart from setting up MQTT variables to track an ongoing scene (which I should do), creating timestamps that I also store, and a script on (re)start of Gladys (by the way, does a boot trigger exist?), wouldn’t there be a (new?) something to resume these scenes where they were stopped?

Thanks for the feedback, and you’re pointing out a real limitation of the current implementation :slight_smile:

Technically, the « Wait » block is just a timer in memory in the Gladys process. Nothing is stored in the database: neither the fact that a scene is running, nor where it is in its list of actions. So, at the slightest restart (update, reboot, power outage), everything after the Wait is lost. It’s not a bug on your side, it’s just how it is today.

And yes, the « Gladys starts » trigger does exist, you’ll find it in the list of triggers.

But I would rather advise you to organize yourself so that you don’t need it.

The smartest thing in your case is to have the timer handled not by Gladys at all, but by the outlet itself. Most hardware can do « turn on and turn off by itself after X seconds ». It depends on what you have:

  • Shelly, with the HTTP Request action: http://<ip>/relay/0?turn=on&timer=10800 (Gen1) or http://<ip>/rpc/Switch.Set?id=0&on=true&toggle_after=10800 (Gen2+)
  • Zigbee2MQTT, with the Zigbee2MQTT action: on zigbee2mqtt/<your_pump>/set, you send {"state":"ON","on_time":10800,"off_wait_time":0}. It works on many Tuya/Moes/Aqara outlets and modules.
  • Tasmota: PulseTime 10900; Power ON (beyond 111, PulseTime equals value − 100 in seconds)

Your scene becomes a single action, no more Wait. And the huge advantage for a pool pump: even if your Gladys is cut off or the mini-PC doesn’t restart, the pump still stops.

If your hardware can’t do that, the second approach is a countdown rather than a wait.

You create a number feature via MQTT, like pool_pump_minutes_remaining. Your startup scene turns on the pump and sets the value to 180. Next to it, you make a monitoring scene with a scheduled trigger in interval mode every 5 minutes, which retrieves the value, continues only if it is > 0, rewrites it with the formula {{0.last_value}} - 5, and if it drops to 0 it turns off the pump. The formula mode works just as well on « Set a value » as in conditions, so everything is done with the mouse.

The interest is that it repairs itself: no need for a boot script or the startup trigger, the next cron run catches up on the situation. At worst, you lose the 5 minutes of the current tick.

And if you can settle for that, the simplest solution is two scheduled scenes, start at 10:00 a.m. and stop at 1:00 p.m. For a pool pump, this is often sufficient and it’s foolproof. If you adjust the duration to the water temperature, you can even have 3 stop scenes (12:00 p.m., 1:00 p.m., 2:00 p.m.) each with a condition on the temperature, it’s a bit brute force but it always works.

The principle to remember: the Wait is for short delays within a sequence, like 2 seconds between two commands or 30 seconds before checking a state. As soon as you exceed a few minutes, and especially when a shutdown action is involved, you need to either offload the timer to the hardware or use a stored state that is read regularly.

That said, your original request remains legitimate: persisting long Waits to reschedule them on startup is doable. If you want to open a feature request about it, don’t hesitate.

Excellent method I hadn’t thought of at all.
I have a NodOn SIN-4-1-21 and it seems possible:

On with timed off

When setting the state to ON, it might be possible to specify an automatic shutoff after a certain amount of time. To do this add an additional property on_time to the payload which is the time in seconds the state should remain on.

Additionally an off_wait_time property can be added to the payload to specify the cooldown time in seconds when the switch will not answer to other on with timed off commands.

Support depends on the switch firmware. Some devices might require both on_time and off_wait_time to work

Examples : {"state" : "ON", "on_time": 300}, {"state" : "ON", "on_time": 300, "off_wait_time": 120}.
And as I send myself a message at the end of the Wait, I will have to create a monitoring scene that checks every minute if the module is on or off.

Thanks for the tip!

I tried with the variable calculation {"state":"ON","on_time": 1.1. Pool (filtration_cycle_duration) *3600 ,"off_wait_time":0} and apparently it didn’t work :frowning:

Do I need to go through a temporary MQTT variable?
And the thing is, I have no way to see the command sent (nothing in Gladys logs, nothing in Z2M).

EDIT: eventually {"state":"ON","on_time":10800,"off_wait_time":0} doesn’t work either :frowning:

After some tests, you should not take the action Send a zigbee2mqtt message but Send an MQTT message otherwise it doesn’t work.
@pierre-gilles is there a specific difference between the 2 actions?

I tested {"state":"ON","on_time":60,"off_wait_time":10} in MQTT (not zigbee2mqtt) and it works, 1 minute later the pump stops properly.

I tested {"state":"ON","on_time":10800,"off_wait_time":10} and there is an issue, either on Gladys’ side or z2m, because everything is multiplied by 10 and therefore I have an out of range:

z2m: Publish 'set' 'state' to 'relais_03' failed: 'RangeError [ERR_OUT_OF_RANGE]: ZCL command 0x84b4dbfffe08ce6e/1 genOnOff.onWithTimedOff({"ctrlbits":0,"ontime":108000,"offwaittime":100}, {"timeout":10000,"disableResponse":false,"disableRecovery":false,"disableDefaultResponse":false,"direction":0,"reservedBits":0,"writeUndiv":false}) failed (The value of "value" is out of range. It must be >= 0 and <= 65535. Received 108000)'

Any ideas?

I continue my tests and the variables don’t work:


and in the z2m logs:

z2m: Invalid message 'undefined', skipping...

not very explicit…