Create a logical 2-way switch using Sonoff Wall Plates

Hi,

I got a sweet deal on a pack of Sonoff Wall Plates (T0US2C) which goes inside the single gang but have two buttons. So here is the configuration of my house:

  1. Current wall switch that operates the outside light that is mounted right above the garage side door that opens into the outside lawn (door1, wallplate(1))
  2. Current wall switch that operates the outside light that is mounted right above the sliding door that opens into the outside lawn (door2, wall plate2)).
  3. Mounted outside are three additional LED flashlights(not the ones mentioned in 1 & 2) that are connected to HA via three Sonoff Basic (light-1, light-2, light-3)

I’ll be replacing wall plates from 1) and 2) above with the Sonoff Wall plates so that I’ve updated options as follows:

wallplate(1) ⇒ wallplate-1 (switch-1, switch-2), connect wallplate-1(switch-1) to the outside light and it will operate as the current manual switch

wallplate(2) ⇒ wallplate-2 (switch-1, switch-2), connect wallplate-2(switch-2) to the outside light and it will operate as the current manual switch

The wallplate-1(switch-2) and wallplate-2(switch-2) have following characteristics:

  1. Both buttons are free and have no electrical utility as there is no electrical load attached to it
  2. Both are connected to HA via Wifi and can be used as buttons to trigger events which can be utilized in automation for a logical 2-way switch for operating light-1, light-2 and light-3 that are not even connected to either of these wallplates.

So here is the logical switch setup in my mind:

  1. When either wallplate-1(switch-2) or wallplate-2(switch-2) are pressed the first time then turn ON light-1, light-2 & light-3
  2. When either wallplate-1(switch-2) or wallplate-2(switch-2) are pressed the second time then turn OFF light-1, light-2 & light-3

For the automation, I can use some help from this forum to incorporate few additional logic:

  1. When a single person leaves from door-1 after turning ON the lights but returns from door-2 then the same person can turn OFF the lights by pressing wallplate-2(switch-2). This is easy and the simplest scenario.
  2. But if there are two persons, person-1 leaves from door-1 after turning ON the outside lights. Then we would not want person-2 (leaving from door-2) to accidentally turn OFF the lights on person-1 when wallplate2(switch-2) is pressed by person-2 the first time. So the automation needs to check if the light-1, light-2 and light-3 are running then DO NOTHING when wallplate2(switch-2) is pressed the first time but turn OFF light-1, light-2 and light-3 when wallplate2(switch-2) is pressed the second time. The same logic would apply when wallplate-1(switch-2) and wallplate-2(switch-2) are interchanged in the scenario above. And I do not want to get into the complication of tracking person(s) so the logic of this step should work for the single person scenario if that person presses the wallswitch twice.

Essentially the above logic is creating a virtual 2-way electrical switch between lights which normally at home are hardwired in large spaces like living rooms or multi-tiered locations like staircases.

Any pointers would be appreciated.

Thanks.

What you describe is really not like a hardwired 2-way switch, because those do not know who clicked them and they always toggle when pressed, regardless of what happened before. Personally I would just set it up like that, it would be the most familiar experience for the users as well. This would just require each button press to toggle the light, no complicated automation.

the automation needs to check if the light-1, light-2 and light-3 are running then DO NOTHING when wallplate2(switch-2) is pressed the first time but 

Define “first time”. First time since when? 5 minutes ago, an hour ago, today? I don’t think you can define it in any usable way, honestly.

1 Like

How are you sensing presence? Are you counting door openings?

Otherwise, I’m tending towards what Fanful has said.

Thanks @Fanful & @parautenbach , this was very helpful.

I think my bias towards a potential solution skewed my framing of the problem but your comments were insightful. Even in the hardwired circuit, the switches are merely toggling and at least from the outside do not show the state (if the lights are ON or OFF). Typically a person leaving through the second door would likely peek outside to see if the lights are ON to get the state. Let me rethink the problem and post an update here.

2 Likes

So here are my updates, for now I decided to leave the automation to only trigger “toggle” when either wallplate-1(switch-2) or wallplate-2(switch-2) are pressed. The intent it to see how it works and if rest of the family has any input or any weird behavior is observed. Here is my actual code for the automation that is working and few caveats:

  1. The code shows the actual entity names and not the schematic ones that I used in my initial summary above.
  2. Added two input_booleans - i) for acting like a kill switch for the automation and ii) capture the status if this automation has turned the lights on as all three lights also have other automations that are specific to events local to those lights.
- id: '1713740874118'
  alias: 00-WallSwitch
  description: '00Automation: wallswitch'
  trigger:
  - platform: state
    entity_id:
    - light.t1_2
    - light.t2_l2_2
  condition:
  - condition: and
    conditions:
    - condition: state
      entity_id: input_boolean.outside_lights_2way_switch_automation
      state: 'on'
    - condition: state
      entity_id: sun.sun
      state: below_horizon
    - condition: template
      value_template: '{{ is_state(''light.t2_l2_2'', ''off'') or is_state(''light.t2_l2_2'',
        ''on'') }}'
    - condition: template
      value_template: '{{ is_state(''light.t1_2'', ''off'') or is_state(''light.t1_2'',
        ''on'') }}'
  action:
  - service: switch.toggle
    target:
      entity_id:
      - switch.basic02_relay
      - switch.basic07_relay
      - switch.basic04_relay
    data: {}
  - service: input_boolean.toggle
    target:
      entity_id: input_boolean.outside_lights_2way_switch_automation_running
    data: {}
  mode: single

Thanks @Fanful and @parautenbach for talking sense into me, I was way overcomplicating the scenario in my head :sweat_smile:

2 Likes