#Connecting two smart switches to smart bulbs.

1 messages Β· Page 1 of 1 (latest)

shy nebula
#

So, I have two smart switches. One has a line and the other just had a neutral for power. I want both switches to sync up. Currently they are both on smart bulb mode and they turn on a group of 9 smart bulbs. (It's weird I know).

Is there an easy solution I'm not thinking of? I feel like automation isn't what I need. Maybe some helper?

mossy oyster
#

What does "just had a neutral for power" mean?Can you draw how it's connected? What smart switches?

shy nebula
#

In short, both switches are powered i.e. connected to home assistant, online, and togglable. It used to be a 3-way circuit but I didn't know what I was doing back in the day and got and installed 2 smart switches. Eventually I just wired the line from the first box to the second so only one switch controls actual power to the fixture.

The wiring isn't really the issue here, it's how to I sync these two switches to the smart bulb group, but also avoid a loop of "if a is turned on, turn on b" and "if b is turned on, turn on a".

mossy oyster
#

Ah, so module 1 isn't actually controlling the light? And module 2 is?

Then you can just make an automation like;

description: ""
mode: single
triggers:
  - trigger: state
    entity_id:
      - switch.module_1
    to:
      - "on"
    from:
      - "off"
  - trigger: state
    entity_id:
      - switch.module_1
    from:
      - "on"
    to:
      - "off"
conditions: []
actions:
  - action: light.toggle
    metadata: {}
    target:
      entity_id: light.module_2
    data: {}
shy nebula
#

Yes but the issue here is that if I toggle on module 1, it will turn on the light, but module 2 will still be in the off position. So if I then toggle module two off, there is no change and it doesn't turn off the lights.

#

The fixture is all smart bulbs (wife wanted dimming). So each switch turns on the bulbs but I need the switch states to sync.

mossy oyster
#

Please try to answer al questions. I have a hard time trying to fill in the gaps.

But I think you have them both in parallel?

But that would mean you will still see the status of both modules in HA and thus you can act on both.

But if you have smart bulbs, especially if they are Zigbee or Thread, I would just connect them straight to power. And just leave the output of the modules unconnected.

shy nebula
#

Where the power is coming from isn't really relevant I don't think. I'm not having a wiring or power issue. Both switches are zwave, blubs are zigbee treated as one device. Both switches are working and turning the lights on and off. Both switches have zwave and manual control off, i.e. smart bulb mode.

What happens is I have an automation like your example:

  1. A and B are both off and the lights are off.
  2. If I turn on A, the lights turn on, but B is still set to the "off" state.
  3. If I go to module B and try to turn off the lights, the switch is already in the off state so nothing happens. I have to press up on the switch to change it's state to on, then press down to actually turn off the lights.
#

Maybe I should just turn everything to toggle so that no matter what state anything is in, it changes the state.

viral musk
#

yeah, "everything toggle" will match the way a normal 3-way switch setup is expected to work.

shy nebula
#

I suppose that makes a lot of sense actually. Wish I was smarter when installing it all lol.

mossy oyster
#

It's not that you have an issue, it is us then not knowing how it actually works! And thus, how we can help πŸ˜‰

But as it doesn't actually matter the other is still off. But might be easiest to keep just all in sync:

description: ""
mode: single
triggers:
  - trigger: state
    entity_id:
      - switch.module_1
      - switch.module_2
    to:
      - "on"
    from:
      - "off"
    id: "on"
  - trigger: state
    entity_id:
      - switch.module_1
      - switch.module_1
    from:
      - "on"
    to:
      - "off"
    id: "off"
conditions: []
actions:
  - if:
      - condition: trigger
        id:
          - "on"
    then:
      - action: switch.turn_on
        metadata: {}
        target:
          entity_id:
            - switch.module_1
            - switch.module_2
        data: {}
    else:
      - action: switch.turn_off
        metadata: {}
        target:
          entity_id:
            - switch.module_1
            - switch.module_2
        data: {}

Could do a toggle on everything but if that gets out of sync (for example, a module is offline for a bit) it's a bit hard to get into sync. This will just force it into sync πŸ™‚

But with cutting the power to the smart bulbs it will still be a less solution as you rely on the state the bulb goes on in and you're not able to set a state to turn on to. And if it's a Zigbee or Thread bulb it breaks the network all the time. So best solution would be you connect them to fixe power. It's an easy fix, open one switch and move the wire from OUT to L πŸ™‚ Or if it's a module that supports detached mode (like a Shelly), just set it to that mode.

shy nebula
#

But doesn't the above automation create a loop?

  1. Turn on A
  2. Automation triggers to turn on B
  3. B turning on triggers the automation to turn on A
  4. Etc.
sacred coral
#

- alias: 3 Way
  id: 3wayswitchexample
  trigger:
  - platform: state
    entity_id:
    - switch.no1
    - switch.no2
  variables:
    entities:
    - switch.no1
    - switch.no2
    state_list:
    - 'on'
    - 'off'
    continue: >
      {{ trigger | default(none) is not none and trigger.to_state is defined and trigger.from_state is defined }}
    to_state: >
      {{ trigger.to_state.state | default(none) if continue else none }}
    targets: >
      {{ expand(entities) | rejectattr('entity_id', 'eq', trigger.entity_id) | rejectattr('state', 'eq', to_state) | map(attribute='entity_id') | list if continue else [] }}
  condition:
  - condition: template
    value_template: "{{ continue and to_state in state_list and targets | count > 0 }}"
  action:
  - service: switch.turn_{{ to_state }}
    target:
      entity_id: "{{ targets }}"
#

debounces and keeps the 2 switches in sync

mossy oyster
shy nebula
#

I see, thanks!

sacred coral
#

I.e. there's no debouncing in that automation

#

(same for off)

mossy oyster
#

Absolutely true, but in most cases that doesn't matter. And doubt it does here.

sacred coral
#

It does matter, that's why I've been using the automation I posted above for years

#

zigbee and zwave's network can flood. And if the switches are out of sync, you get a never ending automation

#

especially if there is a delay in your coordinator

#

Example if you have a slow coordinator:

switch one changes to on
automation runs and switches switch one and switch two on
automation finishes
switch two is finally updated to on because of a delay in the coordinator
automation runs and switches switch one and switch two on
automation finishes

that's 3 additional calls to the coordinator

#

instead of just 1

#

TLDR: You always want to debounce with hardware

#

and the never ending automations happen when the user turns on a switch and then off a switch when the coordinator is trying to catch up

mossy oyster
#

I would call that hardly flooding but okay. It is indeed a nice touch but you do rely on messages still receiving in order not to have a loop.

sacred coral
#

no...

#

it will not loop at all

#

it debounces state changes, this is confirmed at my house because I've had these issues

#

There are plenty of "follow me" blueprints on the forums as well that solve this issue in a similar fashion

#

templates are required to do this

mossy oyster
#

Yes it will stop it, but not if states start passing. But that's not really normal πŸ™‚ So yeah, this is the best you can indeed do πŸ™‚

#

Would actually be nice if HA did it itself πŸ™‚

sacred coral
#

in all instances of that automation, you'll have at most 2 executions, even if the user toggles the switch like mad

mossy oyster
#

Can indeed not oscillate infinity but still do funny stuff. Still 2 executions indeed :p

  • Turn on 1
  • HA receives feedback from 1 (1==on, 2 == off)
  • HA commands 2 on
  • Turn off 1
  • HA receives feedback from 1 (1==off, 2==off)
  • thus nothing happens
  • HA receives feedback from 2 (1==off, 2==on)
  • HA commands 1 on
  • HA receives feedback from 1 (1==on, 2==on)
sacred coral
#

show the traces for those

#

I'm 99% sure you're talking out your ass right now where as I built those automations from having a slow coordinator and debouncing the hardware delays

mossy oyster
#

Man, don't be so mean
No, I don't have a trace as it's just a scenario i sketch which can happen and how HA would react.

sacred coral
#

Don't be so contrarian then just because someone else posted another option

#

and for reference saying "pull shit out of your ass" isn't mean, it's a turn of phrase meaning "you're making things up"

#

it may be insensitive, but not mean

#

πŸ™„ post and then delete