Can I sync a service and an entitiy switch

Hello Everyone,

I have a Zigbee Switch and an Agent DVR Service that I want to keep in sync.

switch.ikea_control_outlet_switch ON <=> Alarm control panel: Arm home
switch.ikea_control_outlet_switch OFF <=> Alarm control panel: Arm away

Is this even possible?

TIA

Should be possible.

Do you want bidirectional syncing, as your arrows seem to imply?

i.e. if the switch changes, change the alarm sate, and if the alarm state changes, change the switch state.

Or do you just want the switch to control the alarm?

What is the alarm entity id?

Thanks for your reply.

Yes, that’s what I’m after.

alarm_control_panel.agent_alarm_panel

Here are the Services.

Then you could do something like this:

trigger:
  - platform: state
    entity_id: switch.ikea_control_outlet_switch
    to:  # null "to" triggers on any state change, ignores attribute changes
    id: switch_changed
  - platform: state
    entity_id: alarm_control_panel.agent_alarm_panel
    to:
    id: alarm_changed
action:
  - choose:
      - conditions:
          - condition: template
            value_template: "{{ trigger.id == 'switch_changed }}"
        sequence:
          - service: "alarm_control_panel_arm_{{ 'away' if trigger.to_state.state == 'off' else 'home' }}"
            target:
              entity_id: alarm_control_panel.agent_alarm_panel
      - conditions:
          - condition: template
            value_template: "{{ trigger.id == 'alarm_changed }}"
        sequence:
          - service: "switch.turn_{{ 'off' if trigger.to_state.state == 'armed_away' else 'on' }}"
            target:
              entity_id: switch.ikea_control_outlet_switch
  - delay: 1  # prevents re-triggering after change is made by automation
mode: single
max_exceeded: silent
1 Like

Fantastic, thank you. I will give it a try tomorrow and let you know how it goes.

Again, many thanks for helping.

1 Like

Tried it out. There’s a syntax error in both the value_template lines, missing single quote.

Two Issues:

  1. Armed Home has the light switch ON instead of OFF. Armed Away has it OFF instead of ON.

  2. Changing the Ikea Switch state ON to OFF or OFF to ON does not change the Armed Status.

Thank you,

Greg

EDIT: Fixed (1) by swapping ON and OFF.

Fixed (2) as service name was incorrect. Should be "alarm_control_panel.alarm_arm_ instead of "alarm_control_panel_arm_

Now all working good. Thank you sooooooooooo much.

That’s because that is what you asked for in your first post:

Good catch on the second issue.

1 Like