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:
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.
Automation D will often not fire at all - even though the MQTT console is showing every button press.
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:
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?
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:
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)
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.