Link On/Off State of Multiple Devices

Link On/Off State of Multiple Devices v1.0.0

Open your Home Assistant instance and show the blueprint import dialog with a specific blueprint pre-filled. View source code

Select multiple entities to link their on/off state. If any selected entity is turned on or off, the other selected entities will be sent a matching on or off command.

You can select any entity, but only entities supported by the homeassistant.turn_on or homeassistant.turn_off service calls will work.

Requirements

  • All selected entities MUST suport homeassistant.turn_on and homeassistant.turn_off or errors will be logged and the blueprint will not work.
  • Requires Home Assistant 2022.5.0 or newer.

Credits

8 Likes

@luma thank you for this great blueprint. I need your help as I have an issue with it.
Iā€™ have 1 Sonoff Mini connected to 2 switches. One of them connected to a light bulb.

What I want to achieve is simple: either switch powen on/off the light :slight_smile:

Iā€™ve used the blueprint and put mini1 and mini2 as entities.
Both support the turn_on turn_off.

The funny thing is that they work 60% of the time, more or less.
Meaning this is expected:

  1. I press switch 1 to on ā†’ switch 2 goes on
  2. I press switch 1 to off ā†’ swith 2 goes off
  3. I press switch 2 to on ā†’ switch 1 goes on
  4. I press switch 2 to off ā†’ swith 1 goes off

now it happens almost a third of the time that I press either 1 or 2 in on/off but the other switch does not commute.
Initially I though it was a 1->2 working and 2->1 not working, while is not like that if I repeat the on/of on the same switch sometimes works, sometimes does not work

Am I the only one whoā€™s happening? how can I diagnose?
any help?

I did some analysis and when the command does not propagate if for this reason:

Note that the first two conditions are met and true

why this:

condition: template
value_template: >-
  {{trigger.to_state.context.parent_id is none or (trigger.to_state.context.id
  != this.context.id and trigger.to_state.context.parent_id != this.context.id)
  }}

is needed?

Additional info:
Iā€™ve removed the last condition and now everything works always.

I use this blueprint to link a zwave wall switch that operates an outlet (nothing connected) with two zwave smart outlets on the other side of the room that operate bedside lamps. The blueprint operates correctly most of the time, often some of the smart outlets are very slow to turn on or off. (at times multiple seconds). None of this behavior is a problem, just a bit odd that it takes so much time to complete the automation.

Tonight a very strange sequence happened where the on/off triggers were operating sequentially. After turning on the wall switch, the three switches were in an open loop turning on and off and not stopping. I had to disable the blueprint to stop it. (It was quite a show that freaked my wife, she thought I had planted a Halloween treat for her! :smile: )

The logbook shows the on/off sequence triggering from other switches in the list.
I have not yet determined what happened. Is it possible that state change operation is not waiting for completion before moving on?

I saw this previously in another application of the same blueprint but triggered instead by an OR of three motion detectors. (Any motion triggers an action of one of three linked light switches) This re-triggering of on/off was quite regular, occurring most of the time. Until tonight I thought that this was a side effect of the motion detectors.

3 Likes

Thanks for this blueprint, itā€™s very useful! :slight_smile:

Thanks to this Blueprint, Thanks @luma . I was following since @hebus timeā€¦great blueprint until the the ā€œunavailableā€ error occurs on the latest HA update.

This one works fantastically.

Solid work @luma. Will you make an update to add in presets, effects and/or effects? Lights Iā€™ve linked to these switches donā€™t survive notification blinks with their color intact.

Hi all, noob here. In regards to this blueprint I only want it to happen during certain times and days of the week. Can I assume that I can just insert the below code into this code under the conditions section?

condition:
  - condition: time
    weekday:
      - mon
      - tue
      - wed
      - thu
      - fri
      - sat
    after: "07:00:00"
    before: "23:59:00"

I assume that I will have to not use the blueprint but instead create an automation from the source code?

All good. I sorted it out with some code from Twanneā€™s blueprint_day_time_condition. Added this to the blueprint and now it works between days and time that are specified. If anyone is interested this is how I set it up

This conditions exists to prevent loop:

S1 physically turns on (trigger blueprint) > Link Blueprint turn S2 (also trigger blueprint, wont get past the condition you deleted)

But appears that the parent id of the context.to_state.parent_id wont appear as null in this sceario:

S1 off > on (physically)
S2 off > on (blueprint turned on)
S2 on > off) (parent_id is not null) (wont get past condition)

edit: seems to only happen when trigged when changing state using the phyisical button on the device, if done via UI works fine.

For my situation, I have a device that reports unavailable when HA restarts. Therefor, Iā€™ve added an extra condition template to have it not trigger the automation when the state of a device changes ā€œfrom unavailableā€:

- condition: template
  value_template: '{{ trigger.from_state.state != "unavailable" }}'

Seems to work like a charm now for me :slight_smile:

1 Like

I have the same issue, How did you manage to solve it?

Thanky for this blueprint !
I used it to link a ZWave in-wall-switch to a Hue Zigbee ceiling lamp (complex with many lights).

