PIR with "multi-click" publishing?

Hi,

i have a esphome node (esp8266) with a pir attached. This pir brings lots of false positives, but I found out that false motions are always very fast and motion goes back to no within half a second. when real motion is detected, duration is more than a second.
so I thouhgt, I could do something like this, so there is only a publish if the duration is more than half a second:

binary_sensor:
  - platform: gpio
    pin: D3
    name: gang_sz_PIR
    device_class: motion
    #state_topic: gang_sz/motion
    on_multi_click:
    - timing:
      - ON for at least 0.5s
      then:
        - logger.log: "PIR on"
        - mqtt.publish:
            topic: gang_sz/motion
            payload: "on"
        - lambda: !lambda |-
            return "on";

However. Coming from fhem, I am pretty new to HA. Have been using esphome for two years or something, but using mqtt only.
Now I have two questions regarding publish:

  1. how can I let the node publish a “motion” directly to HA using the API? The “return ‘on’” does not seem to change the value of the entity in HA. What is wrong here?

  2. also using an mqtt switch and using a “motion activated light” does not work. seems that “on” is the wrong value here.

It would be very kind, if someone could tell me what I am doing wrong.

Best regards and thanks in advance,
Otto

I think there’s two other approaches you should try first before using your solution.

First of all, try activating internal pull-ups and see if that stops the bouncing. Quite possibly it won’t.

Then use a delay_on filter to debounce the false positives. This should work well and is probably the best way to filter off the false positives.

Using the api is as simple as adding api:

Hi and thanks a lot!

turned out that I could get rid of the false positives by limiting wifi power:

output_power: 10db

Best regards and thanks again,
Otto

1 Like