Binary sensor, automation triggers false positive

I have Ikea Vindriktning with ESP air particle sensor. It sends data about every 30 seconds. Some times the sensor goes high without a good reason, and after 30 seconds everything is fine again. I have made an automation which triggers an alarm if the sensed particle level is above certain level for over 90 seconds. But it still triggers even the sensed level were over the level only for 30 seconds.

How should I improve this to prevent false positive alarms?

configuration.yaml:

template:
  - binary_sensor:
      - name: "DownstairsSMOKE"
        state: "{{ states('sensor.vindriktning_97d9b7_pm_2_5')|float(0) > 60 }}"
automation:
- id: '23423422122225112266'
  alias: Telegram SMOKE at downstairs pm25
  description: ''
  trigger:
  - platform: state
    entity_id:
    - binary_sensor.downstairssmoke
    for:
      hours: 0
      minutes: 1
      seconds: 30
  condition: []
  action:
  - service: telegram_bot.send_message
    data:
      message: Downstairs SMOKE pm25
  - if:
    - condition: state
      entity_id: input_boolean.gsm_button
      state: 'on'
    then:
    - service: mqtt.publish
      data:
        qos: '1'
        topic: GSMalert
        payload: a
  mode: single

Näyttökuva 2023-04-23 124537

Your trigger doesn’t seem to be testing for a particular state, so it will fire every time the sensor sends data. Will the “for” bit will work in this case?

You need to add a state to the trigger like ‘on’

At present as you have no ‘to’ or ‘from’ in the trigger so it will trigger every time the binary sensor changes and stays in the same state for more than 1 min 30 sec regardless.

So at current it could technically go to state:
on, off, unknown, unavailable
And if it stays in this state for over 1 min 30 sec your automation will trigger.

Try changing your trigger to include the actual state you want, in this case ‘on’

  - platform: state
    entity_id:
      - binary_sensor.downstairssmoke
    to: "on"
    for:
      hours: 0
      minutes: 1
      seconds: 30

you have invalid quote characters in there.

My bad, didn’t spot that - thanks :+1:

“Now corrected in original post”

Heh, your edit is still invalid quotes. they should look like this " or ' not or

I have no idea why that is happening, Something funky happening in the editor via an ipad and attached keyboard and no matter what I try I cannot get them to format correctly.

It should be correct now as I ended up having to type it else where and cut and paste.

When using iPad, you have to hold the quote button until quote options appear and then choose the appropriate quote. Otherwise it defaults to a quote that is not compatible with yaml.

1 Like

Thank you rossk! :hugs:

1 Like