Automation Assistance - Alarm Previous State?

Hi everyone,
I have written a most excellent automation that makes the lights red in my house when you arrive home and the alarm goes from away to pending, then recalls the snapshot scene to return the lights to their previous state.

The issue is that when the state of alarm disarmed is triggered from the alarm home state change it will recall the snapshot scenes, which can turn the lights on/off at undesired times. I haven’t found a condition to determine the difference between disarmed from away and disarmed from home. Any ideas?

Here’s my automation code for those of you who are interested:

alias: Time to Disarm the Alarm
description: ""
trigger:
  - platform: mqtt
    topic: >-
      /alarm/state
    payload: pending
    id: pending
  - platform: mqtt
    topic: >-
    /alarm/state
    payload: disarmed
    id: disarmed
condition:
  - condition: trigger
    id:
      - pending
      - disarmed
action:
  - choose:
      - conditions:
          - condition: trigger
            id:
              - pending
        sequence:
          - service: scene.create
            data:
              scene_id: alarm_disarm_previous_kitchen
              snapshot_entities: light.kitchen_island
          - service: scene.create
            data:
              scene_id: alarm_disarm_previous_bar
              snapshot_entities: light.bar
          - delay:
              hours: 0
              minutes: 0
              seconds: 0
              milliseconds: 20
          - parallel:
              - service: light.turn_on
                data:
                  brightness_pct: 100
                  color_name: red
                  flash: short
                target:
                  area_id: bar
              - service: light.turn_on
                data:
                  rgb_color:
                    - 255
                    - 0
                    - 0
                  flash: short
                target:
                  entity_id: light.kitchen_island
      - conditions:
          - condition: trigger
            id:
              - disarmed
        sequence:
          - parallel:
              - service: scene.turn_on
                data: {}
                target:
                  entity_id:
                    - scene.alarm_disarm_previous_bar
                    - scene.alarm_disarm_previous_kitchen
mode: queued

You could use a MQTT sensor or trigger-based Template sensor with MQTT triggers to hold the alarm state, then use that sensor as your automation trigger instead of directly triggering the automation off MQTT. That would give you access to the from state in your conditional logic.

Thank you. I have been traveling for work and finally got to work on this.

After reading some more documentation and thinking about it for a few minutes, I came up with this automation output:

params: domain: homeassistant service: turn_on service_data: {} target: entity_id: - binary_sensor.ring_alarm_pending running_script: false

I made a binary_sensor using the Template helper, with the following state template:
trigger: entity_id: automation.ring_alarm_pending to: "true" delay_off: "00:00:60"
The automation doesn’t trigger the binary_sensor for reasons I haven’t been able to piece together quite yet. I’ll look it again after some sleep, but do you (or anyone else) have any ideas as to what I overlooked?

Thanks!

The Template Helper doesn’t support advanced features like triggers or actions for template entities yet, you need to set it up in your configuration.

1 Like