Retry for actions

Has anyone thought about the need for a retry option for an action? Let’s say you have an automation to turn on a light at sunset, but when that automation fires the switch api isn’t reachable… the light never turns on. This happens a lot to me with some products where their API sometimes times out or just doesn’t handle the request.

Can there be a ‘retry after N seconds’ if state doesn’t change or ‘retry for X minutes until state changes to desired’

Maybe it’s just me but I encounter this a lot with automations and random elements not always being triggered reliably.

You can implement this yourself using one of the available repeat actions:

https://www.home-assistant.io/docs/scripts#repeat-a-group-of-actions

e.g. turn off, repeat (with a delay) until off or tried 30 times.

If your actions are not reliable perhaps you should look into upgrading your network?

I understand the script approach but this isn’t scalable for hundreds of devices and countless automations. Also, to the point about network, its reliable but the API’s aren’t always, sometimes there is an API error, sometimes IoT vendors don’t implement resiliency… for example, making large insteon actions is best effort, sometimes a light gets missed and a second try works. I have some other devices like garage door openers where the API sometimes times out. I’m looking for a more general feature to handle if something doesn’t change state as expected.

This would be ideal for any “Device” with clear state reporting and standard actions like lights, covers and locks.

UI / YAML wise adding a retry_in or confirm_in x seconds parameter would be nice… Action fires, waits the retry time then checks if the final state matched the action. If you wanted it left up to the user you could have two parameters, of end_state and retry_time so no special cases need to be coded

I seem to have the luck of some battery zigbee devices like my blinds will be fired in a group and one will fail every now and then super annoying. Sometimes HA has the device stuck in motion state, others it just shows the origonal state and repeating the request just fixes it.

This is exactly it, I’d like to see it as an option in the UI per device, in a configurations screen. Lights, switches, covers are where it would like be used the most.

Any thoughts on this or perhaps something that can retry if an entity is unavailable and then becomes available?

We developed a custom component for this purpose. It adds a new custom service retry.call which wraps the inner service call with a retry logic.
You can read all about it here.

1 Like

Hi Amit, I checked your repo, looks very interesting. Are the times mentioned (0,2,4,…) in seconds ?

Yes, the delays are in seconds.

Going to bump this topic again… It happens to both zigbee and zwave devices often enough that I have some redundant automations that TRY AGAIN just to be sure…

I want to be SURE all my doors are LOCKED and my blinds are CLOSED when I request them to be… I want there to be an error or alert if this does not happen but I would prefer it just worked more reliably.

Most recent case was I have my zwave door locks in a group, I tell the group to lock at a specific time if the group is not already locked… Last night one of the locks did not lock, it wasn’t until the second automation 30min later tried again it worked… Nothing was blocking the door or anything it may have just not got the command or something.

I would prefer not to have to create all my critical automations with redundant triggers just to be more sure they complete.