Single switch into 2 virtual devices

Hi. I have 1 tasmota switch. Switch A. What I need is to create 2 virtual devices - Device 1 and 2 with customisable icons and set its states based on this switch. Also be able to activate/deactivate those devices by clicking on them (which is the way I will operate SwitchA).
Logic is: SwitchA on = Device1 enabled, Device2 disabled. SwitchA off = Device1 disabled, Device2 enabled.
What is the best way to realize this? Thank you.

Template switches or binary sensors. Sensors would be best as the logic is only one way (you don’t want someone trying to change the state of device 1 or 2).

binary_sensor:
  - platform: template
    sensors:
      device_1:
        friendly_name: "Device 1"
        value_template: "{{ states('switch.switch_a') }}"
      device_2:
        friendly_name: "Device 2"
        value_template: "{{ not states('switch.switch_a') }}"

But I also need to really use this switch by clicking on virtual devices icons. Is this possible with binary sensor?

No, but you did not define what happens in this case in your original post.

@Jiran Try setting it up as a multi relay Tasmota device and then your config would be something like this:

  - platform: mqtt
    name: "Stairs"
    state_topic: "stat/sonoff4CH01/POWER1"
    command_topic: "cmnd/sonoff4CH01/POWER1"
    availability_topic: "tele/sonoff4CH01/LWT"
    qos: 1
    payload_on: "ON"
    payload_off: "OFF"
    payload_available: "Online"
    payload_not_available: "Offline"
    retain: false    
  
  - platform: mqtt 
    name: "Sink"
    state_topic: "stat/sonoff4CH01/POWER2"
    command_topic: "cmnd/sonoff4CH01/POWER2"
    availability_topic: "tele/sonoff4CH01/LWT"
    qos: 1
    payload_on: "ON"
    payload_off: "OFF"
    payload_available: "Online"
    payload_not_available: "Offline"
    retain: false

Substitute your name here “sonoff4CH01” without the double quotes

PS: it does not matter that your device may not have two relays…it still works as a virtual device.

PLUS you will need to make an automation OR have a look at using Tasmota Rules

OR a 4 channel sonoff device has a built in setup for interlocking (sounds like what you need) which is realised by some onboard switches.

From original post: Also be able to activate/deactivate those devices by clicking on them (which is the way I will operate SwitchA).

Tuanks @wellsy but I don’t believe this is the cleanest solution. There must be something much straightforward.

Worth keeping as a fallback possibility?

Yeah ok. I just saw the logic is...

Another person who comes here, asks a question, gets a correct answer and then says it is not good enough.

1 Like

1, in fact I have sonoff DUAL, but I use only one of 2 switches for switching water valve output to electric heater or fireplace water tank. If this switch is ON, water goes from water tank, if is OFF water goes from electric heater. The second switch on this sonoff dual tells electric heater to be ON/OFF.

So in near future I will need automation which will decide (based on need of heating by rooms + is there hot water in the tank?) if run heating from electric heater or water tank.

But now, when automation is not finished, I would like to control it manualy and just to have some “slider” to choose heating from electric heater (turn switch 1OFF+2 ON) or from water tank (1ON+2 OFF).