Help Needed - Alarm automation: flash lights on state

Hi, all

I’ve been trying to troubleshoot this the entire weekend and I can’t figure out the issue for the life of me, any help would be appreciated.

Expected behavior:

  • When alarm changes to Pending (Alarmo 30sec Entry Delay) - Pulse Lights Yellow
  • When alarm changes to Triggered - Pulse Lights Red
  • When alarm is Disarmed - Turn lights to ‘normal’ (100% brightness, 3k Kelvin for 2min, then turn off)

Problem:

  • Automation works when alarm is pending (lights yellow :white_check_mark:), it works when alarm changes to triggered (lights red :white_check_mark:). It does not work if alarm if pending and I disarm it, i.e. changing from pending to disarmed. (:x:)
description: Turn on hallway lights based on defined conditions
mode: restart
trigger:
  - platform: state
    entity_id:
      - alarm_control_panel.alarmo
    to: pending
    id: alarm-is-pending
  - platform: state
    entity_id:
      - alarm_control_panel.alarmo
    to: triggered
    id: alarm-is-triggered
  - platform: state
    entity_id:
      - alarm_control_panel.alarmo
    to: disarmed
    id: alarm-is-disarmed
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id:
              - alarm-is-pending
        sequence:
          - alias: Repeat Pulse Hallway Yellow until Alarmo Triggered
            repeat:
              sequence:
                - service: script.turn_on
                  metadata: {}
                  data: {}
                  target:
                    entity_id: script.lights_flash_yellow
              until:
                - condition: state
                  entity_id: alarm_control_panel.alarmo
                  state: disarmed
                  enabled: true
                - condition: state
                  entity_id: alarm_control_panel.alarmo
                  state: triggered
            enabled: true
      - conditions:
          - condition: trigger
            id:
              - alarm-is-triggered
        sequence:
          - alias: Repeat Pulse Hallway Red until Alarmo Disarmed
            repeat:
              sequence:
                - service: script.turn_on
                  metadata: {}
                  data: {}
                  target:
                    entity_id: script.lights_flash_red
              until:
                - condition: state
                  entity_id: alarm_control_panel.alarmo
                  state: disarmed
            enabled: true
      - conditions:
          - condition: trigger
            id:
              - alarm-is-disarmed
        sequence:
          - service: script.turn_on
            metadata: {}
            data: {}
            target:
              entity_id: script.lights_hallway_presence

Visual aid:




Explain “does not work”…

Does the trigger fire?

Is the correct Choose option selected or not?

Is the script.turn_on action executed?

Does the script run?

Hi, @Didgeridrew, all triggers fire as expected. But on changing (from pending) to disarmed, the lights don’t change from yellow to to ‘normal’. Or rather they do for less than a second and return to the yellow state. It seems that somehow the yellow script assigned to the pending state is being put above in the priority level.

I recorded a video - link - (a bit blurry, apologies) to show what I mean. You can see in the very end after scanning the nfc tag (i.e. disarming the alarm) the bulb initially changes to the expected state (brightness 100%) and then goes back to a yellow lower brightness state that is not present in the automation. I can’t understand why it’s doing that.

The better option would be to review/post the trace for the automation when the flip to white and back to yellow happens.

Hi, @FriedCheese

Including a screenshot of the trace below. Nothing jumps to me as wrong after looking at it, to be honest. Let me know if you’d like more info.

Also this is the script it’s running:

alias: Lights Hallway Presence
sequence:
  - service: light.turn_on
    data:
      kelvin: 3000
      brightness_pct: 100
    target:
      entity_id:
        - light.hallway_1
        - light.hallway_2
  - delay:
      hours: 0
      minutes: 3
      seconds: 0
      milliseconds: 0
  - service: light.turn_off
    data: {}
    target:
      entity_id:
        - light.hallway_1
        - light.hallway_2
mode: single

You want to look at the trace timeline tab. There’s a dropdown at the top that should show a time entry each time the automation is triggered. You can do the same for your scripts.

What does the script for flashing the light yellow look like? My assumption is that you have a small race condition going. The automation runs the script to turn the light white, but your yellow script gets part way through a run right after (thus turning the light back yellow) before being stopped.

So here’s a strange thing. I’ve tried running the automation about 10 more times. Of those, maybe 3/4 times it ran as expected, the others had the same issue as described above. Note that I changed absolutely nothing between those tests.

Below examples of when it ran as expected and not as expected (nothing seems different).

Running as expected:
Automation - alarm Pending:


Script - Pulse Lights Yellow

Automation - alarm Disarmed:

Script - Lights back to normal

Running with the issue:
Automation - alarm Pending:


Script - Pulse Lights Yellow

Automation - alarm Disarmed:

Script - Lights back to normal

Here’s all the scripts for flashing the lights:
Flash Yellow/Red when alarm is Pending/Triggered (both scrips are similar, only the color changes):

