Everything works fine, but when I hooked up several of these template switches to the google home and put them in the same room then when I want to disable all the light in the room then if any light was off at that moment, then it would be toggeled to on state.
This means to me that even though the light was off it recieved the switch.toggle command, which I do not want it to recieve. What should I do?
I get the same behaviour if I have this template switch in on state and just call service swtich.turn_on on this switch (from the developer tools menu) then it turns off even though it was on and should not react to this service (my logic tells me so).
This does not suit me, because the physical light state is not always the same as the virtual switch state that toggles the light. I did find a workaraound already. I made a script:
The problem is much deeper. it is because I use specific configuration for my lights. They are controlled with PLC - Siemens Logo. Which in turn gives me the ability to use any light and any light switch I want in my house. In my house I use pushbuttons to turn the light on and of and the light is triggered by a pulse trigger. The pulse trigger reacts to pulses. To make the homeassistant to produce pulse I either have to make a script that makes them or program logo to produce pulse whenever the virtual switch of homeassistant changes its state. I choose the second option, which means that if the virtual switch wont change its state the pulse wont be generated, that is why I can not use simple switch.turn_off or trun_on. I need it to use toggle so independently os state of virtual switch I would triger a pulse signal inside my PLC.
How about creating an independent input boolean, the virtual switch is tied to that to operate the light and the toggles can be applied to the boolean ???
Yes. This works. If in some case (which is the case when I call the service from google home) and there is no valid service it just does nothing. Which is good because my google home updates the states quite slowly sometimes. And sometimes it sends a service call to turn_off the light even if it is turned off. Using this if statement this call just does not work. But to get it working clieanly, you can make a dummy script for the else statement, but to my mind it is not needed here.
You can also change the logic so that the service call is static and the entity_id is dynamic. This allows you to take advantage of setting entity_id to none (a valid reference in the case where no entity_id is desired) when nothing should be toggled.
Yes, in my haste, I overlooked to do that when I modified the example.
It will still work with service_template but it’s not needed. I have updated the example in my previous post and replaced service_template with service.