I have exactly this problem but with 2 switches, and at the moment I am solving it using NodeRed, because my heating relay is HTTP controlled, but the climate entities in Home Assistant are intergrated with MQTT. So I am able to intercept the command in NodeRed and decide if it should really be on or off ( after a short 30 second delay to allow multiple commands to come in, before I make a single http call )
Yep. 3 diodes.
One way to do this in ESPhome would entail:
Setup 3 binary_sensors using HA as the ‘platform’ so they now represent the state of those switches in HA.
Setup an ‘interval’ component in ESPhome that checks, e.g. every second if:
switch a is on
or
switch b is on
or
switch c is on
then
turn relay on
else
turn relay off
This assumes you don’t mind not having instantaneous response at the relay to the state of the switches in HA. This approach results in an average of a half-second delay (half of whatever you set the interval timer to).
To avoid that delay, you could instead:
define on_change automation logic on the binary_sensors that turn the relay on if any of them turns on, and if any of them turns off, checks the other two to see if this is the last one turning off and then turns the relay off.
That logic could be in a separate ESPHome ‘script’ so you don’t have to replicate it on each of the sensors. And it would react much faster than the polling method using the interval timer.
This is the exact logic of a group with the all option set to false (the default).
Creat a group of your switches and import that into esphome as a sensor. Use the on_value triggers in esphome (under the group sensor) to switch your relay on/off as the group sensor changes.
In HA, I believe.
The HA group object has a state which is the boolean ‘OR’ product of its members’ states.
Importing that group into ESPhome gives you an ESPHome component that you’ll use to set the relay’s state.
Edit 22-12-2021, indention and missing - in my code, which is why the delay did not work, now corrected
Any thoughts welcome
Regards Dave
Edit: I have tried and reduced the delay to 1mS and it still functions ok. If you don’t have a delay then the acc1,2 & 3 ID flags are still set when the script runs (that’s what took me a while to sort out) even though they are technically all off, obviously a timing issue within ESPhome of when those ID’s get updated.
I have 2 thermostats controlling the same SonOff, if you use the same switch in the climate settings, they fight each other, also running my another old HA on a Pi3, that I also want to control the heating from until I move over to my Pi4 (hence 3 outputs), but you can have as many or as few as you like.