Trigger delay on binary sensors and Alarmo - false alarms - urgent request

I have a real-life, and unfortunately, urgent problem I need help with. The sleepy little town in South Africa I live in has been discovered by criminal elements, and burglaries have taken place with regular frequency for the last few months. This has unfortunately now escalated to murder, as one of our residents was murdered during one such burglary on Sunday. I was very fortunate, as the culprits were actually on my back wall, but for random reason decided to pick another house.

Screenshot 2024-03-13 at 10.32.16

Screenshot 2024-03-13 at 10.32.29

I use Alarmo to monitor my house, and so far Home Assistant and this brilliant add-on has been fantastic. Well done to the many talented and amazing contributors.

One of the areas that I need help with though, is my external perimiter security and the associated devices / programming. Amongst other security measures, I built beams that covers my perimiter, using gate closure beams (laser), ESP8266 boards and Tasmota firmware, bringing in all the data through MQTT to Home Assistant.

The triggers work brilliant, the data is immediate, Alarmo triggers on que. However, due to factors I am unable to determine, I get some false alarms on these beams regularly. These can be as often as once or twice a night, or as infrequent as once a week. Checking video footage of the areas does not show anything physical. So, the family (and neighbours) are complaining of not being able to sleep, and being nervous wrecks. You also have the possibility of “Crying Wolf” too often, whereby the alarm will just be ignored by everyone. As such, these beams are currently excluded from the Alarm system.

I have replaced the sensors with more expensive sensors, tried different boards, power stabilisation, etc, but still the occasional false alarm comes through (I typically try to fix hardware - my nature I suppose). What I have seen though, is that these false triggers (when they trigger), have a duration of less than a second. So, this morning I decided to reach out to the community to see if someone can give me advice or more (Like I said, I am a hardware guy, not at all good with any programming etc), to solve this.

My thinking is that if this tirgger has to be active for more than X (seconds / milliseconds) before it actually triggers the alarm. Unless these criminals are superfast, they will not clear the walls in under 1 second. Logic would dictate there are several places where this can be achieved (and this is where I need help)

  1. Alarmo: If there was an option in Alarmo for example a field called “Trigger Duration” or similar. not only I, but other other users could for instance prevent a lot of false alarms due to a gust of wind triggering a PIR, or similar. So, a sensor can either be “immediate” or has to be in a certain state for eg. (1.5 seconds), upon which it will trigger the alarm
  2. Automation: This gets a bit more complex (for me with my skills at least), but my thinking is to have a “dummy” sensor. The automation set it for instance “active” once the actual sensor has been active for 1.5 seconds (not after 1.5 seconds of going active [and back to inactive], but after being actually active for 1.5 seconds) , and “inactive” once the sensor has been inactive for 1.5 seconds. The “dummy” sensor then gets used in Alarmo to trigger the alarm. I have no idea where to start though to set up such a dummy sensor, and make sure it is the right class to be used in Alarmo.
  3. Tasmota / MQTT: I suppose it is in theory possible for either the board running Tasmota, or MQTT not to pass the “trigger” through to Home Assistant and Alarmo unless the trigger is active for X milliseconds, but frankly, as I said my programming skills are close to zero, I would not even have an idea where to start.

Apologies for the long post, but I am in dire straights, and unfortuantely work as an expat in another country, so not physically present to change hardware at the moment. Also, apologies if I use wrong terminology, but like I said, I have very little (no, basically none at all) programming experience.

I have been through the forums to see if something like this has been done, but could only see slightly related topics, but none which would help me figure this out.

Thank you in advance.

I seem to have a temporary fix for the time being.

It is not ideal from a complexity level, but initial testing so far shows success.

Tasmota supports Rules, so using the Rules System, I created the following Rule

Rule1 ON POWER1#state=1 DO RuleTimer1 1 ENDON ON POWER1#state=0 DO RuleTimer1 0 ENDON ON POWER1#state=0 DO RuleTimer2 1 ENDON ON Rules#Timer=1 DO backlog publish homeassistant/stat/tasmota_beams2/POWER1DELAYED AAN ENDON ON Rules#Timer=2 DO publish homeassistant/stat/tasmota_beams2/POWER1DELAYED AF ENDON

I then created an additional binary sensor in configuration.yaml as follows:
(The first one is the original sensor, which I am keeping for the time being.
The second entry is the additional sensor - which now has a 1 second time delay before triggering).
I removed the initial sensor from Alarmo, and added the newly created sensor (bottom entry below) to Alarmo.

