Best way to avoid/filter redundant alerts from triggered sensor

Greetings,

This may be an odd request as I haven’t seen anything similar asked here on the forum. I have an automated front security gate that swings open/closed that I’ve made “smart”. I’ve placed a photoelectric beam sensor to monitor anything (person/vehicle) passing through the front gate entrance. I’ve set up a simple HA Automation to play a wave file when the photo electric beam is triggered. The issue I have is when the gate opens or closes the gate, as it swings it arc, triggers the beam sensor multiple times and , hence, the sound notification multiple times. I’m a complete noob when it comes to Node-Red or HA Automations. My first thought was to change the Automation to Node-Red giving me a more granular control. Then based on the manual trigger of the gate opener and/or the automated time that the gate opens/closes, filter or enforce the sound notification to play only once. I have no idea where to begin or how to go about this or if it’s even possible. Any feedback or direction would be greatly appreciated!

Thanks all

TD

Do you have a flow already?

@sender Thank you for the super fast reply. I do not, at least not in Node-Red. I have a HA Automation to trigger a sound notification when the beam sensor is tripped. And I have a HA Automation to automatically close the gate if open at 7:00PM each night. To be clear, these are in HA, not Node-Red.

TD

So what do you want? Someone else to make it for you? :slight_smile: Or do you want help creating it yourself? Make a start and someone might be able to help…

You can easily do this in node red by e.g. using a “limit node” to limit the sound playing only once during a certain time (gate open/close)

@hackerkatt If you can share what you have as your current automation, someone will help improve it.

For some reason my response to you @sender yesterday failed to deliver.

Address not found

Your message wasn’t delivered to [email protected] because the address couldn’t be found, or is unable to receive mail.

Anyway, here was my response and to @bastero too :slight_smile:

Hey @sender. Nope, don’t want somebody to actually do it for me I want to learn. I’m actually a network engineer and have done a fair amount of software development but just have no experience with Node-Red. I’m not familiar with its elements. So I was looking for some direction and pointers. But your suggestion gives me a start and that’s what I was looking for. I’ll play around with it using that limit element and see where that takes me if I have any other questions I’ll be sure to ask the experts here at home assistant forum. To be clear, if the sound notification is triggered by the tripped sensor the limit will be aware of the previous trigger, seconds/milliseconds, and not sound it again?

@bastero, awesome! It’s my objective to gain a good working knowledge of Node-Red, and I need to start somewhere. I don’t think it has any bearing on the objective, but I’ve got a raspberry pi with VLC player dedicated to receive HTTP requests to play audio. I didn’t find any real happy users of the various plugins available so I’m utilizing, at least for the time being, the shell_command function in HA to make requests.

Thanks again!

My relative config snippets…

ESPHome

binary_sensor:
# GATE STATUS
# PhotoElectic Beam Sensor
# Seco PN# E-931-S35RRQ
#   - BLACK Wire - Normally Open - is an OPEN circuit which closes when the beam is broken
#   - WHITE Wire - Comm
  - platform: gpio
    pin:
      number: 27
      mode: INPUT_PULLUP  # Will go LOW when the beam is broken and circuit is closed
      inverted: True
    id: gate_secure_sensor
    name: "Gate Status"
    device_class: opening

# GATE PERIMETER    
# PhotoElectic Beam Sensor
# Seco PN# E-931-S35RRQ
#   - BLACK Wire - Normally Open - is an OPEN circuit which closes when the beam is broken
#   - WHITE Wire - Comm
  - platform: gpio
    pin:
      number: 14
      mode: INPUT_PULLUP  # Will go LOW when the beam is broken and circuit is closed
      inverted: True
    id: gate_laser_sensor
    name: "Laser Sensor"
    device_class: motion

automations.yaml

id: '1603589077467'
  alias: Sound Notice Front Gate Motion
  description: 'Trigger VLC Player to Play Sound'
  trigger:
  - device_id: bad3175ee4144c7a978978cdfcb5a144
    domain: binary_sensor
    entity_id: binary_sensor.laser_sensor
    platform: device
    type: motion
  condition: []
  action:
  - data: {}
    service: shell_command.door_open_audio
  mode: single

@hackerkatt Sounds like you have a bounce issue with your sensor signal that is probably best to mitigate within the ESPHome code, with inserting either debounce or filtering (delta) parameters.

https://esphome.io/components/sensor/index.html#throttle-heartbeat-debounce-delta

@bastero Interesting, thank you… Looking at the ESPHome doc it states that

… You define them by adding a filters block in the sensor configuration (at the same level as platform ; or inside each sensor block for platforms with multiple sensors)

So in my case with multiple binary_sensors and wishing to apply the filter(s) to one sensor, I’ve applied to following config as I understand it’s placement withing the sensor block. When I validate it fails. I’m missing something, not sure what that is. I’ve moved the filter block up under the binary_sensor base, which would apply to all the subsequent sensor blocks to test, although that’s not how I would like to have the filters applied. In both cases the validation fails.

Validation fails

INFO Reading configuration /config/esphome/frontgate.yaml...
INFO Detected timezone 'MST' with UTC offset -7
Failed config

