Tie entity togheter

I have a switch Input entity on/off and a relay entity.

I want something as simple that the relay always follow the state of the switch input. Currently i need to creat two automation rules for this, one that turn on the relay and one rule that turn it off, depending on the switch inpur entity.

I think this is just a hassel, how can i creat something simpler then this? I need one script/automation that take care of voth on and off switching. How can this be done?

Very simply. Please post what you have already so we don’t have to guess at what the relevant entities are.

yes and how do you do it? just point me in the direction to the documentation or a give a pointer.

i dont see the point in copy the entitys in here as that is not relevant to the question. you can call it entity 1 and entity 2.

entity 1 is a normaly open switch (INPUT)
entity 2 is also a normaly open switch (relay)

iam confused here as it seems to be no separation for switch as outputs should be relay

Is this relay entity a switch.xxx? And the input entity has been created by yourself input_boolean.xxx? If so, try the template switch. This will create a switch where you can define what happens when you turn it on/off.

Phil asked you for the entities … to make things easier … you just want a link to the documentation.
The problem is, with an input boolean and a switch there are a million and one things you can do with them, so the documentation can’t cover every possible permutation.
What @Burningstone gave you should work but it’s a bit complicated if you never operate the switch directly (just using the input boolean)

You could use this : -

  - alias: au_switch_from_boolean
    trigger:
      - platform: state
        entity_id: input_boolean.xxx 
    action:
      - service_template: switch.turn_{{trigger.to_state.state}}
        entity_id: switch.xxx

It’s more likely to be a binary sensor and a switch.

Maybe, that’s why Phil asked for the entities
:man_shrugging:
He’ll have to adapt it then

Edit:
Though he says : -

So maybe what he really wants is to mirror one switch to another switch.

Dunno !

Copy the automations you created and paste them here.

It’s to help the people who wish to help you. It allows them to work with what you already have rather than try to invent code from scratch. Posting automations, for analysis, is very commonly done in this community forum.

If you don’t want to share the automations, it makes it more challenging for others to help you. In other words, fewer people may be willing to help you if you refuse to comply with a simple request to share what you already have.

Anyway, it’s your decision. Good luck.

1 Like

Yes maybe i could be more clear.

Input is a switch, aka fibaro smart input, its normaly open so its a boolean, as i noted in second post, both enitys is switch.

The output is also a smart implant but a different one. My intention was to use zwave group association in group 2 on this devices but that failed misserable.

There are no virtual entitys, onl ay the ones created by the devices itself.

Yes see my second post

Yes that is correct, as the thread header say “tie entity togheter” this applys that the entitys must be of same type. Switch.

Smart implat from fibaro is created that the INPUT 1 and OUTPUT 1 are SAME entity. That means if you set the input to high the output is high. If you turn the switch entity to high the output will be high.

I use two of this implants, one that reads input only and creates switch.entity 1 and the second that uses OUTPUT only and has entity switch.entity2

I want to tie this togheter, in a simple means, that entity 2 always reflect entity 1

I would have solved this by using group association for on/off and put the output smart implant in the input group, but association in HA dont work

The automation rules that i try to avoid using is:

For turn ON

IF SWITCH.ENTITY1 = ON
SET: SWITCH.ENTITY2 = ON

For turn OFF

IF SWITCH.ENTITY1 = OFF
SET: SWITCH.ENTITY = OFF

using any form of toggle is not possible!

It appears that what you want can be achieved with the technique used in Mutt’s example. Something like this:

  - alias: leader follower
    trigger:
      - platform: state
        entity_id: switch.entity1
    action:
      - service_template: switch.turn_{{trigger.to_state.state}}
        entity_id: switch.entity2

This is perfect.

Just one note, when using template with oneliners, remember to use quote or place it on new line.

service_template: |
  switch.turn_{{ trigger.to_state.state }}

I wish the documentation was better i HA, its kind of difficult to find anything

Thank you

I approached this by having a script that does the logic. Then I can reuse the script.

Here’s my script:

# If the leader is on, then turn on the followers.
# Otherwise turn off the followers.
set_to_leader:
  sequence:
  - service_template: >
      {% if (is_state(leader, "on")) %}
        homeassistant.turn_on
      {% else %}
        homeassistant.turn_off
      {% endif %}
    data_template:
      entity_id: "{{followers}}"

Then I call it as follows:

- alias: Kitchen All On Off
  id: kitchen_all_on_off
  mode: restart
  trigger:
    - platform: event
      event_type: zwave_js_value_notification
      event_data:
        node_id: 15 # light.kitchen_ceiling_switch
        value: 16 # single-click
  action:
    - service: script.set_to_leader
      data_template:
        leader: light.kitchen_ceiling_switch
        followers: light.kitchen_counter_switch, switch.kitchen_fan_accent_switch, switch.kitchen_bar_switch

You could simplify the template a bit with the suggestion in this thread too.

1 Like