RavenSystem / esp-homekit-devices

Advanced firmware to add native Apple HomeKit and custom configurations, compatible with any SoC based on ESP32, ESP32-S, ESP32-C and ESP8266 series. (Shelly, Sonoff, Electrodragon, Tuya...)
Other
2.71k stars 357 forks source link

Sonoff basic R2 motion sensor #1091

Closed adamgdynia closed 4 years ago

adamgdynia commented 4 years ago

Hello!

I've been reading most of the threads and wiki on how to configure a motion sensor with sonoff basic R2. Till now I can not get it to work properly. What I want to achieve is to get motion sensor turn GPIO12 (relay) on when active, then after 10 seconds turn it off. This is the exact scenario as in wiki (https://github.com/RavenSystem/esp-homekit-devices/wiki/Sensors#example)

I have my PIR (HC-SR501 or HC-SR505 - tested both) connected to RX (GPIO3 on Sonoff basic R2) and my code is:

{
  "c": { "l": 13},
  "a": [{
    "t": 12,
    "i": 10,
    "0": { "r": [{ "g": 12, "v": 0 }] },
    "1": { "r": [{ "g": 12, "v": 1 }] },
    "f1": [{ "g": 3 }]
  }]
}

I don't know what's wrong. PIR is connected to 5V from Sonoff board and data pin in connected to GPIO3 (RX). Today the package with AM312 PIR is arriving and will test it with 3.3V from Sonoff.

Thanks for any help! Adam

vsidlu commented 4 years ago

Hi,

This is my json for motion - sonoff basic.

{"c":{"o":1,"l":13,"i":1,"n":"dresingroom_motion","b":[{"g":0,"t":5}]},"a":[{"t":2,"s":5,"0":{"r":[{"g":12}]},"1":{"r":[{"g":12,"v":1}]},"b":[{"g":0}]},{"t":12,"i":5,"f1":[{"g":14,"p":0,"i":1,"t":0}]}]}

There is t in motion accessory which I can not explain but it helps.

Try this one

adamgdynia commented 4 years ago

Thanks for you json, but it seems it doesn't work... I have modified it using the template and now using this:

{ "c": { "l": 13, "n": "Motion Sensor" }, "a": [{ "t": 2, "s": 5, "0": { "r": [{"g": 12, "v": 0 }] }, "1": { "r": [{"g": 12, "v": 1 }] }, "b": [{"g": 0}] }, { "t": 12, "i": 10, "0": { "r": [{ "g": 12, "v": 0 }] }, "1": { "r": [{ "g": 12, "v": 1 }] }, "f1": [{ "g": 3 }] }] }

The effect is not ideal. Sometimes switch works, sometimes not. Later today I will explain in details.

Murdrock commented 4 years ago

Edit:

{"c":{"l":13,"b":[{"g":0,"t":5}]},"a":[{"0":{"r":[{"g":12}]},"1":{"r":[{"g":12,"v":1}]},"b":[],"s":0},{"1":{"s":[{"a":1}]},"b":[],"s":0},{"1":{"s":[{"a":2}]},"b":[],"s":0},{"0":{"r":[{"g":12,"v":0}]},"1":{"r":[{"g":12,"v":1}]},"t":12,"s":0,"f0":[],"f1":[{"g":3,"t":0,"i":1,"p":0}],"i":10}]}

How about this? It has switch plus two dummy switches, one for setup and one for OTA UPDATE. Also you should sulply the sensor with 3.3v

image

Murdrock commented 4 years ago

Is there a reason you have the outlet accessory?

adamgdynia commented 4 years ago

Hi! The reason for outlet accessory is to have ability to manually turn on the light if necessary. I plan to use this combo as a light outside the house.

What I find strange is that sometimes the motion sensor triggers the relay and sometimes is not. What is the algorytm in general? I have red that the sensor checks every 2s if there is a motion and gives 3.3v on data pin - I have checked that.

Why sonoff is not executing "1" when there is 3.3v on GPIO3 (RX) after it changed to "0"? Is there another delay?

adamgdynia commented 4 years ago

Btw, Murdrock, thanks for the tip on how to convert 5V HC-SR501 to 3.3V HC-SR501. For others - you simply connect 3.3V as Murdrock showed by the arrow, then Ground and Output!

Murdrock commented 4 years ago

{"c":{"l":13,"n":"Motion","b":[{"g":0,"t":5}]},"a":[{"0":{"r":[{"g":12}]},"1":{"r":[{"g":12,"v":1}]},"b":[{"g":16,"t":1},{"g":16,"t":0}],"s":0},{"1":{"s":[{"a":1}]},"b":[],"s":0},{"1":{"s":[{"a":2}]},"b":[],"s":0},{"t":12,"s":0,"f0":[],"f1":[{"g":4,"t":1}],"i":6}]}

This is the one I use for mine. Gpio 16 (jumper pins) is used to trigger the switch manually, and the motion triggers it through Home app automation.

The motion sensor is connected to s1s2.

Two dummy switches for setup And OTA.

adamgdynia commented 4 years ago

Murdrock, everything work, except motion sensor :) Have you connected data to s2 and ground to s1?

adamgdynia commented 4 years ago

I think I have figured out the HC-SR501 PIR. It works when I set the time delay on the sensor to minimum (0,3s?). It would be veery helpful to know the algorithm though... Thanks guys for your help!

Murdrock commented 4 years ago

Data to s2 and ground s1. Set the manual delay on PIR to minimum.

adamgdynia commented 4 years ago

Thanks, sitting the delay to minimum was the key!

Murdrock commented 4 years ago

I don't know what else to think. I am not an expert! Just tinkering stuff!

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.