ESP32 PIR False Positiv

Hi there,

I’m desperate! Since weeks I’m trying to get an HC-SR501 to work on an ESP32and this is not my first ESPHome project.
But I’m getting still a lot of false triggers when nobody is in the room, no sunlight, no heating. Even with capacitors, ferrits and so on. Also the sensor is far away from the ESP32.
I tried the posted code here and my problem now is, that I do not get any status from “Landing PIR 1” into my Home assistant.
I tried already renaming, rebooting, ESPHome restart, Home Assistant restart but nothing helped.
I can see the “Sending state ON” or “Sending state OFF” in the WEB UI or in the logging, but not in HA.
I also set the “internal: true” to “Internal: false” but no…

This is a code which I found in the forum here:

globals:
  - id: pir_trigger_count
    type: int
    restore_value: no
    initial_value: '0'

binary_sensor:
  - platform: template
    name: "Landing PIR 1"
    device_class: motion
    id: landing_pir_1

  - platform: gpio
    pin: D3
    device_class: motion    
    id: landing_pir_sensor_trigger
    internal: true
    on_multi_click:
    - timing:
      - ON for 0.1s to 5s
      then:
       - lambda: |-
          id(pir_trigger_count) += 1;
          if (id(pir_trigger_count) >= 2) {
            id(landing_pir_1).publish_state(true);
          }             
    - timing:
      - OFF for at least 3s
      then:
       - lambda: |-
          id(pir_trigger_count) = 0;
          id(landing_pir_1).publish_state(false);

Somebody out there can help me please??

Thx,
charly

What you mean with “any status”?
Internal has to be false (or remove it).
Your multiclick has to match your sensor output. What jumper position you have? What delay time you have set (potentiometer)?

Back to your original problem, did you try to reduce the sensitivity (other potentiometer)?

With any status I mean, in HA I don’t get anything, the PIR does not show that it gets triggered:

But in the WEB UI of the sensor I can clearly see, that it is getting triggered. So I sorted out the jumper or poteniometer positions. Internal set to false or removed did also not help.

Then you have some HA problem.

I cant help with the HA part but when i used a single HC-SR501 it gave me a lot of false positives, basically the device is unusable alone(at least for me). To solve this i added a second HC-SR501 and added:

binary_sensor:
  - platform: gpio
    id: pir1
    pin: 13
    name: "PIR1"
    device_class: motion
    internal: true
    filters: 
      - delayed_off: 2s

- platform: gpio
    id: pir2
    pin: 14
    name: "PIR2"
    device_class: motion
    internal: true
    filters: 
      - delayed_off: 2s

- platform: template
    name: "Motion Detected"
    id: motion_detected
    device_class: motion
    #Edit this lambda below to match your stats
    lambda: |-
      return id(pir1).state == "true" && id(pir2).state == "true";
    on_press:
      then:
        ....do your thing...

Many of the PIR sensors ive bought over the years have had as few as 1 dud or defective sensor and sometimes rhere would be several bad ones that acted like thet had a seizure disorder the way they would spaz out off and on 24/7 and simply swapping it out for a different PIR sensor would be completely opposite and that one would work just fine.

If you didnt buy these in a 5 pack or more, then you might want to start doing that in the future. Its not uncommon at all for defective components to come out of China without anyone losing any sleep over silly ideas like having Quality Control in their child operated manufacturing facilities so, bad components are to be expected which is probably why so much comes in 5-10 sensors in 1 order.

Its good to see you not wanting to give up and figure it out but, you never should have had to add all this input filtering and smoothing out if the thing was working as its supposed to and even if you do get it where you want, there’s no guarantee that it will last or wont get worse, since it is messed up from very start.

The other thing worth mentioning is, you should probably go ahead and join everyone else who switched to mmwave sensors that are 10x better than PIR sensors and they dont seem to have so many defective components from whoever makes those.

Take a gander at the documentation for the ld2410 mmwave sensor and see if you can figure out why people have largely moved on from using PIR.