Switch turn off / on acts like a toggle

Hi there,

if I simply call the service switch.turn_on or switch.turn_off, it does what it should do: Turn ON or OFF a switch.

But if the switch is e.g. already turned ON before I call the turn_on service, it turns OFF the switch. And vice versa (switch is OFF and turn_off afterwards turns ON the switch).

This doesn’t make sense. Like this it’s a toggle service which I don’t want.

My use case is:
Turn ON certain lights at a certain time. But if one of the lights was already turned ON before manually, just keep it ON. I thought by just letting the automation trigger the “turn_on” job again doesn’t change the state, because if a switch is ON then it stays ON if the “turn_on” job is called.

What am I doing wrong?

You have not included any of the important parts.
What light is it? How is it integrated? What code do you use to get this behaviour?

Sorry, here some additional information:

I use Home Assistant 2021.11.2

It can be the case that I did something wrong in my configuration because the chain to trigger the light is complicated:
Home Assistant switch → Triggers Automation → Automation triggers script → sets virtual key in Homematic CCU unit → throws Intertechno command to plug → light turns ON

But my general question is:
If the state of the switch “MySwitch” is ON and I trigger the service “switch.turn_on → entity: MySwitch”, does it call the turn_on switch services I configured in my configuration.yaml again or would it skip them?

I would expect to skip them because the switch is already ON…

They will be executed again, the service doesn’t check whether the light is on or off. You should add a condition before the service that checks whether the lights is off.

Sure, a condition would be great but I have 6 lights to be switched ON in a sequence.

Can I couple the condition to the single actions like this? :
If MySwitch 1 is OFF, then turn ON MySwitch 1
If MySwitch 2 is OFF, then turn ON MySwitch 2
If MySwitch 3 is OFF, then turn ON MySwitch 3

Because just adding all 6 switch states as a condition would be bad: If one light would be on, the entire automation wouldn’t be executed.

You still haven’t included any of your code blocks so I just have to assume that this will work for you, but the choose action can be used as an if statement.

Normally, turning on a light that is already on does not turn it off.

Post the automation that is responsible for the strange behaviour.

This is the same problem I am having. It only occurs with zigbee devices (different brands) that are being controlled by an automation. The option is there to turn on, turn off, or toggle. Adding a condition is not helpful as I have several switches included and the automation tool doesn’t allow conditions for each action. This destroys the convince of the automation tool. I don’t believe a custom script should be needed here.

Having this issue as well. Calling light.turnoff from developer tools turns the effected bulbs off as expected, but calling light.turnoff from my automation seems to toggle the lights. Oddly, the lights that toggle to on do it only in reported state, but do not light up most of the time. Sometimes they do.

They are zigbee lights. I’m using the sky connect in zigbee only mode. Never had this issue with my previous zigbee coordinator.

Yeah it does.

https://www.home-assistant.io/docs/scripts#if-then