Enable/disable automation alarm

Hi,
I wish to create a button or switch on my dashboard, to enable/disable an automation who is an active an “alarm mode”.
My automation send me notification if my cameras detect movement or if my windows detector receives open state.

alias: Alarm
description: Alarme
trigger:
  - platform: device
    device_id: 149b2799b5d82a300c5601165b9a2ce3
    domain: select
    entity_id: ce1d019c9d7a9853ebc8a197baf214c8
    type: current_option_changed
    from: Not Recording
    to: Motion Record
  - platform: device
    type: changed_states
    device_id: 6f103c1b1a43d909ba4d1b7ac02c5915
    entity_id: c348971f284a1488f429242ac2e4eb4b
    domain: switch
  - type: opened
    platform: device
    device_id: db00d9e1535e6533dade812e8e0e2bc1
    entity_id: d13149d5c0a13d70ff1b34d07bc1c38d
    domain: binary_sensor
condition: []
action:
  - choose:
      - conditions:
          - condition: device
            device_id: 149b2799b5d82a300c5601165b9a2ce3
            domain: select
            entity_id: ce1d019c9d7a9853ebc8a197baf214c8
            type: selected_option
            option: Motion Record
        sequence:
          - service: telegram_bot.send_message
            metadata: {}
            data:
              message: Un mouvement a été détecté sur la caméra intérieure.
              title: Alerte mouvement intérieur!
      - conditions:
          - condition: device
            type: is_on
            device_id: 6f103c1b1a43d909ba4d1b7ac02c5915
            entity_id: c348971f284a1488f429242ac2e4eb4b
            domain: switch
        sequence:
          - service: telegram_bot.send_message
            metadata: {}
            data:
              message: Un mouvement a été détecté dehors.
              title: Alerte mouvement extérieur!
      - conditions:
          - type: is_open
            condition: device
            device_id: db00d9e1535e6533dade812e8e0e2bc1
            entity_id: d13149d5c0a13d70ff1b34d07bc1c38d
            domain: binary_sensor
        sequence:
          - service: telegram_bot.send_message
            metadata: {}
            data:
              message: La baie vitrée a été ouverte.
              title: Alerte baie vitrée ouverte!
mode: single

Maybe something better is also possible.

Thanks.

service: automation.turn_off
target:
  entity_id: automation.your_automation
data:
  stop_actions: true

There is also the corresponding turn_on and toggle

I use the alert platform. It has better flexibility.

Here’s an example

This has an input boolean to enable / disable the alert. It also only fires if the house is alarmed.

input_boolean:
  al_dr_man_door_alert_enable:
    name: dr_man_door alert enable
binary_sensor:
  - platform: template
    sensors:
      al_dr_man_door_alert:
        value_template: '{{ (is_state("binary_sensor.man_door_open","on") and is_state("binary_sensor.aw_alarm_enable","on")) and is_state("input_boolean.al_dr_man_door_alert_enable", "on") }}'
alert:
  al_dr_man_door:
    name: dr_man_door
    message: 'ALERT {{state_attr("zone.home","friendly_name")}} dr_man_door door opened'
    done_message: 'Cleared {{state_attr("zone.home","friendly_name")}} dr_man_door door opened'
    entity_id: binary_sensor.al_dr_man_door_alert
    state: "on"
    repeat:
      - 60
      - 240
    can_acknowledge: true
    skip_first: false
    notifiers:
      - sms_telegram_admin
recorder:
1 Like

Thanks for yours answers.
Don’t know where to put code.
My button card is like:

show_name: true
show_icon: true
type: button
tap_action:
  action: toggle
entity:

Where and how to put :

service: automation.turn_off
target:
  entity_id: automation.your_automation
data:
  stop_actions: true

Or

input_boolean:
  al_dr_man_door_alert_enable:
    name: dr_man_door alert enable
binary_sensor:
  - platform: template
    sensors:
      al_dr_man_door_alert:
        value_template: '{{ (is_state("binary_sensor.man_door_open","on") and is_state("binary_sensor.aw_alarm_enable","on")) and is_state("input_boolean.al_dr_man_door_alert_enable", "on") }}'
alert:
  al_dr_man_door:
    name: dr_man_door
    message: 'ALERT {{state_attr("zone.home","friendly_name")}} dr_man_door door opened'
    done_message: 'Cleared {{state_attr("zone.home","friendly_name")}} dr_man_door door opened'
    entity_id: binary_sensor.al_dr_man_door_alert
    state: "on"
    repeat:
      - 60
      - 240
    can_acknowledge: true
    skip_first: false
    notifiers:
      - sms_telegram_admin
recorder:

Or

trigger:
  - platform: state
    entity_id:
      - binary_sensor.yard_motion_sensor
    to: "on"
condition:
  - condition: state
    entity_id: input_boolean.yard_override
    state: "off"
action:
  - service: light.turn_on
    target:
      entity_id: light.yard

Don’t turn automations on and off, use a condition instead.

Create a Toggle (input_boolean) helper called Alarm Override. Put that in a dashboard so it appears as a switch.

Then add it to your automation. If you are working in YAML, replace the:

condition: []

with

condition:
  - condition: state
    entity_id: input_boolean.alarm_override
    state: "off"

If you are working in the UI, add a condition (“And If” in the English version) like this but with your alarm_override helper:

1 Like

I’m adding the slider :

type: custom:slider-button-card
entity: input_boolean.alarm_override
name: Alarme
slider:
  direction: left-right
  background: gradient
  use_state_color: true
  use_percentage_bg_opacity: false
  show_track: false
  toggle_on_click: true
  force_square: false
  show_attribute: false
show_name: true
show_state: true
compact: false
icon:
  show: true
  use_state_color: true
  tap_action:
    action: more-info