mqtt:

  - binary_sensor:
      state_topic: "homeassistant/stat/tasmota_beams2/POWER1"
      name: "Bert&Carol Beam Break"
      payload_on: "ON"
      payload_off: "OFF"
      qos: 0
      device_class: motion
      availability_topic: "homeassistant/tele/tasmota_beams2/LWT"
      payload_available: "Online"
      payload_not_available: "Offline"

  - binary_sensor:
      state_topic: "homeassistant/stat/tasmota_beams2/POWER1DELAYED"
      name: "Bert&Carol Beam Break Delayed"
      payload_on: "AAN"
      payload_off: "AF"
      qos: 0
      device_class: motion
      availability_topic: "homeassistant/tele/tasmota_beams2/LWT"
      payload_available: "Online"
      payload_not_available: "Offline"

i’m not sure if i totally get it. are you just asking how you can trigger the alarm/notification only if motion is detected for an extended duration?

i don’t see a way to do it in mqtt (but someone else may know, not claiming you can’t). but you can do it in the automation. just add a for section. here’s an example:

description: ""
mode: single
trigger:
  - platform: state
    entity_id:
      - binary_sensor.motion_detected
    for:
      seconds: 5
condition: []
action:
  - service: notify.sound_the_alarm

Hi Armedad.

What the Tasmota Code does is it waits for one second before publishing a specific message to MQTT. If the sensor goes inactive before that one second has passed, it effectively cancels publishing the “delayed” message. It is not ideal (messy like I said), but testing shows it works so far. Live testing will be done tonight.

Regarding your suggestion, yes, if I was doing my whole alarm using a lot of differnt automations, I suppose I could use your method, but since I am just integrating sensors into the Alarmo integration, the option to do a “for” in an automation is not there. I did reach out to the creator of the Alarmo integration, as I think such an option in Alarmo would make a lot of sense to reduce potential false alarms for movement sensors.

I suppose a similar method to what you say would be (related to option 2 I mentioned above), but I have no Idea how to create a “blank” binary motion sensor, which state can be controlled by an automation (Then your solution would be spot on). I found some things related to “switch sensors” that looks promising, but as I am pressed for time, I focussed on the Tasmota Rule coding.

If the Tasmota coding works, then the pressure is reduced and I can take more time to do some research and try to come up with a more elegant and easy solution that can be controlled by HA.

You can create a binary template sensor, which would copy the state of a beam break sensor but delay the ‘on’ state until the beam sensor remains broken for a specified amount of time.

This code would go in your configuration.yaml (unless you’ve customized your installation to place it elsewhere)

template:
  - binary_sensor:
      - name: "Beam Break Delayed On"
        delay_on:
          seconds: 2
        state: >
          {{ states('binary_sensor.my_beam_break_sensor') }}

you said you can’t do this in the automation? i’m not sure i understand. what’s listening to your sensor? isn’t there an automation that’s listening to the sensor and then reacting when the motion is detected?

if you need to do it via wrapping a sensor, we just had this on another thread. @tom_l provided this solution below:

template:
  - binary_sensor:
      - name: Debounced
        state: >
          {% if has_value('binary_sensor.some_data') %}
            {{ states('binary_sensor.some_data')|bool }}"
          {% else %}
            {{ this.state }}
          {% endif %}
        delay_on: 2

Fantastic - Thanks a lot.

If I had this earlier today I could have saved quite a bit of research time into Tasmota Rules :wink: . But, anything learned is not a waste…

I will try this on one of the other (non-Tasmota) motion sensors.

Excellent - fantastic to see such amazing participlation.

just saw @mekaneck posted a similar suggestion as i was typing. the has_value part that’s the substantative difference between ours is to handle the state if the motion detector returns unavailable temporarily… as some hardware sensors do here and there.

Thanks a lot.

I will try both solutions and update in case of any issues.

Just a follow-up question…

Can the delay function only use integer (whole) numbers, or is it possible for instance to specify a value like 1.5s?

good question. i don’t see it specified in the docs, but i just tried it and it looks to me like it works. but you should test it to make sure.

I will try. Thanks

I can report that both the methods proposed by armedad and mekaneck works.

Easier to implement than the Tasmota method, much cleaner solution, but however requires a restart of HA when changing the delay in yaml (small price to pay for this great functionality). As such, I will try the non-integer delays tomorrow.

the delay_on (or delay_off) variables accept a number of different formats. I can’t tell you if non-integer values are accepted but you should be able to use the millisecond key to define an integer number of milliseconds. The options are documented here. And yes I realize you are not creating a script or specifying a delay, but that just happens to be the only place the options for things like this are documented.

        delay_on:
          seconds: 1
          milliseconds: 500

One more comment: you don’t need to restart HA after modifying your code. Instead, go to developer tools → YAML → scroll down to find TEMPLATE ENTITIES and click that.

Doing that will reload the YAML code that falls under the template: heading.

Thanks Mekaneck. I will try.

Just some feedback…

The system worked as expected, and no false alarms last night, while giving the protection I expected.

To the whole community, you are heroes!!!

2 Likes

glad it works… cool that home assistant is helping keep the neighborhood safer!