Virtual timers across ecosystems: what should happen after a hub restart?

The request for virtual switches and countdown timers on the M3 raises a recovery question: Feature Request: Virtual Switches / Timers exported to Matter & HomeKit (Hub M3)

Suppose a virtual timer turns off a desk lamp after ten minutes, but the hub restarts before it expires. Should the timer resume the remaining time, cancel visibly, or run the overdue action when the hub returns? I would want the chosen policy shown explicitly, with the expiry time and whether the action actually ran. A restored switch state alone would not tell another ecosystem whether a timer completed.

For anyone already bridging timer helpers between Aqara and another platform, how do you prevent a restart from replaying an old action? This is a design question, not a claim that the M3 currently exposes virtual timers.

3 Likes

So in Home Assistant you can create virtual switches (Helpers → Create Toggle) and under “Each time Home Assistant starts” you have three options: “Restore previous state”, “Turn on” or “Turn off”. This allows you to decide for yourself depending on the use case.

A virtual timer can also be created (Helpers → Create Timer) and here too you can choose whether or not to activate the option “Restore state and time when Home Assistant starts”.

In the current version of Home Assistant you can also see during a restart whether automations are still running that your restart would interrupt, and you can decide whether to restart immediately or later.

The virtual switches can then be passed on to Apple or Aqara Home via a virtual Matter bridge. But I believe the timer cannot be shared via Matter. I think there is no suitable cluster for it, right?

Otherwise it is very practical to be able to pass on such a virtual switch. For example, I use this with the car. An iPhone Shortcut turns a switch on when connecting to CarPlay and off when disconnecting. So in Home Assistant I can see who is currently in the car.

In this case restoring the switch state is certainly the most sensible choice, because the probability that HA fails or restarts right when the iPhone connects or disconnects from CarPlay is quite low. However, that does not rule out incorrect states occurring. For instance, if the switch is active, HA restarts, and the Shortcut executes upon CarPlay disconnect at that exact moment, the virtual switch remains active. The state would correct itself at the latest with the next disconnect.

Had the setting been chosen so that the switch turns off after a restart, the error would already be corrected the next time CarPlay connects. But in HA it would look as though the person is not currently driving the car, even though they still are. And the likelihood of HA restarting while you are driving is also higher.

So you can see that such problems can be handled in different ways, but it is difficult to rule out errors entirely. It makes sense to weigh the probabilities. For example, not setting the switch to on after a restart when a restart is most likely to happen while you are not in the car, which would basically set the “driver status” to currently “driving”.

2 Likes

Your CarPlay example makes the tradeoff clear: restoring a value can preserve a missed disconnect just as forcing it off can erase a valid state. For a countdown, I would want the bridge to show the expiry time and a separate completed/cancelled/unknown result, rather than asking another platform to infer completion from a switch. Have you tried restarting HA while a short timer expires, and checking what the receiving platform actually sees? I have not verified direct Matter timer support, so I would keep that separate from the virtual-switch workaround.

1 Like

As previously mentioned, there is no standalone timer device type in Matter. Therefore, it is not possible to send a timer over Matter to another system, so you inevitably have to resort to using a virtual switch.

Devices such as washing machines, clothes dryers, dishwashers, and robot vacuums feature an optional CountdownTime attribute as well as operational states (Running, Paused, Stopped). Cooktop and microwave appliances allow you to set cooking times and monitor the remaining duration. You could theoretically repurpose one of these devices to get a timer into Apple or Aqara, but I strongly doubt that an interactive countdown timer widget is built into those apps. And it is also questionable whether you can use that in if conditions.

However, it doesn’t work with the virtual Matterbridge I’m using straight away. Either you’d have to write some code yourself, or you’d have to find something like that. Although I haven’t actually checked, there’s almost certainly something available for HA.

2 Likes

I think to answer your question we must ask another one:

What is the general purpose of the timer?

Use Case 1: Delay/trigger of an action

Usually if we delay an action (in most cases in an automation), we actually do not want the timer to delay the action exactly by the specified time. For example, if I use “delay 10s”, I will actually settle for 10-15s. But not 1-60min, as it may cause an unexpected side effects (for example: I’ve expected that an automation failed at this point and another automation ran).

I’ve had one case when some third party Matter device fired a trigger very late (in the middle of the night), disabling my camera on a night when I really wanted to see what happened during the night.

Use Case 2: Scheduling an action

So it’s kind of similar, but actually different. When we schedule an action, we want to fire it in the future (eventually). So if I schedule my automation to run at 7:00 every day, then 7:02 will also be be ok. I just want the automation to run, as it’s not the case of “I clicked a button and 10s later everything was set up” or “I entered the room and saw a nice fade in of lights”. It’s more like “I’ve set up this action and I really want it to run (like an alarm clock), I will probably forget it’s there and won’t be there to supervise if it succeeded”

Notice that usually the first “delay” (as a trigger for the next part of the automation) needs to be seconds. Usually when we schedule an action, we accept an offset of few minutes.

I suggest the following solution:

The virtual timer should always be preserved after the hub restart, BUT if it has a “no later than” property, then it will respect it and won’t fire the timer after this time.

When setting up a timer, user can be suggested a “no later than” time (it can be an optional property).

1 Like