ESPHome Tag reader trigger automation twice

Hello, I’ve build the ESP home tag reader from the GIT hub page of Adonno. This worked fine for quite some time.
I have two automations attached to it:

  • disable alarm if alarm is enabled & send message to telephone Alarm disabled
  • enable alarm if alarm is disabled & send message to telephone Alarm enabled

Since a couple of months I have the strange problem, when i swipe my token passed the reader while the alarm is disabled, it enables it and i get 2 messages on my app telling me that the alarm is enabled. I thought it was strange but it worked…

Recently (since a week of 4) when i swipe my token when the alarm is enabled, i get an message that he alarm is disabled, but immediately i egt a second message that the alarm is enabled again.
The alarm is effectively enabled after this.
I can use the Alarmo keypad on my phone to disable fine.

When i check the tracer, i see both automation triggered at the same time.

Automation Alarm On

alias: Tag Erwin_tag Arm
description: ""
trigger:
  - platform: tag
    tag_id: zz-zz-zz-zz
  - platform: tag
    tag_id: yy-yy-yy-yy
  - platform: tag
    tag_id: xx-xx-xx-xx
condition:
  - condition: device
    device_id: 1
    domain: alarm_control_panel
    entity_id: alarm_control_panel.alarmo
    type: is_disarmed
action:
  - device_id: 1
    domain: alarm_control_panel
    entity_id: alarm_control_panel.alarmo
    type: arm_away
  - device_id: 2
    domain: mobile_app
    type: notify
    message: Alarm thuis ingeschakeld
  - device_id: 3
    domain: mobile_app
    type: notify
    message: Alarm thuis ingeschakeld
  - device_id: 4
    domain: mobile_app
    type: notify
    message: Alarm thuis ingeschakeld
mode: single

Automation Alam off:

alias: Tag Erwin_tag Disarm
description: ""
trigger:
  - platform: tag
    tag_id: zz-zz-zz-zz
  - platform: tag
    tag_id: yy-yy-yy-yy
  - platform: tag
    tag_id: xx-xx-xx-xx
condition:
  - condition: device
    device_id: 1
    domain: alarm_control_panel
    entity_id: alarm_control_panel.alarmo
    type: is_armed_away
action:
  - service: alarmo.disarm
    data:
      entity_id: alarm_control_panel.alarmo
      code: "AABBCCDD"
mode: single`

is there any way i can see why this is happening? and what can i do to prevent this?
Any advise is welcomed…

You are using the same trigger for both automations and when you swipe it you begin both automations. Check the traces button on the top right of the screen when you select the automation.
Perhaps there is a short delay in the time before trigger and condition so if goes from enable to disable the enable automation sees the condition as disabled and proceeds with the action.
Combine the 2 automations with a choose condition as an action but leave empty the initial and if blank.

action:
  - service: alarmo.disarm
    data:
      entity_id: alarm_control_panel.alarmo
      code: "AABBCCDD"

Don’t know if you just mistyped the automation on the alarm on but there is no service call to arm it or if it’s armed in a different way.

I’m not so well in making these automations.
I understand to combine the two i need some sort of
if armed do action1
if disarmed do action 2

How can i combine this in the automations.

I did the current one via the GUI, and it worked for quite a while ( over a year)

You don’t need to hide your enitity_ids, device_ids or tags.
It will just make it a lot messier for you now.
Redacting the code is sensible but everything else is just your entities.

alias: Tag Erwin_tag Arm/disarm
description: ""
trigger:
  - platform: tag
    tag_id: zz-zz-zz-zz
  - platform: tag
    tag_id: yy-yy-yy-yy
  - platform: tag
    tag_id: xx-xx-xx-xx
condition: []
action:
  - choose:
      - conditions:
          - condition: device
            device_id: 1
            domain: alarm_control_panel
            entity_id: alarm_control_panel.alarmo
            type: is_disarmed
        sequence: 
          - device_id: 1
            domain: alarm_control_panel
            entity_id: alarm_control_panel.alarmo
            type: arm_away
          - device_id: 2
            domain: mobile_app
            type: notify
            message: Alarm thuis ingeschakeld
          - device_id: 3
            domain: mobile_app
            type: notify
            message: Alarm thuis ingeschakeld
          - device_id: 4
            domain: mobile_app
            type: notify
            message: Alarm thuis ingeschakeld

      - conditions:
          - condition: device
            device_id: 1
            domain: alarm_control_panel
            entity_id: alarm_control_panel.alarmo
            type: is_armed_away
        sequence: 
          - service: alarmo.disarm
            data:
              entity_id: alarm_control_panel.alarmo
              code: "AABBCCDD"
mode: single
1 Like

I have made a change to the Alarm on automation, i has an extra dependecy that the alarm is disbaled for at leat 10 seconds.

I’ll test it tonight.

alias: Tag Erwin_tag Arm
description: ""
trigger:
  - platform: tag
    tag_id: 12-34-56-78
  - platform: tag
    tag_id: AA-BB-CC-DD
  - platform: tag
    tag_id: AA-12-BB-24
condition:
  - condition: and
    conditions:
      - condition: device
        device_id: 9c039588c01313373bbfe9f59b01c3bb
        domain: alarm_control_panel
        entity_id: 37fd362a31c0519f60fc89885df8c97d
        type: is_disarmed
      - condition: state
        entity_id: alarm_control_panel.alarmo
        attribute: arm_mode
        state: Disarmed
        for:
          hours: 0
          minutes: 0
          seconds: 10
action:
  - device_id: 9c039588c01313373bbfe9f59b01c3bb
    domain: alarm_control_panel
    entity_id: alarm_control_panel.alarmo
    type: arm_away
  - device_id: 73f559795930538337400252133ff851
    domain: mobile_app
    type: notify
    message: Alarm thuis ingeschakeld
  - device_id: 43fdf830c8001ad3566fe1021ae3eda7
    domain: mobile_app
    type: notify
    message: Alarm thuis ingeschakeld
  - device_id: e0f217ea81db46365cb55ad80509ecbf
    domain: mobile_app
    type: notify
    message: Alarm thuis ingeschakeld
mode: single

The above didn’t work, 2nd condition was never met…

Are you sure it’s the arm_mode that is Disarmed? Shouldn’t it be the state?

The code worked before, I’ve added the time out later since the automation are triggered in correctly since a couple of weeks

That condition is not in your first post.

Have you tried the code I posted?

Hi Hellis,

I’m sorry for the late response was bussy in other areas ;-(
I completly mised that you rewrote my code to a working sollution.

I’ve implemnetd the automation as made by you.
Tested it and it works like a charm. :partying_face:

I’m really happy with the outcome.
Thank you very much for the help and effort.

(And i learned an new option “Then Do” “Choose between 2 actions” )