I have the following entity defined light.hull which works just fine.
Recently I created an automation to turn off all lights when I leave home using the turn_off service.
To my surprise when I tested the automation, every time I run the actions all the actual lights would turn off as expected.
All the template lights I have including the one below toggled state. So turn ON if was already OFF.
To clarify, the respective entity does change state and icon
Off
On
so I am not sure if there is something I am doing wrong or if this is some sort of bug.
In case this makes any difference I am using a Sonoff Dual R3 to control a two way light.
The binary_sensor.hall_state is on when there is power consumed in any of the 2 relays. So I am using this to then show a light entity reflecting if the light is On or Off.
How do you expect it to behave differently from the turn_on service when it calls the same service call (button.press) for the same button (button.hall)?
If the state is OFF the turn_off service should not be executed.
So the expected behaviour would be no action at all.
Else how to distinguish which service to execute if not take into account the state.
By checking the state of binary_sensor.hall_state in both the turn_on and turn_off. Effectively it’s what tom_l suggested (but using a different entity).
Brilliant. That worked!
Thanks a lot for the help guys!
That makes me wonder, where do you get this format from? I just checked the “template light” documentation and I don’t see any reference to “condition”
- condition: state
entity_id: light.hall
state: 'off'
I see. That helps for future references.
Thanks again!
The behaviour I noticed in my original post, though, is wrong behaviour. No?
I mean I did follow the template guide and the behaviour was not exactly the expected one. So wondering should I raise a bug ticket somewhere. If so where?
The problem arose because you are using the same turn on and turn off action without checking the light state. Look at the example, it uses separate actions:
Ok, I understand now I think. It sounds unintuitive to me which is why I thought there must be a bug.
I was under the impression that when you call e.g. the turn_off service the state is automatically checked and only if is, in this example, ON then it is executed.
It is clear to me that that is not the case.