Alarmo script to toggle lights when alarm is triggered: works except for the last part

The following script flashes/toggles the following on and off when Alarmo is triggered:

  • light.wiz_rgbw_tunable_f511a3 (Philips color light)
  • switch.piano_light_switch (Sonoff ZigBee Smart Plug connected to a lamp)
  • switch.buffet_table_lamps_switch (Sonoff ZigBee Smart Plug connected to a lamp)
  • light.master_bathroom_ceiling_lights (Levitron D26HD light wifi switch)

This part works. They flash or change color. But when the Alarmo system is disarmed, only the smart plugs correctly turn the lights back on. The light switch, however, doesn’t turn the light back on. And the smart bulb stays in the red color state.

Can you advise me on what I should change (towards the end) of this script to force the light switch to turn the light back on, and for the light bulb to return to a white colour state?

alias: Alarmo flashing lights
sequence:
  - repeat:
      sequence:
        - service: light.turn_on
          target:
            entity_id:
              - light.wiz_rgbw_tunable_f511a3
            device_id: []
            area_id: []
          data:
            rgb_color:
              - 0
              - 0
              - 255
            brightness_pct: 100
        - service: switch.turn_on
          target:
            entity_id:
              - switch.piano_light_switch
              - switch.buffet_table_lamps_switch
          data: {}
        - type: turn_on
          device_id: fbefee1ced2f20e4d92d825eaee043c0
          entity_id: 8eb5a5f0f9c816463216308889e98352
          domain: light
          brightness_pct: 100
        - service: light.turn_on
          target:
            entity_id:
              - light.master_bathroom_ceiling_lights
            device_id: []
            area_id: []
          data:
            transition: 0
        - delay:
            hours: 0
            minutes: 0
            seconds: 1
            milliseconds: 0
        - service: light.turn_on
          target:
            entity_id:
              - light.wiz_rgbw_tunable_f511a3
            device_id: []
            area_id: []
          data:
            rgb_color:
              - 255
              - 0
              - 0
            brightness_pct: 100
        - service: switch.turn_off
          target:
            entity_id:
              - switch.piano_light_switch
              - switch.buffet_table_lamps_switch
          data: {}
        - type: turn_off
          device_id: fbefee1ced2f20e4d92d825eaee043c0
          entity_id: 8eb5a5f0f9c816463216308889e98352
          domain: light
        - service: light.turn_off
          target:
            entity_id: light.master_bathroom_ceiling_lights
          data:
            transition: 0
      until:
        - condition: state
          entity_id: alarm_control_panel.alarmo
          state: disarmed
  - service: switch.turn_on
    target:
      entity_id:
        - switch.piano_light_switch
        - switch.buffet_table_lamps_switch
    data: {}
  - service: light.turn_on
    target:
      entity_id:
        - light.master_bathroom_ceiling_lights
      device_id: []
      area_id: []
    data:
      brightness: 65
      profile: Max brightness
      transition: 0
  - type: turn_on
    device_id: fbefee1ced2f20e4d92d825eaee043c0
    entity_id: 8eb5a5f0f9c816463216308889e98352
    domain: light
    brightness_pct: 100
  - service: light.turn_on
    target:
      entity_id: light.wiz_rgbw_tunable_f511a3
    data:
      rgb_color:
        - 255
        - 255
        - 255
      kelvin: 3015
      brightness_pct: 100
mode: single
icon: mdi:lightbulb

First off, bad form using device_id to refer to a device (via type: turn_on); you should switch that to a service that supports the device (light.turn_on?)

I haven’t really diagnosed your existing code, rather I’d recommend replacing everything outside of the repeat action

Before the repeat, create a temporary scene (a “snapshot” which saves the current states of your four devices: on/off state for switch, color data for light)

  - service: scene.create
    data:
      scene_id: before_alarm
      snapshot_entities: 
        - light.wiz_rgbw_tunable_f511a3
        - switch.piano_light_switch
        - switch.buffet_table_lamps_switch
        - light.master_bathroom_ceiling_lights

…and then replace everything after the repeat with a call to restore the entities to their snapshot

  - scene: scene.before_alarm

Put it all together and you get:

alias: Alarmo flashing lights
sequence:
  - service: scene.create
    data:
      scene_id: before_alarm
      snapshot_entities: 
        - light.wiz_rgbw_tunable_f511a3
        - switch.piano_light_switch
        - switch.buffet_table_lamps_switch
        - light.master_bathroom_ceiling_lights
  - repeat:
      sequence:
        - service: light.turn_on
          target:
            entity_id:
              - light.wiz_rgbw_tunable_f511a3
            device_id: []
            area_id: []
          data:
            rgb_color:
              - 0
              - 0
              - 255
            brightness_pct: 100
        - service: switch.turn_on
          target:
            entity_id:
              - switch.piano_light_switch
              - switch.buffet_table_lamps_switch
          data: {}
        - type: turn_on
          device_id: fbefee1ced2f20e4d92d825eaee043c0
          entity_id: 8eb5a5f0f9c816463216308889e98352
          domain: light
          brightness_pct: 100
        - service: light.turn_on
          target:
            entity_id:
              - light.master_bathroom_ceiling_lights
            device_id: []
            area_id: []
          data:
            transition: 0
        - delay:
            hours: 0
            minutes: 0
            seconds: 1
            milliseconds: 0
        - service: light.turn_on
          target:
            entity_id:
              - light.wiz_rgbw_tunable_f511a3
            device_id: []
            area_id: []
          data:
            rgb_color:
              - 255
              - 0
              - 0
            brightness_pct: 100
        - service: switch.turn_off
          target:
            entity_id:
              - switch.piano_light_switch
              - switch.buffet_table_lamps_switch
          data: {}
        - type: turn_off
          device_id: fbefee1ced2f20e4d92d825eaee043c0
          entity_id: 8eb5a5f0f9c816463216308889e98352
          domain: light
        - service: light.turn_off
          target:
            entity_id: light.master_bathroom_ceiling_lights
          data:
            transition: 0
      until:
        - condition: state
          entity_id: alarm_control_panel.alarmo
          state: disarmed
  - scene: scene.before_alarm
