Hello forum
I ve TV and MUSIC system connected to two different sockets which are connected to nodemcu with 2 relays (GPIOs) individually.
Here is what I’m looking.
There should be only one UI button on HA homepage.
When is press the switch on UI, the switch has to activate two relays (two GPIOs ON).
I searched all materials couldnt find it, can you please help?
please dont restrict to two GPIOs there can be more GPIO and followed by IR code aswell.
This can be done several ways, look into the integrations Group, Scripts and Automation, each has slight variations on how they operate and call services. I would suggest starting with scripts, which can be done through the UI, - configuration panel - scripts - add button. Use a button card to call whichever entity or service you choose to make. Good luck
Thanks for your kind reply.
I tried scripts. switching ON is OK, but how to switch off? it dont have a clue how to do it . each time i "Execute " it turns ON as expected. but i need the same toggle button to turn off aswell.
the best way im preferring is
something like below
So if I understand what you want: the code you have is on the esp device, the output part looks fine, but I am unsure if you can have two outputs on one switch, but if that works great, then all you need is to find the entity_id for the esp switch( probably switch.sony_tv ), on the entities page in HA, and make an entities card, using that entity_id. Because it is a switch it will be a toggle device on the card you can turn on and off.
If you can’t have two outputs then on the esp:
switch:
- platform: output
name: "SONY TV 1"
output: 'relay1'
- platform: output
name: "SONY TV 2"
output: 'relay2'
then group them like this in HA configuration.yaml:
Then use the entity_id for the group in the entities card. I have not used groups in a while, so this may not be perfect, but should get you going.
Your issue with scripts and automations, yes they are kind of one way, not easily back to off, they just execute. The reason I mentioned it was because you said you may want to add IR, and you may not be able to group them effectively as the state wont be on or off for that IR entity. And you probably don’t want to run the same IR Code when you shutdown anyway. What you could do is make an input boolean, (see toggle under helpers on the configuration page) in HA, and make two automations in HA, one operates when the input boolean goes from off to on, the other runs when it goes from on to off., one automation can turn on the relays, switches, or call an IR service, even after a short delay to allow time for startup. The other turns them back off. Use an entities card to toggle the input boolean. You could also use a button card and set tap action to toggle. Lots to read, hope this helps a bit. Good luck.