Hi @adchevrier , just wanted to chime in with an interesting side effect, since I love this blueprint, and I use it heavily, maybe I can contribute.
I’ve noticed that I get some error masseges in my logs, HA not findig service which the blueprint calls. I realised it’s due to the fact that sometimes my shelly switches become unavailable, and when this state change happens to any of the lights included in the automation based on this blueprint, it tries to set the other lights to unavailable as well
Minor issue, doesn’t influence normal behaviour, just wanted to let you know.
Error while executing automation automation.XXXX: Unable to find service homeassistant.turn_unavailable
Thanks for the blueprint.
I wanted to use the blueprint to sync the status of my media player with an input_boolean so that I could turn the TV on and off via google home.
Unfortunately, a media player has more states than just on and off (unavailable, playing, unknown) so that error messages keep popping up in the log.
I have been messing with trying to make this work for two days and well dah me…I should have come here first and looked for blueprint…Thank you so much for this simple but yet effective blueprint!
Hello,
Im having an issue. Im not sure if its the blueprint or my setup. I have a Tuya 4 touch switch with the Tuya integration controlling 2 light groups (consisting of 2 bulbs each using Tuya integration) and 2 broadlinks controlling 2 A/Cs. The switches with the devices are out of sync. Seems that sometimes it gets out of sync when I use Alexa to control the devices instead of the switches, but not all the time. I can ask Alexa to turn the A/C on and the switch turns on, but not all the time. Also if Alexa turns off the light the switch can stay on and after some time the lights turn back on. Im guessing its syncing the lights to the switch and turns it on instead of turning the switch off. Any ideas? Thanks.
Hello,
I think I have figured out most of it except for the A/C part. My A/C has off and cool, not off and on. My switch has off and on. How can I translate cool to on for this to work?
Error message is:
Error while executing automation automation.synchronize_office_wall_switch_2_to_office_a_c: Unable to find service homeassistant.turn_cool
Thats because it doesn’t exist for what I know. I think the automation is looking for cool when it doesn’t exist because the A/C has off and cool as options. Is there a way to add for example, cool = on for the A/C entity on the automation? Thanks.
Well, you should be able to achieve that, but not with this blueprint I guess. You can manually modify the automation, or better, modify a copy without a reference to the blueprint.
Then you can call any service you like, for instance from the climate domain.
So I set this up to synchronize the lights at the top and bottom of my stairs. However, it’s not exactly what I want, as I only really have one switch I want to use and so I really want to unidirectionally “copy” state from one entity (a switch) to another (a receptacle). Also, my receptacle device is slow, and sometime it is slow enough (or maybe it just misses the state change) the old, incorrect state gets copied BACK and the light turns off! It’s also overall slower than I would like. I switched to HA from ST to try and avoid cloud delays, but if anything it’s slower now. I often end up halfway down the stairs before the light at the top (connected to the “controlled” receptacle) turns on.
I realize a blueprint to just “copy” a binary state is actually a pretty trivial (probably I should try to set it up directly as an automation) but it still would be pretty useful to have as a blueprint just to allow for a nicer setup UI.
If it matters both devices are Z-Wave (for now; the light at the top is an addressable LED strip, eventually to be turned into an ambient data display via MQTT probably, but for now I just want to control it by switching power on and off). Anyway, the future extension I have in mind is why I want to do this with an automation rather than Z-wave direct association etc.
I’m guessing you added a condition to prevent flickering/loop. If you think about it, it can still go to an infinite loop if states are not updated in real time. Personally I found that the only way to truely prevent a loop is to add a 0.5-1 second delay to one switch/light triggering the other. So it goes like this: If light A is turned on/off, then immediately turn light B on/off. If light B is turned on/off FOR ONE SECOND, then turn light A on/off. Let me know your thoughts. In my use case the delay is not a big deal and preventing the loop really gives me peace of mind
1 second delay is too long to my liking. It also have the side effect of not registering if the switch was turned ON then OFF in less than 1s.
I’ve been runing this for almost a year and never experienced flickering. I do agree that it could still happen in some edge cases.
One thing you may test is adding a condition on the context, to block state change if it was triggered by the automation itself. I tested it briefly and it seems to do the trick:
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) }}
I tested this one extensively this morning, and worked very well for me.
I have versions of this with up to 5 switches and fast clicking did not resulted in flickering.
Please let me know if it works for you.
blueprint:
name: Synchronize 2 States
description: Bind two switches together to act in unison
domain: automation
input:
switch_1:
name: Switch 1
selector:
entity:
domain: switch
switch_2:
name: Switch 2
selector:
entity:
domain: switch
variables:
switches:
- !input switch_1
- !input switch_2
trigger:
- platform: state
entity_id:
- !input switch_1
- !input switch_2
mode: queued
max_exceeded: silent
condition:
- condition: template
value_template: '{{ trigger.to_state.state != trigger.from_state.state }}'
- 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) }}
action:
# Set to target value
- service: 'switch.turn_{{ trigger.to_state.state }}'
target:
entity_id: '{{ expand(switches) | selectattr("entity_id", "!=", trigger.entity_id) | map(attribute="entity_id") | list }}'
I have some recessed lights that are in the ceiling 2 next to each other. Unfortunately some lights come on without being triggered. Always on by the way, never off or any other change.
Could I use this template to check each pair and if 1 is of, to also switch the other off?
How would I do this?
Thank you for your sharing. It seems to be better but still not cover all the cases.
I’ve tested your updated blueprint and if still touch button 1 very fast, there is still a loop (I test 3 times and got 1 time loop).
Beside that, if touch button 1 very fast then touch button 2 only 1 time, the button 1 is not synced with button 2.