alias: Lights - Flash Yellow
sequence:
  - service: light.turn_on
    metadata: {}
    data:
      rgb_color:
        - 255
        - 200
        - 0
      brightness_pct: 100
      transition: 1
    target:
      entity_id:
        - light.hallway_1
        - light.hallway_2
  - delay:
      hours: 0
      minutes: 0
      seconds: 1
      milliseconds: 50
    enabled: true
  - service: light.turn_on
    metadata: {}
    data:
      rgb_color:
        - 255
        - 200
        - 0
      brightness_pct: 30
      transition: 1
    target:
      entity_id:
        - light.hallway_1
        - light.hallway_2
  - delay:
      hours: 0
      minutes: 0
      seconds: 1
      milliseconds: 50
    enabled: true
mode: single

So, this reads to me like both the ‘white’ and ‘yellow’ scripts changed the light color within the same second (so a race condition). I’d edit option 3 and add an action before the ‘white’ script to turn off the other two (script.turn_off). Ideally, this will make sure they are no longer running before turning the light back to white.

1 Like

Sir, this seems to have worked like a charm, and you are an absolute legend. I’ve tried it 5 times now and it has ran successfully every single time.

Thank you so much, this was driving me absolutely nuts!

Edit:

If someone runs into the same problem in the future and finds this thread, here’s my full automation:

alias: "Lights - Flash Depending on Alarm State"
description: Turn on hallway lights based on defined conditions
trigger:
  - platform: state
    entity_id:
      - alarm_control_panel.alarmo
    to: pending
    id: alarm-is-pending
  - platform: state
    entity_id:
      - alarm_control_panel.alarmo
    to: triggered
    id: alarm-is-triggered
  - platform: state
    entity_id:
      - alarm_control_panel.alarmo
    to: disarmed
    id: alarm-is-disarmed
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id:
              - alarm-is-pending
        sequence:
          - alias: Repeat Pulse Hallway Yellow until Alarmo Triggered
            repeat:
              sequence:
                - service: script.turn_on
                  metadata: {}
                  data: {}
                  target:
                    entity_id: script.lights_flash_yellow
              until:
                - condition: state
                  entity_id: alarm_control_panel.alarmo
                  state: triggered
            enabled: true
      - conditions:
          - condition: trigger
            id:
              - alarm-is-triggered
        sequence:
          - service: script.turn_off
            metadata: {}
            data: {}
            target:
              entity_id:
                - script.lights_flash_yellow
          - alias: Repeat Pulse Hallway Red until Alarmo Disarmed
            repeat:
              sequence:
                - service: script.turn_on
                  metadata: {}
                  data: {}
                  target:
                    entity_id: script.lights_flash_red
              until:
                - condition: state
                  entity_id: alarm_control_panel.alarmo
                  state: disarmed
            enabled: true
      - conditions:
          - condition: trigger
            id:
              - alarm-is-disarmed
        sequence:
          - service: script.turn_off
            metadata: {}
            data: {}
            target:
              entity_id:
                - script.lights_flash_red
                - script.lights_flash_yellow
          - service: script.turn_on
            metadata: {}
            data: {}
            target:
              entity_id: script.lights_hallway_presence
    enabled: true
mode: restart

1 Like

is it possible for you to share the yaml coding for the blinking of lights for arming, disarming and arming? id be very interested into the route you chose for this alarm setup

Sure thing, @Mike_Breault, see my full automation below:

alias: Lights - Flash Depending on Alarm State
description: Turn on hallway lights based on defined conditions
trigger:
  - platform: state
    entity_id:
      - alarm_control_panel.alarmo
    to: pending
    id: alarm-is-pending
  - platform: state
    entity_id:
      - alarm_control_panel.alarmo
    to: triggered
    id: alarm-is-triggered
  - platform: state
    entity_id:
      - alarm_control_panel.alarmo
    to: disarmed
    id: alarm-is-disarmed
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id:
              - alarm-is-pending
        sequence:
          - alias: Repeat Pulse Hallway Yellow until Alarmo Triggered
            repeat:
              sequence:
                - service: script.turn_on
                  metadata: {}
                  data: {}
                  target:
                    entity_id: script.lights_flash_yellow
              until:
                - condition: state
                  entity_id: alarm_control_panel.alarmo
                  state: triggered
            enabled: true
      - conditions:
          - condition: trigger
            id:
              - alarm-is-triggered
        sequence:
          - service: script.turn_off
            metadata: {}
            data: {}
            target:
              entity_id:
                - script.lights_flash_yellow
          - alias: Repeat Pulse Hallway Red until Alarmo Disarmed
            repeat:
              sequence:
                - service: script.turn_on
                  metadata: {}
                  data: {}
                  target:
                    entity_id: script.lights_flash_red
              until:
                - condition: state
                  entity_id: alarm_control_panel.alarmo
                  state: disarmed
            enabled: true
      - conditions:
          - condition: trigger
            id:
              - alarm-is-disarmed
        sequence:
          - service: script.turn_off
            metadata: {}
            data: {}
            target:
              entity_id:
                - script.lights_flash_red
                - script.lights_flash_yellow
          - service: script.turn_on
            metadata: {}
            data: {}
            target:
              entity_id: script.lights_hallway_presence
    enabled: true
mode: restart