Then the first is an entity (sensor).
The entity check that the status of the relay
here in the off position
the second is an entity button.
This change the relay state via modbus
here in the on position
As you can see, the button icon is always off even if the lamp is on.
That is, it turns on, rightly, for a moment and then turns off every time I press it. So if I didn’t have the other entity (sensor) I wouldn’t understand when the lamp is on or not
My intent would be to have only one entity button that shows its on / off icon based on the state of the entity (sensor).
I think you will need to create a template switch that tells the actual switch to turn on & off as the action and then use the state of the relay as the state of the template switch.
Then you can use the template switch instead of your actual switch and then everything should work the way you want.
Hi finity,
I added the template switch.
I have also set an icon different from the default one on the entity button but, it doesn’t change my icon and not as before
The light dont work !!
Where am I wrong?
also, and pardon me if I missed this in the discussion before, but you use service: switch.toggle for turning on and off. Why not use switch.turn_off and switch.turn_on
if the only thing you need is to set an icon and icon_color based on the state of a sensor, you best use the customization I posted before. You are making things very complicated right now. (but again, sorry if I missed the essentials of needing a dedicated template switch. I thought you had that part working already before you started this topic…)
I think the problem is that the switch was a momentary switch that when the button was pushed only stayed on for a second then went back off immediately. Then the relay was operated to turn on the light. All of that was operating correctly in the HA frontend.
The OP wanted a button that would show a status that followed the state of the relay, not the state of the momentary button.
I see, that is nothing very special. Having a frontend entity display the state of another entity.
For me the question remains, why not use the customization with the state of that relay? Icon and icon color would easily be templated in custom-ui
Mariusthvdb and finity,
thank you so much for the passion you put into making me understand what to do.
I’m a newbie to HA and unfortunately I can’t translate what you suggested into code.
All of that is true but it also entails the extra (not unsubstantial) step of installing and maintaining another custom component and it also means learning a new templating format language that a new person might not want to undertake.
My way is supported natively in the code so it’s a bit more straight forward.
Hi, Sure you’r right, I am not disputing that at all, and I think the template switch is a very nice tool in the box. So great to show in this case and probably the solution for the OP’s technical issue.
I know my suggestion needs the custom-ui install. This is a 1 time thing though, and provides a plethora of options throughout the full setup though, so certainly worth the effort.
Adding to that, there’s no native way to color icons, besides the yellow and black used now, (and your suggestion above doesn’t color the icons either ) other than installing extra custom-cards in Lovelace. Which, as it stands now, requires much more effort and has a steep learning curve, since many of these cards use their own way of templating, and have their own level of support for templating all together. Not to mention the efforts one has to take to update these and change when features require so after updating. In fact, keeping custom cards up to date and keep up with breaking changes in Lovelace is a task by itself…
Coming to think of it, Themes could of course also color the individual items but is a global way of changing the frontend, while custom-ui enabled individual customizing.
Hi finity,
I tried to insert the code you attached to me but it doesn’t work.
Practically when I press the entity button it does not turn on or off the light and does not change the icon.
I think I’ll have to wait if an entity switch is ever added with a status input for the icon.
Thanks anyway, Alberto
Your solution works, I try it both with and without the extra “brackets” (that @alverman used). Not sure why he need those extras…Thanks for your solution.
The reason I’m doing that is because my button activates a pushbutton via dry contact, so there is no feedback on state. So i have a reed switch which will pick up if it’s open or closed so I want to relay that information visually on this button rather than having a button and a sensor state glance adjacent.