binary_sensor.gpio: [source /config/esphome/frontgate.yaml:56]
  platform: gpio
  pin: 
    number: 14
    mode: INPUT_PULLUP
    inverted: True
  id: gate_laser_sensor
  name: Laser Sensor
  device_class: motion
  filters: 
    - [source /config/esphome/frontgate.yaml:65]
      
      Unable to find filter with the name 'throttle'.
      throttle: 1s [source /config/esphome/frontgate.yaml:65]
    - [source /config/esphome/frontgate.yaml:66]
      
      Unable to find filter with the name 'debounce'.
      debounce: 0.9s [source /config/esphome/frontgate.yaml:66]

ESPHome config

binary_sensor:
# GATE STATUS
# PhotoElectic Beam Sensor
# Seco PN# E-931-S35RRQ
#   - BLACK Wire - Normally Open - is an OPEN circuit which closes when the beam is broken
#   - WHITE Wire - Comm
  - platform: gpio
    pin:
      number: 27
      mode: INPUT_PULLUP  # Will go LOW when the beam is broken and circuit is closed
      inverted: True
    id: gate_secure_sensor
    name: "Gate Status"
    device_class: opening
      
# GATE PERIMETER    
# PhotoElectic Beam Sensor
# Seco PN# E-931-S35RRQ
#   - BLACK Wire - Normally Open - is an OPEN circuit which closes when the beam is broken
#   - WHITE Wire - Comm
  - platform: gpio
    pin:
      number: 14
      mode: INPUT_PULLUP  # Will go LOW when the beam is broken and circuit is closed
      inverted: True
    id: gate_laser_sensor
    name: "Laser Sensor"
    device_class: motion
    filters:
      - throttle: 1s
      - debounce: 0.9s

Try this alignment:

      filters:
        - throttle: 1s
        - debounce: 0.9s

I think that’s how I have it formatted. Looking at your copy/paste snippet of my filters, the dash ‘-’ shows I would have it aligned up under with the ‘s’ of the filters: statement. But I do have the dash ‘-’ aligned with the “l” (ell) in filters. I also tried locating the filters block right up under the - platform statement.

@hackerkatt The following validates for me

binary_sensor:
 - platform: status
   name: "Dry Vibration"
 - platform: gpio
   pin: GPIO13
   name: "dryer"
   device_class: vibration
   filters:
   - delayed_on: 10ms
   - delayed_off: 2min

Hmmm, interesting… You’ve got a single space with the “- platform” entry on the definition of the block. YAML is a standard of two spaces identifying each parent/child. I moved the throttle and debounce statements to to be inline with the filter statement as in your example, it still failed validation. I then moved all of my “- platform” and children back one space to match that of your example. I then got a failure on the YAML formatting of the entire structure. I attached a screenshot of the actual code editor so you can see how it looks. Without the filter statement, the code validates.

binary_sensor:
  - platform: gpio
    pin:
      number: 14
      mode: INPUT_PULLUP
      inverted: True
    id: gate_laser_sensor
    name: "Laser Sensor"
    device_class: motion
    filters:
    - throttle: 1s
    - debounce: 0.9s
binary_sensor.gpio: [source /config/esphome/frontgate.yaml:56]
  platform: gpio
  pin: 
    number: 14
    mode: INPUT_PULLUP
    inverted: True
  id: gate_laser_sensor
  name: Laser Sensor
  device_class: motion
  filters: 
    - [source /config/esphome/frontgate.yaml:65]
      
      Unable to find filter with the name 'throttle'.
      throttle: 1s [source /config/esphome/frontgate.yaml:65]
    - [source /config/esphome/frontgate.yaml:66]
      
      Unable to find filter with the name 'debounce'.
      debounce: 0.9s [source /config/esphome/frontgate.yaml:66]

Selection_180

