amitfin / retry

Home Assistant Integration with Retry Service
MIT License
95 stars 4 forks source link

Custom Action when retry failed (Auto "Repair") #85

Closed Mathea90 closed 3 months ago

Mathea90 commented 3 months ago

Checklist

Is your feature request related to a problem? Please describe.

Sometimes unsuccessful actions can be attributed to straightforward failure sources like e.g. a failed initialization of an integration. Retry will not help here, no matter how many attempts. In this case the service call fails and Home Assistant will take no action but perhaps display a repair notification. Specific example in my home: my lawn mower robot sometimes does not react to commands until I reload its integration. Other example: I have a zigbee switch which sometimes loses connection and cannot be controlled anymore until it is power-cycled. This zigbee switch lives in a circuit which I can also control with a connected relay. I fix the problem by toggling the power with the relay.

Describe the solution you'd like

I suggest implementing a custom definable action if the retry failed after X attempts. This could be used to e.g. defining possible "repair" actions, like e.g. automatically reloading an integration in an attempt to "self-heal" the problem. Alternatively it could be used to send a notification if some retry call failed to alert the user, which could also be very helpful in some instances. In my opinion, this retry integration is the perfect candidate to implement such a behavior.

To enhance the usefulness of this feature, an additional "validation" or a definable wait timer could be implemented after which the initial retry service call is carried out again.

The behavior could look like this:

  1. start retry call
  2. retry fails after X attempts
  3. custom action is carried out (e.g. reloading an integration or sending a notification to a user)
  4. wait for X seconds or wait for some validation trigger (e.g. entity switches from "unavailable" to some other state)
  5. carry out initial service call again
  6. If the action fails again, stop and display the repair notification

Describe alternatives you've considered

It is possible to create automations which react to certain states and carry out such repair actions. But implementing this in the retry integration would be much more elegant because the detection logic of failures is already in place.

Additional context

I love this integration and would be very happy if its usefulness would be incrementally enhanced in the future. So thank you very much for creating it in the first place and thank you for the support.

buschtoens commented 3 months ago

It’s almost eery, that I discovered this extremely helpful addon just yesterday, and already find myself in need of this exact feature. 😄

amitfin commented 3 months ago

v.2.10.0 adds on_error parameter for specifying a sequence of actions to execute if all retries fail. See also documentation.

@Mathea90 , @buschtoens , can you please give it a try and verify it addresses your use case?

buschtoens commented 3 months ago

@amitfin Just what I needed. Thank you very much! :heart: