It would be great to have an option not to send an action, when the state of the targeted device is already in the expected state. For instance switch.turn_off would not be sent if the state is already off.
Typically you do this with an if statement.
if:
- condition: state
entity_id: switch.light
state: 'on'
then:
- action: switch.turn_off
target:
entity_id: switch.light
Thank you, I know this can be done, it’s a bit cumbersome, though
I like the suggestion, but I think the way shown in the example by petro is the correct approach.
In general, it shouldn’t be problematic to set the device to a state it is already in.
However, assuming the state in the state engine matches the actual device often isn’t the case.
Take for example, devices that are polled for their status or have an assumed state (these make up for the larger sum of integrations in Home Assistant), the actual state in HA can actually be different from the actual state the device is in. Logic as the above thus will have an incorrect result.
…/Frenck