Skip to content

Commit 7136695

Browse files
authored
Merge pull request #48 from Lyr3x/dev
v1.3
2 parents 0b09cf4 + 0ab0032 commit 7136695

29 files changed

+1336
-1160
lines changed

.github/workflows/main.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@ jobs:
1414
run: |
1515
python -m pip install --upgrade pip
1616
pip install -U esphome
17+
- name: Validate ESP8266 Config
18+
run: esphome config peopleCounter.yaml
1719
- name: Build ESP8266
1820
run: esphome compile peopleCounter.yaml
21+
- name: Validate ESP32 Config
22+
run: esphome config peopleCounter32.yaml
1923
- name: Build ESP32
2024
run: esphome compile peopleCounter32.yaml
25+

.gitignore

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,18 @@
44
.vscode/.browse.c_cpp.db*
55
.vscode/c_cpp_properties.json
66
.vscode/launch.json
7-
.vscode/
7+
.vscode/*
8+
!.vscode/settings.json
9+
!.vscode/extensions.json
810
lib/Configuration/Config.h
9-
roode/
10-
roode32/
11-
roode_dev/
11+
/roode/
12+
/roode32/
13+
/roode_dev/
14+
roode8266
1215
.esphome/
16+
.pyc
1317
.DS_Store
1418
common/wifi.yaml
1519
common/secrets.yaml
16-
secrets.yaml
20+
secrets.yaml
21+
__pycache__

.vscode/extensions.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"recommendations": [
3+
"esphome.esphome-vscode",
4+
"ms-vscode.cpptools"
5+
]
6+
}

.vscode/settings.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"files.associations": {
3+
"*.yaml": "esphome",
4+
"__split_buffer": "cpp",
5+
"__tree": "cpp",
6+
"algorithm": "cpp",
7+
"deque": "cpp",
8+
"functional": "cpp",
9+
"iterator": "cpp",
10+
"locale": "cpp",
11+
"regex": "cpp",
12+
"string": "cpp",
13+
"unordered_map": "cpp",
14+
"unordered_set": "cpp",
15+
"vector": "cpp"
16+
}
17+
}

README.md

Lines changed: 169 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,162 @@
22

33
People counter working with any smart home system which supports ESPHome and therefore Home Assistant. All necessary entities are created automatically.
44

5-
65
[![Roode community](https://img.shields.io/discord/879407995837087804.svg?label=Discord&logo=Discord&colorB=7289da&style=for-the-badge)](https://discord.gg/RK3KJeSy)
76

7+
## Wiring
8+
The sensors from Pololu, Adafruit and the GY-53 can also be connected to the 5v pin (VIN) as they have an voltage regulator.
9+
10+
If you use a GY-53 you need to connect GND the PS (Ps=0) pin.
11+
12+
Ps=1 (default): Serial port UART mode, Pin3 is TX, Pin4 is RX, TTL level, PWM output works.
13+
Ps=0 (when connected to GND): In the IIC mode, the user can operate the chip by himself. The module owns the MCU and does not operate the chip. The PWM output does not work.
14+
15+
### ESP32
16+
17+
```
18+
ESP32 VL53L1X board
19+
------------------------- -------------
20+
3V3 - VIN
21+
GND - GND
22+
SDA (pin 42, GPIO21) - SDA
23+
SCL (pin 39, GPIO22) - SCL
24+
```
25+
26+
### ESP8266
27+
```
28+
ESP8266 VL53L1X board
29+
------------------------- -------------
30+
3V3 - VIN
31+
GND - GND
32+
D2 (GPIO 4) - SDA
33+
D1 (GPIO 5) - SCL
34+
```
35+
## Configuration
836

9-
![Roode](Roode.png)
37+
Roode is provided as an external_component which means it is easy to setup in any ESPHome sensor configuration file.
38+
39+
Example configuration
40+
41+
```
42+
roode:
43+
id: roode_platform
44+
address: 0x29
45+
update_interval: 100ms
46+
calibration: true
47+
roi_height: 16
48+
roi_width: 6
49+
threshold_percentage: 80
50+
roi_calibration: false
51+
invert_direction: true
52+
restore_values: true
53+
```
54+
55+
### Configuration variables
56+
57+
- **address (Optional, integer)**: The I²C address of the sensor. Defaults to `0x29`.
58+
- **update_interval (Optional, Time)**: The interval to check the sensor. Defaults to `100ms`.
59+
- **roi_height (Optional, int)**: The height of the ROI zones. Min: `4` Max: `16`. Defaults to `16`.
60+
- **roi_width (Optional, int)**: The height of the ROI zones. Min: `4` Max: `16`. Defaults to `6`.
61+
- **max_threshold_percentage (Optional, int)**: The maxium threshold in % which needs to be reached to detect a person. Min: `50` Max: `100`. Defaults to `85`.
62+
- **min_threshold_percentage (Optional, int)**: The minimum threshold in % which needs to be reached to detect a person. Min: `0` Max: `100`. Defaults to `0`.
63+
- **calibration (Optional, bool)**: Enables automatic zone calibration (experimental). Defaults to `true`.
64+
- **roi_calibration (Optional, bool)**: Enables automatic ROI calibration (experimental). Defaults to `false`.
65+
- **invert_direction (Optional, bool)**: Inverts the counting direction. Defaults to `false`.
66+
- **restore_values (Optional, bool)**: Enables the restoration of the last count, after a reboot occurs. Defaults to `false`.
67+
- **advised_sensor_orientation(Optional, bool)**: Inverts the detection orientation of the sensor. Defaults to `true`.
68+
69+
### Sensor
70+
71+
Example Sensor setup to use all available features:
72+
73+
```
74+
binary_sensor:
75+
- platform: status
76+
name: $friendly_name Status
77+
- platform: roode
78+
presence_sensor:
79+
name: $friendly_name presence
80+
81+
sensor:
82+
- platform: roode
83+
id: hallway
84+
people_counter_sensor:
85+
id: peopleCounter
86+
name: $friendly_name people counter
87+
distance_sensor:
88+
name: $friendly_name distance
89+
filters:
90+
- delta: 100.0
91+
threshold_zone0:
92+
name: $friendly_name Zone 0
93+
threshold_zone1:
94+
name: $friendly_name Zone 1
95+
roi_height:
96+
name: $friendly_name ROI height
97+
roi_width:
98+
name: $friendly_name ROI width
99+
100+
- platform: wifi_signal
101+
name: $friendly_name RSSI
102+
update_interval: 60s
103+
104+
- platform: uptime
105+
name: Uptime Sensor
106+
id: uptime_sensor
107+
update_interval: 120s
108+
internal: true
109+
on_raw_value:
110+
then:
111+
- text_sensor.template.publish:
112+
id: uptime_human
113+
state: !lambda |-
114+
int seconds = round(id(uptime_sensor).raw_state);
115+
int days = seconds / (24 * 3600);
116+
seconds = seconds % (24 * 3600);
117+
int hours = seconds / 3600;
118+
seconds = seconds % 3600;
119+
int minutes = seconds / 60;
120+
seconds = seconds % 60;
121+
return (
122+
(days ? String(days) + "d " : "") +
123+
(hours ? String(hours) + "h " : "") +
124+
(minutes ? String(minutes) + "m " : "") +
125+
(String(seconds) + "s")
126+
).c_str();
127+
128+
text_sensor:
129+
- platform: roode
130+
version:
131+
name: $friendly_name version
132+
- platform: roode
133+
entry_exit_event:
134+
name: $friendly_name last direction
135+
136+
- platform: template
137+
name: $friendly_name Uptime Human Readable
138+
id: uptime_human
139+
icon: mdi:clock-start
140+
```
10141

11142
## Algorithm
12-
The implemented Algorithm is an improved version of my own implementation which checks the direction of a movement through two defined zones. ST implemented a nice and efficient way to track the path from one to the other direction. I migrated the algorithm with some changes into the Roode project.
13-
The concept of path tracking is the detection of a human:
14-
* In the first zone only
15-
* In both zones
16-
* In the second zone only
17-
* In no zone
143+
144+
The implemented Algorithm is an improved version of my own implementation which checks the direction of a movement through two defined zones. ST implemented a nice and efficient way to track the path from one to the other direction. I migrated the algorigthm with some changes into the Roode project.
145+
The concept of path tracking is the detecion of a human:
146+
147+
- In the first zone only
148+
- In both zones
149+
- In the second zone only
150+
- In no zone
151+
18152

19153
That way we can ensure the direction of movement.
20154

21155
The sensor creates a 16x16 grid and the final distance is computed by taking the average of the distance of the values of the grid.
22-
We are defining two different Region of Interest (ROI) inside this grid. Then the sensor will measure the two distances in the two zones and will detect any presence and tracks the path to receive the direction.
156+
We are defining two different Region of Interest (ROI) inside this grid. Then the sensor will measure the two distances in the two zones and will detect any presence and tracks the path to receive the direction.
23157

24158
However, the algorithm is very sensitive to the slightest modification of the ROI, regarding both its size and its positioning inside the grid.
25159

26160
ST Microelectronics define the values for the parameters as default like this:
27-
- `ROI_width = 8 //min 4`
28-
- `ROI_height = 16 //min 4`
29-
- `center = {167,231}`
30161

31162
The center of the ROI you set is based on the table below and the optical center has to be set as the pad above and to the right of your exact center:
32163

@@ -37,6 +168,7 @@ ST user manual UM2555 explains ROI selection in detail, so we recommend
37168
reading that document carefully. Here is a table of SPAD locations from
38169
UM2555 (199 is the default/center):
39170

171+
```
40172
128,136,144,152,160,168,176,184, 192,200,208,216,224,232,240,248
41173
129,137,145,153,161,169,177,185, 193,201,209,217,225,233,241,249
42174
130,138,146,154,162,170,178,186, 194,202,210,218,226,234,242,250
@@ -54,11 +186,13 @@ UM2555 (199 is the default/center):
54186
122,114,106, 98, 90, 82, 74, 66, 58, 50, 42, 34, 26, 18, 10, 2
55187
121,113,105, 97, 89, 81, 73, 65, 57, 49, 41, 33, 25, 17, 9, 1
56188
120,112,104, 96, 88, 80, 72, 64, 56, 48, 40, 32, 24, 16, 8, 0 <- Pin 1
189+
```
57190

58191
This table is oriented as if looking into the front of the sensor (or top of
59192
the chip). SPAD 0 is closest to pin 1 of the VL53L1X, which is the corner
60193
closest to the VDD pin on the Pololu VL53L1X carrier board:
61194

195+
```
62196
+--------------+
63197
| O| GPIO1
64198
| |
@@ -74,99 +208,48 @@ closest to the VDD pin on the Pololu VL53L1X carrier board:
74208
| |
75209
| O| VDD
76210
+--------------+
211+
```
77212

78213
However, note that the lens inside the VL53L1X inverts the image it sees
79214
(like the way a camera works). So for example, to shift the sensor's FOV to
80215
sense objects toward the upper left, you should pick a center SPAD in the
81216
lower right.
82217

83-
84-
85-
86218
#### Threshold distance
87219

88220
Another crucial choice is the one corresponding to the threshold. Indeed a movement is detected whenever the distance read by the sensor is below this value. The code contains a vector as threshold, as one (as myself) might need a different threshold for each zone.
89221

90-
The SparkFun library also supports more formats for the threshold: for example one can set that a movement is detected whenever the distance is between two values. However, more information for the interested reader can be found on the corresponding page.
91-
92-
With the updated code (however only for esp32 at the moment) the threshold is automatically calculated by the sensor. To do so it is necessary to position the sensor and, after turning it on, wait for 10 seconds without passing under it. After this time, the average of the measures for each zone will be computed and the threshold for each ROI will correspond to 80% of the average value. Also the value of 80% can be modified in the code, by editing the variable `threshold_percentage`
222+
The threshold is automatically calculated by the sensor. To do so it is necessary to position the sensor and, after turning it on, wait for 10 seconds without passing under it. After this time, the average of the measures for each zone will be computed and the thereshold for each ROI will correspond to 80% of the average value. Also the value of 80% can be modified in the code, by editing the variable `max_threshold_percentage` and `min_threshold_percentage`.
93223

94-
The calibration of the threshold can also be triggered by a MQTT message. An example for doing so is in the file `integration_with_home_assistant.md`.
95224

225+
If you install the sensor e.g 20cm over a door you dont want to count the door open and closing. In this case you should set the `min_threshold_percentage` to about `10`.
96226

227+
Example:
97228

98-
## Useful links
229+
```
230+
Mounting height: 2200mm
231+
Door height: 2000mm
232+
Person height: 1800mm
233+
max_threshold_percentage: 85% = 1760
234+
min_threshold_percentage: 10% = 200
99235
100-
[SparkFun library guide](https://learn.sparkfun.com/tutorials/qwiic-distance-sensor-vl53l1x-hookup-guide/all) with more information about the functions used in the code
236+
All distances smaller then 200mm and greater then 17600mm will be ignored.
237+
```
101238

102239
## Hardware
240+
103241
There will be a specific Hardware setup (recommended brands etc.) soon!
104-
* ESP8266 or ESP32 (Wemos D1 mini case will be available)
105-
* 1x VL53L1X (GY-53 and cheap chinese sensors)
106-
* Optional HC-SR501
107-
* Optional 128x32 OLED
108-
* Power Supply
109-
* Enclosure (see .stl files) - will be updated soon!
110-
Pins:
111-
SDA_PIN D2 or 21 (ESP32)
112-
SCL_PIN D1 or 22 (ESP32)
113242

243+
- ESP8266 or ESP32 (Wemos D1 mini case will be available)
244+
- 1x VL53L1X (Pololu, GY-53 and cheap chinese sensors)
245+
- Power Supply
246+
- Encolsure (see .stl files) - will be updated soon!
247+
Pins:
248+
SDA_PIN 4 or 21 (ESP32)
249+
SCL_PIN 5 or 22 (ESP32)
250+
114251
## Configuration
115-
### ESPHome
116-
Configure at least the secrets.yaml with your wifi SSID and password to connect. Check the peopleCounter.yaml to adapt the exposed sensors to your needs.
117-
118-
### Entry/Exit inverted:
119-
Set INVERT_DIRECTION to true or false to invert the direction.
120252

253+
### ESPHome
121254

122-
## Configuration
123-
Be sure to configure your wifi credentials and adapt the global variables to set everything to your needs.
124-
The most important config part is the calibration mode. You have two different calibration modes available:
125-
Calibration v1 calibrates the distance for one zone and calculates the standard deviation and uses that value for both zones.
126-
Calibration v2 calibrates both zones individually (thanks to @andrea-fox).
127-
128-
## Changelog
129-
### Changelog v1.0
130-
#### Additions and Breaking Changes
131-
* ESPHome (thanks to @diplix)
132-
* Removes legacy support which includes
133-
* Arduino platform
134-
* MySensors platform
135-
* **Non** VL53L1X-Sensors
136-
* VL531L1X TOF Sensor with configurable ROI zones for one-sensor-solution
137-
* Counting people entering and leaving a room with path tracking for improved accuracy
138-
* Sensor threshold calibration for each zone
139-
* Receiving commands from the the controller e.g softreset
140-
* OLED support (coming in 1.1)
141-
* Sleep mode with Motion Sensor support (coming in 1.1)
142-
* Firmware upgrades over WebUI (esphome)
143-
144-
145-
### Changelog v0.9.6
146-
#### Additions
147-
* added full VL53L0X support
148-
* Added OLED brightness config option
149-
* Updated to [email protected]
150-
#### Bugfixes and other changes
151-
* Measuring speed improvements
152-
* Fixed receiving and sending message issues
153-
* General bug fixes and improvements
154-
* Changed default PA_LEVEL to HIGH
155-
156-
### Changelog v0.9.5
157-
* Added VL53L0X support
158-
* Using the Pololu VL53XXX Library
159-
* Huge Code refactor
160-
161-
### Changelog v0.9.4-alpha2:
162-
* added incomplete push button support
163-
* There is a need of 2 spare interrupt PINS
164-
* May be working with PinChangeInterrupt library
165-
* minor bugfixes
166-
* rename send() function and changed signature
167-
### Changelog v0.9.4-beta:
168-
* changed IR-calibration hardcoded value to THRESHOLD_X
169-
* CALIBRATION_VAL to 4000
170-
### Changelog v.0.9.4-release
171-
* Added standard deviation threshold calculation
172-
* Removed constant THRESHOLD_X
255+
Configue at least the secrets.yaml with your wifi SSID and password to connect. Check the peopleCounter.yaml or peopleCounter32.yaml to adapt the exposed sensors to your needs.

common/api.yaml

Lines changed: 0 additions & 4 deletions
This file was deleted.

common/common.yaml

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)