amitfin / retry

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

Toggle service suitable? #42

Closed oudoulj closed 9 months ago

oudoulj commented 9 months ago

Checklist

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

I am wondering if service: homeassistant.toggle is a suitable service to use Retry with? I use that service to turn on/off lights in one automation instead of having 2 of them (one for off and one for on)

Describe the solution you'd like

I was thinking of

service: retry.call
data:
  service: homeassistant.toggle
target:
  entity_id: light.kitchen

but I'd like to be sure to, say, turn off the light and not turn it on in case the light was on and the toggle was called BUT failed and then was "retried" but this second time it would try to turn the light on (instead of off). Hope I make sense ^^

Describe alternatives you've considered

I don't have any.

Additional context

No additional context.

amitfin commented 9 months ago

homeassistant.toggle is not suitable since it's a relative operation and not an absolute one.

For the README file:

Note: This service is not suitable for the following scenarios:

  1. ...
  2. For a relative state change: for example, fan.increase_speed is relative while light.turn_on is absolute. The reason is that a relative service call might change the state and only then a failure occurs. Calling it again might have an unintentional result.
  3. ...

I'm adding homeassistant.toggle as another explicit example in the documentation quoted above.

amitfin commented 9 months ago

https://github.com/amitfin/retry/commit/5f2f3264d7fb39002f55d5f0b4bc65203f2c3f2a (the README file update)

amitfin commented 9 months ago

Please note that it's not needed to double the amount of automation rules in order to use absolute operations. It's possible to use trigger ID with if-then or choose which can then have absolute operations based on the trigger ID.

oudoulj commented 9 months ago

Please note that it's not needed to double the amount of automation rules in order to use absolute operations. It's possible to use trigger ID with if-then or choose which can then have absolute operations based on the trigger ID.

Interesting approach/suggestion! Thank you for the answer and the update of the README file :+1: