Set state of switch

Hey everyone I would like to set that state of a switch in an automation I have. So I have a soundbar that turns off after nothing is being played through it after x. The soundbar is a dumb sound bar and is only IR. So I want to tell HA that the soundbard is off otherwise it still thinks it is on. So the automation would be something like if media player changes from playing to idle or off (might have to do two automations) for x minutes then set soundbar state to off. So does anyone know how to set the state of a switch?

Thanks!!

What kind of switch component are you using?

1 Like

It’s a broadlink switch. Thanks!

calling the switch.turn_off service will set the state of the switch to off, but it will also execute the turn_off command.
This might, (or might not) be an issue for your implementation.

You can test it in the Services developer tool

Yeah I know how to turn off a switch this won’t work for me since turning on and off is the same IR code and could actually turn it on. So I just need to set the state. You can do it in the developer settings in the GUI but I want to know how to do this in a script or automation. Thanks.

Have you found any solution? I am looking to do the same but can’t find any solution how to change the state of my broadlink without calling the service at the same time. Since the ON and OFF commands are the same it turns off the switch on HA but turns the speaker back on.

the speaker goes off soon after anyway as it is not in use but the solution is not as tidy as I wanted it to be.

Curious if anyone figured out the answer for this as I’m trying to do the same thing: set the state of a input_boolean switch to off without actually triggering the service ‘turn_off’

Thx,

I have the same problem and haven’t find a way to do it…is there anybody who can help?

1 Like

Ok I found the answer :

Switch.turn_on is checking the current state and call turn_on if and only if current state is off

BUT

Homeassistant.turn_on is calling turn_on whatever the state is!

2 Likes

I am having the same issue but one thing that could help to set state via a physical watts meter.

So if the meter > certain watts , set virtual switch state to on and off.

I have yet try automation, there are couple cases needs to be handled to get the automation to work as we expected.

If anyone like to contribute the cases, we should be able to figure it out together.

hello, maybe i am necroposting but, this is exactly what i want to do. it’s a bit starnge that there’s no solution…
@phil1688 did you find out a solution?