Problems with Alarm control panel automations

I have defined a number of automations to control a home alarm system.
A. Alarm Triggered - plays a media file (siren) on media players around the house
B. Alarm disarmed - pauses playback on all media players around the house
C. Turn on alarm using 433Mhz remote - Arms the alarm system
D. Turn off alarm using 433Mhz remote - Disarms the alarm system

The problems I am having are:

  1. Automation C will often fire once and once only (it is triggered when I press a button on a Sonoff 433MHz remote). If I press the button a second time the automation is not fired again. I can only get it to fire again if I restart HA. Sometimes I can get it to fire more than once in a short period of time, but often not. I use the MQTT console to check for button presses and every press is being registered.
  2. Automation D will often not fire at all - even though the MQTT console is showing every button press.
  3. When Automation A has been triggered (and the alarm media files are playing), Automation D (when I can actually get it to run) does not pause the media playback on the media players. It should do this by causing Automation B to fire (Automation B pauses media playback). Even if both D and B fire correctly, the media playback continues until I disarm the alarm manually using the Alarm Panel card in Lovelace. The alarm is actually disarmed when I press the button, but the media keeps playing.

Are the triggers or logic that I’m using inherently unreliable, or is there a flaw in the way I have things defined?
Definitions are below:
Automation A:

- alias: Alarm triggered
  trigger:
  - platform: state
    entity_id: alarm_control_panel.home_alarm
    to: triggered
  action:
  - service: media_player.play_media
    target:
      entity_id:
      - media_player.study_speaker_3
      - media_player.lounge_speaker
      - media_player.kitchen_speaker_3
    data:
      media_content_id: http://www.mydomain.com/countdown15s_alarm2m.mp3
      media_content_type: audio/mp3
  - service: input_boolean.turn_on
    data:
      entity_id:
      - input_boolean.alarm_triggered
  id: 387f56544fdd401e9178511f50f7f38b

Automation B:

- alias: Alarm disarmed
  trigger:
  - platform: state
    entity_id: alarm_control_panel.home_alarm
    to: disarmed
  action:
  - service: media_player.media_pause
    data:
      entity_id: media_player.study_speaker_3
  - service: media_player.media_pause
    data:
      entity_id: media_player.lounge_speaker
  - service: media_player.media_pause
    data:
      entity_id: media_player.kitchen_speaker_3
  id: 2eb84bc3ca924bada273d0e1f42e103e

Automation C:

- id: '1630948007972'
  alias: Turn on alarm using Sonoff 433MHz remote
  description: ''
  trigger:
  - platform: state
    entity_id: binary_sensor.sonoff_433mhz_remote
    to: 'on'
  condition: []
  action:
  - service: alarm_control_panel.alarm_arm_away
    target:
      entity_id: alarm_control_panel.home_alarm
  mode: single

Automation D:

alias: Turn off alarm using Sonoff 433MHz remote
description: ''
trigger:
  - platform: state
    entity_id: binary_sensor.sonoff_433mhz_remote
    to: 'off'
condition: []
action:
  - service: alarm_control_panel.alarm_disarm
    target:
      entity_id: alarm_control_panel.home_alarm
mode: single

…and here is the binary_sensor I have defined for the 433MHz remote:

binary_sensor:
#Sonoff 433MHz remote button 1 (top left)
  - platform: mqtt
    name: "Sonoff 433MHz Remote"
    state_topic: "tele/rf-bridge/RESULT"
    value_template: '{{value_json.RfReceived.Data}}'
    payload_on: "773B78"
    payload_off: "773B7C"
    qos: 1

The behavior you described for automations C and D would be consistent with a binary_sensor that changes to on but never returns to off (unless you restart Home Assistant or Reload MQTT Entities).

Double check the configuration and operation of the binary_sensor.

Would the solution be to set an off_delay of say 30 (seconds) for the binary sensors?
While that would explain not being able to re-trigger those automations, I’m not sure it explains why Automation C doesn’t stop the media playback when it triggers automation B?

Why not simply correct the binary_sensor’s existing configuration? You supplied the following:

payload_off: "773B7C"