mode: single
icon: mdi:lightbulb

Note: the before_alarm scene is deleted upon restart of your system.

Thank you for the advice on creating a temporary scene. I used the code your tweaked and it works with the Run Script (under three dots). But when I trigger the Alarmo alarm, it fails to run. Not sure why. I re-started the YAML, etc. I then tried my original (messy) code again and that worked. Then I discovered the reason why my Philips Wiz color light wasn’t reverting back to white. In the settings, you can only list a value in the Color section OR the Color Temperature section—but not both. That is why it didn’t turn white after Alarmo was disarmed. And for my Levitron switch, I unchecked the box Transition, which left only the Brightness Value checked. This solved that problem as well. So, now my original script works.

I like you idea of creating the temporary scene, as that is cleaner code. It’s just that something about that script isn’t activating when my Alarmo is triggered.

For the record, here is my updated script based on my original script.

alias: Alarmo flashing lights v1
sequence:
  - repeat:
      sequence:
        - service: light.turn_on
          target:
            entity_id:
              - light.wiz_rgbw_tunable_f511a3
            device_id: []
            area_id: []
          data:
            rgb_color:
              - 0
              - 0
              - 255
            brightness_pct: 100
        - service: switch.turn_on
          target:
            entity_id:
              - switch.piano_light_switch
              - switch.buffet_table_lamps_switch
          data: {}
        - type: turn_on
          device_id: fbefee1ced2f20e4d92d825eaee043c0
          entity_id: 8eb5a5f0f9c816463216308889e98352
          domain: light
          brightness_pct: 100
        - service: light.turn_on
          target:
            entity_id:
              - light.master_bathroom_ceiling_lights
            device_id: []
            area_id: []
          data:
            transition: 0
        - delay:
            hours: 0
            minutes: 0
            seconds: 1
            milliseconds: 0
        - service: light.turn_on
          target:
            entity_id:
              - light.wiz_rgbw_tunable_f511a3
            device_id: []
            area_id: []
          data:
            rgb_color:
              - 255
              - 0
              - 0
            brightness_pct: 100
        - service: switch.turn_off
          target:
            entity_id:
              - switch.piano_light_switch
              - switch.buffet_table_lamps_switch
          data: {}
        - type: turn_off
          device_id: fbefee1ced2f20e4d92d825eaee043c0
          entity_id: 8eb5a5f0f9c816463216308889e98352
          domain: light
        - service: light.turn_off
          target:
            entity_id: light.master_bathroom_ceiling_lights
          data:
            transition: 0
      until:
        - condition: state
          entity_id: alarm_control_panel.alarmo
          state: disarmed
  - service: switch.turn_on
    target:
      entity_id:
        - switch.piano_light_switch
        - switch.buffet_table_lamps_switch
    data: {}
  - service: light.turn_on
    target:
      entity_id:
        - light.master_bathroom_ceiling_lights
      device_id: []
      area_id: []
    data:
      brightness: 255
  - type: turn_on
    device_id: fbefee1ced2f20e4d92d825eaee043c0
    entity_id: 8eb5a5f0f9c816463216308889e98352
    domain: light
    brightness_pct: 100
  - service: light.turn_on
    target:
      entity_id: light.wiz_rgbw_tunable_f511a3
    data:
      brightness_pct: 100
      rgb_color:
        - 255
        - 255
        - 255
mode: single
icon: mdi:lightbulb

Not sure what would be preventing it from running. For future reference, if you check Settings > System > Logs you will likely see information related to why things fail as you were initially experiencing. To solve your new problem, you can open the trace data for automations/scripts to see what’s going wrong, where the script or calling automation isn’t going through (clicking the triple dots and choosing Traces)

Hi, I’m trying to do the same ‘lights flash’ when Alarmo is triggered and came across this script.
I appologise in advance for my butchering of the script but I know nothing about coding.
At the moment I just want to get a single lamp to flash as I’m still trying to get my head around Alarmo etc.
This is my butchered code that comes back as valid YAML on all the verifiers I’ve tried, but I get the error 'Message malformed: extra keys not allowed @ data[‘sequence’] when trying to save it in Home Assistant.
I’m running HAOS, fully patched and updated.

alias: Alarmo flashing lights
sequence:
  - service: scene.create
    data:
      scene_id: before_alarm
      snapshot_entities: 
        - light.diningroom_light
  - repeat:
      sequence:
        - service: light.turn_on
          target:
            entity_id:
              - light.diningroom_light
            device_id: []
            area_id: []
          data:
            rgb_color:
              - 0
              - 0
              - 255
            brightness_pct: 100
        - delay:
            hours: 0
            minutes: 0
            seconds: 1
            milliseconds: 0
        - service: light.turn_off
          target:
            entity_id:
              - light.diningroom_light
          data: {}
      until:
        - condition: state
          entity_id: alarm_control_panel.alarmo
          state: disarmed
  - scene: scene.before_alarm
mode: single
icon: mdi:lightbulb

Any help gratefully recieved.

I just copy/pasted your exact script (replacing with my own entities), saved it, then triggered the repeat action with no problem.

sometimes the YAML editor glitches, try refreshing the page and saving it again, or check your Settings>System>Logs for more detailed error message