I found that I seem to only be able to use the specific filters associated with the binary_sensor as documented here (https://esphome.io/components/binary_sensor/index.html). But if I understand what the doc states, I should be able to use the debounce and throttle filters as they are supported sensor filters. And you are able to validate according to your binary_sensor. So I am at a loss as to why my code/code editor considers them invalid filters.

@hackerkatt the more I look at the documentation the more it seems that the debounce and throttle filters are only to be used with ‘sensor:’ component and the ‘delayed_on’ & ‘delayed_off’ are filters only to be used with the ‘binary_sensor:’ component. It may be worth trying the delayed_on /off filters in your application?

As you can see my yaml code is being validated correctly…

@bastero That’s the conclusion I came too as well. I will experiment with those options. Thanks again for your for help and persistence!

Tony

If you didn’t get any further with the debounce issue you could always use an automation to set the state of an Input Boolean to ON if the Gate is opening and sound file has started, or OFF if the gate is closed and then use the same Input Boolean to only trigger the sound notification if it is set to OFF.
i.e in either node red or HA Automation you can have 2 automations with the following logic:-

Laser Sensor Triggered --> Open Gate–> Check state of Input Boolean is OFF --> Set Input Boolean to ON --> Play Sound File

Gate Closed --> Set Input Boolean to OFF

Input Boolean Docs --> https://www.home-assistant.io/integrations/input_boolean/

1 Like

Thank you @jamos, I haven’t had much success with the filters. We found that debounce and throttle were not valid filters for the binary_sensor:, they are only valid on a sensor:

I tried the delayed_on filter for the binary_sensor with no success. I’m not yet familiar with Node-Red but understand that it would give me much more control and granularity to an automation.

If you get the node red addon installed then import flow below and it may help you get started with this. Although I have never used a shell command before so I can’t test if this will work. This example also uses the Rate Limit in the Delay node (suggested by one of the other replies) so you will need to adjust it’s reset time according to how long the gate causes the debounce when opening and closing.

If you have a sensor to check if the state of the gate is open or closed then the input boolean method may work better.

[{"id":"2845537e.235364","type":"api-call-service","z":"ff9644ac.164fe","name":"","server":"57ce5691.fd6e48","version":1,"debugenabled":false,"service_domain":"shell_command","service":"door_open_audio","entityId":"","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":490,"y":740,"wires":[["9d8f336c.b881c8"]]},{"id":"4d6422ec.5a3314","type":"inject","z":"ff9644ac.164fe","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":260,"y":740,"wires":[["2845537e.235364"]]},{"id":"216254b1.08dd04","type":"delay","z":"ff9644ac.164fe","name":"","pauseType":"rate","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"10","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":true,"x":440,"y":500,"wires":[["391f9023.a143c8"]]},{"id":"e18b7f16.692818","type":"inject","z":"ff9644ac.164fe","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":260,"y":500,"wires":[["216254b1.08dd04"]]},{"id":"9d8f336c.b881c8","type":"debug","z":"ff9644ac.164fe","name":"DEBUG: Example: Audio SHELL Command","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":830,"y":740,"wires":[]},{"id":"391f9023.a143c8","type":"debug","z":"ff9644ac.164fe","name":"DEBUG: Example Rate Limit","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":680,"y":500,"wires":[]},{"id":"5c4ac151.7fc8","type":"comment","z":"ff9644ac.164fe","name":"Example: Service Node - Play Door Open Sound","info":"","x":360,"y":700,"wires":[]},{"id":"3c915be3.67303c","type":"comment","z":"ff9644ac.164fe","name":"Example: Delay -Node - Limit to 1 msg per 10 seconds - Change this value","info":"","x":440,"y":460,"wires":[]},{"id":"d0a6f578.68079","type":"server-state-changed","z":"ff9644ac.164fe","name":"Laser Sensor State","server":"57ce5691.fd6e48","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"binary_sensor.laser_sensor","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"on","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"for":0,"forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"x":270,"y":620,"wires":[["2b1197e1.bca93"],["a44ef82e.c6a678"]]},{"id":"2b1197e1.bca93","type":"debug","z":"ff9644ac.164fe","name":"DEBUG: Example Laser Trigger ON","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":790,"y":600,"wires":[]},{"id":"a44ef82e.c6a678","type":"debug","z":"ff9644ac.164fe","name":"DEBUG: Example Laser Trigger OFF","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":790,"y":640,"wires":[]},{"id":"ab7bcd9c.a57858","type":"comment","z":"ff9644ac.164fe","name":"Example: Event State Listening to If Sensor is on or off","info":"","x":380,"y":580,"wires":[]},{"id":"41505b53.1638fc","type":"server-state-changed","z":"ff9644ac.164fe","name":"Laser Sensor State","server":"57ce5691.fd6e48","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"binary_sensor.laser_sensor","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"on","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"for":0,"forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"x":270,"y":880,"wires":[["5e277d7.90ee704","3651edf2.a6a4ca"],[]]},{"id":"5e277d7.90ee704","type":"delay","z":"ff9644ac.164fe","name":"","pauseType":"rate","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"10","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":true,"x":500,"y":880,"wires":[["4b885084.4905a8","8aaec727.f5894"]]},{"id":"4b885084.4905a8","type":"api-call-service","z":"ff9644ac.164fe","name":"","server":"57ce5691.fd6e48","version":1,"debugenabled":false,"service_domain":"shell_command","service":"door_open_audio","entityId":"","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":810,"y":880,"wires":[["63b52fec.5a8258"]]},{"id":"3651edf2.a6a4ca","type":"debug","z":"ff9644ac.164fe","name":"DEBUG: Laser Trigger ON","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":640,"y":960,"wires":[]},{"id":"8aaec727.f5894","type":"debug","z":"ff9644ac.164fe","name":"DEBUG: Rate Limit","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":890,"y":940,"wires":[]},{"id":"63b52fec.5a8258","type":"debug","z":"ff9644ac.164fe","name":"DEBUG: Audio SHELL Command","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1120,"y":880,"wires":[]},{"id":"c6530ea2.b5e4f","type":"comment","z":"ff9644ac.164fe","name":"Put it All together","info":"--If Laser Sensor State is on (i.e triggered)\n--Then only allow 1st message and drop subsequent messages  for the first 10 seconds\n--Play Sound","x":260,"y":840,"wires":[]},{"id":"57ce5691.fd6e48","type":"server","name":"Home Assistant","addon":true}]