action_button:
  mode: toggle
  icon: mdi:power
  show: true
  show_spinner: true
  tap_action:
    action: toggle

And my automations

alias: Alarm
description: Alarme
trigger:
  - platform: device
    device_id: 149b2799b5d82a300c5601165b9a2ce3
    domain: select
    entity_id: ce1d019c9d7a9853ebc8a197baf214c8
    type: current_option_changed
    from: Not Recording
    to: Motion Record
  - platform: device
    type: changed_states
    device_id: 6f103c1b1a43d909ba4d1b7ac02c5915
    entity_id: c348971f284a1488f429242ac2e4eb4b
    domain: switch
  - type: opened
    platform: device
    device_id: db00d9e1535e6533dade812e8e0e2bc1
    entity_id: d13149d5c0a13d70ff1b34d07bc1c38d
    domain: binary_sensor
condition:
  - condition: state
    entity_id: input_boolean.alarm_override
    state: "off"
action:
  - choose:
      - conditions:
          - condition: device
            device_id: 149b2799b5d82a300c5601165b9a2ce3
            domain: select
            entity_id: ce1d019c9d7a9853ebc8a197baf214c8
            type: selected_option
            option: Motion Record
        sequence:
          - service: telegram_bot.send_message
            metadata: {}
            data:
              message: Un mouvement a été détecté sur la caméra intérieure.
              title: Alerte mouvement intérieur!
      - conditions:
          - condition: device
            type: is_on
            device_id: 6f103c1b1a43d909ba4d1b7ac02c5915
            entity_id: c348971f284a1488f429242ac2e4eb4b
            domain: switch
        sequence:
          - service: telegram_bot.send_message
            metadata: {}
            data:
              message: Un mouvement a été détecté dehors.
              title: Alerte mouvement extérieur!
      - conditions:
          - type: is_open
            condition: device
            device_id: db00d9e1535e6533dade812e8e0e2bc1
            entity_id: d13149d5c0a13d70ff1b34d07bc1c38d
            domain: binary_sensor
        sequence:
          - service: telegram_bot.send_message
            metadata: {}
            data:
              message: La baie vitrée a été ouverte.
              title: Alerte baie vitrée ouverte!
mode: single

But slider is on or off, I’m always receiving notifications.

Then either your card is not changing the slider properly, or you’ve not re-loaded the automations. If that input boolean is on, the action block will not be reached when the automation is triggered.

If you run the automation manually (rather than by a trigger) then only the action section is executed. That is expected behaviour.

Is it always better to use a condition instead of disabling an Automation? So for example of you have a summer and winter automation check on summer/ winter to determine which should run?

There might be edge cases, but I would do it that way, yes. It’s more elegant and less confusing.

Thanks :slight_smile:

Here my button code :

type: custom:slider-button-card
entity: input_boolean.alarm_override
name: Alarme
slider:
  direction: left-right
  background: gradient
  use_state_color: true
  use_percentage_bg_opacity: false
  show_track: false
  toggle_on_click: true
  force_square: false
  show_attribute: false
show_name: true
show_state: true
compact: false
icon:
  show: true
  use_state_color: true
  tap_action:
    action: more-info
action_button:
  mode: toggle
  icon: mdi:power
  show: true
  show_spinner: true
  tap_action:
    action: toggle

And my alarm automation :

alias: Alarm
description: Alarme
trigger:
  - platform: device
    device_id: 149b2799b5d82a300c5601165b9a2ce3
    domain: select
    entity_id: ce1d019c9d7a9853ebc8a197baf214c8
    type: current_option_changed
    from: Not Recording
    to: Motion Record
  - platform: device
    type: turned_on
    device_id: 6f103c1b1a43d909ba4d1b7ac02c5915
    entity_id: d7da3ff4c10714c4dd42650161ff93d2
    domain: switch
  - type: opened
    platform: device
    device_id: db00d9e1535e6533dade812e8e0e2bc1
    entity_id: d13149d5c0a13d70ff1b34d07bc1c38d
    domain: binary_sensor
condition:
  - condition: state
    entity_id: input_boolean.alarm_override
    state: "on"
action:
  - choose:
      - conditions:
          - condition: device
            device_id: 149b2799b5d82a300c5601165b9a2ce3
            domain: select
            entity_id: ce1d019c9d7a9853ebc8a197baf214c8
            type: selected_option
            option: Motion Record
        sequence:
          - service: telegram_bot.send_message
            metadata: {}
            data:
              message: Un mouvement a été détecté sur la caméra intérieure.
              title: Alerte mouvement intérieur!
      - conditions:
          - condition: device
            type: is_on
            device_id: 6f103c1b1a43d909ba4d1b7ac02c5915
            entity_id: c348971f284a1488f429242ac2e4eb4b
            domain: switch
        sequence:
          - service: telegram_bot.send_message
            metadata: {}
            data:
              message: Un mouvement a été détecté dehors.
              title: Alerte mouvement extérieur!
              photo:
                file: >-
                  /api/camera_proxy/camera.r4252_smart_outdoor_camera?token=93d768ac5b2bdbe75d3754e1267043cddabff79db77a93f97eb9036c4b6b0149
                caption: Photo
      - conditions:
          - type: is_open
            condition: device
            device_id: db00d9e1535e6533dade812e8e0e2bc1
            entity_id: d13149d5c0a13d70ff1b34d07bc1c38d
            domain: binary_sensor
        sequence:
          - service: telegram_bot.send_message
            metadata: {}
            data:
              message: La baie vitrée a été ouverte.
              title: Alerte baie vitrée ouverte!
mode: single

Now, need to test if the three trigger work well (when motion is detected on camera 1, or when motion is detected on camera 2, or when window is open).

And after that, to succeed install and configure frigate to capture camera picture and send to telegram.

Thanks.