I’m trying to accomplish a similar thing, but it’s not working for me. I’d like to add a button in lovelace that toggles between two scenes, one that sets my indoor cameras as on and the other one as off.
I tried following the above solution but it’s not working because it says “no type provided”.
I tried adding “type: button” but in this case it gives an error for more-info missing information.
If I add the more info entity, it won’t act as a switch/button but it will open the specified entity card (tried with different ones)
which I think it’s what you were suggesting, but I get this error:
permission denied while trying to connect to the Docker daem
on socket at unix:///var/run/docker.sock: Get "http://%2Fvar
%2Frun%2Fdocker.sock/v1.24/containers/hassio_cli/json": dial
unix /var/run/docker.sock: connect: permission denied
Anyway it seems like it’s working. I managed to add the button, although it stays grey all the time. I was expecting it to become yellow when set to on. What am I doing wrong?
I talked too soon.
Actually the button doesn’t work at all. It works inversely (when I click on it and it turns on it actually turns the cameras off) only when I go to Settings → Devices & Services → Entities and toggle the entity itself.
But in the button above, it doesn’t do anything.
Edit: ok, I managed to make it work. I had to delete the value_template line because it was unnecessary and it only made things complicated. Now everything works as it should.
Thank you very much for all the help.
The value template provides feedback on your switch state in case it is changed outside of HA. Without this you are operating in optimistic mode and the state of the switch shown in HA could get out of sync with the actual switch state.
A better solution than deleting the template would be to work out why you are not getting the correct result from it.
Add the template to Developer Tools → Template editor. Change the switch state and observe the template result to try and work out what you have incorrect. It could be as simple as an incorrect letter case, e.g.
I will definitely look into the matter, even though in this case there’s no way for the switch state to be changed outside of HA, because everything is managed through HA.
Also, the state of the switch is not really important because all the changes to it are made through scenes, which as I understand them, kind of “overwrite” the state in any case.
Still I understand why you pointed this out and since it’s probably going to be useful in the future I will do my best to look into this and understand more of how value_template works.
Ok, I have looked into this, but I can’t seem to find the solution.
I’m probably getting something wrong: in my intentions I want that the state of the switch template is reported as on when the state of switch.cam_sala_2 is on.
Since switch.cam_sala_2 is a Zigbee device I went to the Zigbee2MQTT integration and checked its reported state, which is ON (all capitals).
Therefore I put these lines in my configuration.yaml :
But the reported state of the template switch is wrong (it’s set to off even if switch.cam_sala_2 is ON, and the button on the dashboard is not working.
I tried but I get the following error when checking the configuration:
Error loading /config/configuration.yaml: while parsing a block mapping
in "/config/configuration.yaml", line 46, column 9
expected <block end>, but found '{'
in "/config/configuration.yaml", line 46, column 27
Line 46 is the one with the value_template written the way you suggested.
Edit: scratch all of the above, I think I made a typo somewhere because after copying and pasting your line it doesn’t give any errors anymore and everything works as intended.
Damn, HA is hard!!
Thank you so so much for your patience in helping me.
Another question though: is it possible to check two statuses? For example, what if one wanted the status of the template switch as on when the state of both switch.switch_1 and switch.switch_2 is on? Or when only one of the two switches report its state as on?
Is this doable?
Of course, that was what I intended. Thank you for the clarification.
I have read it all but, frankly, it didn’t clarify much to me because it’s way too technical and beyond my comprehension level. I acknowledge I am not very skilled in this kind of things, and I will do my best to learn more.
Then I’d recommend joining the HA Discord and asking for help in the templates channel. The folks there are really good at helping people learn templating.