Sadly, I found an error I canā€™t quite get behind :

  • Using the Home Assistant app / Lovelace UI everything works as expected. I can even see the switch state change as expected.
  • When using the switch alone, everything works as expected

Here comes the error :

  • When I change the state over the UI / App, I canā€™t change the state using the switch for some seconds (something like 4-5 seconds)
    Does anyone have an idea what it might be ?
    Thanks !

Whjile this plugin works great, anyone also noticing a noticable delay between flcking a switch (not the main one but the slave one),

takes about 10-15 seconds in order to switch the other switch. Any idea how i can resolve this delya??

View the traces in your automation and check the timestamps to find where the delay is happening. Either the master switch is slow to report, or your slave switch is slow to respond.

Got it fixed.

Device causing it was an ESP32. Setting the powersafe option in ESP home to none, fixed it.

Thought it was the plugin, but my mistake. Plugin is working instantly!!

Excuses :slight_smile:

Hello,

This is a great blueprint, thank you! One question, is there a way to still operate the switches individually? Most of the times I want all of the switches to turn on/off at the same time, but there are occasions when I would only one to turn on. Can this be achieved? (Ideally Iā€™d like to create a ā€˜masterā€™ switch for all the switches, but then also retain all the idividual switches).

Thanks

edit: just figured out i can do this with a Group Helper

Edit 2: is there a way to add Helpers to dashboard??

I use this to link a wifi wall switch with a wifi power inline on a light cord. Very simple setup.

Yesterday I had it freak out on me after turning the wall switch off and on quickly by mistake, then trying to turn it off again. They both start toggling on and off continuously for about 10 seconds. Never seen this before.

Sharing my v1.1 update with @bart_lauwers53 code and every minute background check. Nothing else changed. Source code here

Getting many errors in log from you 1.1 script (15.000 errors in 2 days).

Logger: homeassistant.components.automation
Source: components/automation/__init__.py:1006
Integration: Automatisierung ([documentation](https://www.home-assistant.io/integrations/automation), [issues](https://github.com/home-assistant/core/issues?q=is%3Aissue+is%3Aopen+label%3A%22integration%3A+automation%22))
First occurred: 18:27:00 (645 occurrences)
Last logged: 19:09:00

* Error evaluating condition in 'Link_SpĆ¼le_Alexa': In 'condition' (item 1 of 4): In 'template' condition: UndefinedError: 'dict object' has no attribute 'to_state' In 'condition' (item 2 of 4): In 'template' condition: UndefinedError: 'dict object' has no attribute 'to_state' In 'condition' (item 3 of 4): In 'template' condition: UndefinedError: 'dict object' has no attribute 'to_state' In 'condition' (item 4 of 4): In 'template' condition: UndefinedError: 'dict object' has no attribute 'from_state'
* Error evaluating condition in 'Link_Badstreifen_Alexa': In 'condition' (item 1 of 4): In 'template' condition: UndefinedError: 'dict object' has no attribute 'to_state' In 'condition' (item 2 of 4): In 'template' condition: UndefinedError: 'dict object' has no attribute 'to_state' In 'condition' (item 3 of 4): In 'template' condition: UndefinedError: 'dict object' has no attribute 'to_state' In 'condition' (item 4 of 4): In 'template' condition: UndefinedError: 'dict object' has no attribute 'from_state'
* Error evaluating condition in 'Link_Werkbank_Alexa': In 'condition' (item 1 of 4): In 'template' condition: UndefinedError: 'dict object' has no attribute 'to_state' In 'condition' (item 2 of 4): In 'template' condition: UndefinedError: 'dict object' has no attribute 'to_state' In 'condition' (item 3 of 4): In 'template' condition: UndefinedError: 'dict object' has no attribute 'to_state' In 'condition' (item 4 of 4): In 'template' condition: UndefinedError: 'dict object' has no attribute 'from_state'
* Error evaluating condition in 'Link_Werkstatt_Alexa': In 'condition' (item 1 of 4): In 'template' condition: UndefinedError: 'dict object' has no attribute 'to_state' In 'condition' (item 2 of 4): In 'template' condition: UndefinedError: 'dict object' has no attribute 'to_state' In 'condition' (item 3 of 4): In 'template' condition: UndefinedError: 'dict object' has no attribute 'to_state' In 'condition' (item 4 of 4): In 'template' condition: UndefinedError: 'dict object' has no attribute 'from_state'
* Error evaluating condition in 'Link_Unten_Alexa': In 'condition' (item 1 of 4): In 'template' condition: UndefinedError: 'dict object' has no attribute 'to_state' In 'condition' (item 2 of 4): In 'template' condition: UndefinedError: 'dict object' has no attribute 'to_state' In 'condition' (item 3 of 4): In 'template' condition: UndefinedError: 'dict object' has no attribute 'to_state' In 'condition' (item 4 of 4): In 'template' condition: UndefinedError: 'dict object' has no attribute 'from_state'

Can you tell me whats wrong here? (Links are working flawlessly)

1 Like