It doesn’t appear to be receiving that value because if it were then it would be setting the binary_sensor to off. Fix this first.

TBH I’m wondering whether I should be defining this as a Switch, rather than a binary sensor? Would a switch allow me to trigger it repeatedly, without regard for its current state?

I tried exploring a Switch entity as an alternative but couldn’t work it out, so have reverted back to a binary sensor.
If I understand you correctly, my automation is perhaps not being triggered because it must first be in the “off” state in order to register a change to the “on” state. Part of the issue here is that there are several ways that my alarm can be armed or disarmed. The default is that it is armed when the last person leaves the house, and disarmed when the first person arrives home. The Sonoff switch is intended as an override for situations such as:failure of the associated geolocation functions: e.g.

  • alarm triggered even though someone is at home
  • alarm not armed even though nobody is at home.
    There are other override options too: e.g. using the Home Assistant app or web console to turn the alarm on or off.

So each press of the “on” button may not necessarily be followed by a press on the “off” button. They may be used in any kind of random order. What would be the best way to handle this, so that the “on” automation can be triggered at any time, regardless of its current state?

  • A single button that transmits a command when pressed, and another command when released, can be modeled as a binary_sensor.
  • Even if it doesn’t transmit a command when released (only when pressed) it can still be modeled as a binary_sensor by using the off_delay option.

However, in either case, the binary_sensor can only be used as a trigger to arm your alarm_panel when the button is pressed or to disarm it but not both.

If you have the binary_sensor configured correctly (and I don’t believe you do) then this will work when the button is pressed. It can be used to arm the alarm_panel.

  - platform: state
    entity_id: binary_sensor.sonoff_433mhz_remote
    to: 'on'

However, the following will trigger the moment you release the button (or after off_delay expires). Obviously the same button cannot be used to disarm the alarm_panel.

  - platform: state
    entity_id: binary_sensor.sonoff_433mhz_remote
    to: 'off'

If you don’t want to fix the binary_sensor then don’t create one. Use an MQTT Trigger like this one:

alias: Turn on alarm using Sonoff 433MHz remote
trigger:
  - platform: mqtt
    topic: tele/rf-bridge/RESULT
    payload: '773B78'
action:
  - service: alarm_control_panel.alarm_disarm
    target:
      entity_id: alarm_control_panel.home_alarm

Sorry I think I may not have properly communicated the type of remote control that I am using. It has two separate buttons for on/off. Each transmits a single 433MHz payload when the button is pressed, but nothing when the button is released. So there are two different payloads/codes, one for on, one for off.
I tried an off_delay, but that simply turned off the alarm after the specified interval, which is clearly not what is desired.
Given the above, I have redefined the automation with an MQTT trigger:

alias: Turn on alarm using Sonoff 433MHz remote
description: ''
trigger:
  - platform: mqtt
    topic: tele/rf-bridge/RESULT
    payload: 773B78
condition: []
action:
  - service: alarm_control_panel.alarm_arm_away
    target:
      entity_id: alarm_control_panel.home_alarm
mode: single

…but it doesn’t fire when I press the button
???
(also tried double-quotes around the payload, but it didn’t help)

Then you definitely didn’t model that arrangement properly by using a binary_sensor. Simply use an MQTT Trigger.

That’s due to my mistake. I overlooked to add value_template to the MQTT Trigger.

alias: Turn on alarm using Sonoff 433MHz remote
description: ''
trigger:
  - platform: mqtt
    topic: tele/rf-bridge/RESULT
    payload: '773B78'
    value_template: '{{ value_json.RfReceived.Data }}'
condition: []
action:
  - service: alarm_control_panel.alarm_arm_away
    target:
      entity_id: alarm_control_panel.home_alarm
mode: single

Ah…that’s it…it now seems to work fine.
Many thanks!

1 Like

Glad to hear it.

Please consider marking my post above with the Solution tag (and in the other topic where I helped you recently).

It will automatically place a check-mark next to the topic’s title which signals to other users that this topic is resolved. This helps other users find answers to similar questions. For more information, refer to guideline 21 in the FAQ.