GithubHelp home page GithubHelp logo

lyr3x / roode Goto Github PK

View Code? Open in Web Editor NEW
149.0 16.0 41.0 26.4 MB

A reliable smart home people counter based on VL53L1X and ESPHome

License: The Unlicense

C++ 65.34% Python 34.66%
esp8266 esp32 esphome home-assistant vl53l1x vl53l1x-sensor smarthome people-counter people-detection

roode's Introduction

RooDe

GitHub release Build Maintenance

Roode community

People counter working with any smart home system which supports ESPHome/MQTT like Home Assistant. All necessary entities are created automatically.

Hardware Recommendation

  • ESP8266 or ESP32
    • Wemos D1 Mini ESP32 <-- Recommended
    • Wemos D1 mini (ESP8266)
    • NodeMCU V2
  • 1x VL53L1X
    • Pololu <-- Recommended
    • GY-53
    • Black PCB chinese sensor
    • Pimoroni
  • 1A Power Supply Do not use an USB port of your computer!
  • Encolsure (see .stl files) - will be updated soon! Pins: SDA_PIN 4 (ESP8266) or 21 (ESP32) SCL_PIN 5 (ESP8266) or 22 (ESP32)

Wiring

The sensors from Pololu, Adafruit and the GY-53 can also be connected to the 5v pin (VIN) as they have an voltage regulator.

If you use a GY-53 you need to connect GND the PS (Ps=0) pin.

Ps=1 (default): Serial port UART mode, Pin3 is TX, Pin4 is RX, TTL level, PWM output works. 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.

ESP32

                    ESP32   VL53L1X board
-------------------------   -------------
                      3V3 - VIN
                      GND - GND
     SDA (pin 42, GPIO21) - SDA
     SCL (pin 39, GPIO22) - SCL

ESP8266

                  ESP8266   VL53L1X board
-------------------------   -------------
                      3V3 - VIN
                      GND - GND
              D2 (GPIO 4) - SDA
              D1 (GPIO 5) - SCL

Configuration

Platform Setup

Roode is provided as an external_component which means it is easy to setup in any ESPHome sensor configuration file.

Other than base ESPHome configuration the only config that's needed for Roode is

external_components:
  - source: github://Lyr3x/Roode@master
    refresh: always
vl53l1x:
roode:

This uses the recommended default configuration.

However, we offer a lot of flexibility. Here's the full configuration spelled out.

external_components:
  - source: github://Lyr3x/Roode
    refresh: always
    ref: master

# VL53L1X sensor configuration is separate from Roode people counting algorithm
vl53l1x:
  # A non-standard I2C address
  address:

  # Sensor calibration options
  calibration:
    # The ranging mode is different based on how long the distance is that the sensor need to measure.
    # The longer the distance, the more time the sensor needs to take a measurement.
    # Available options are: auto, shortest, short, medium, long, longer, longest
    ranging: auto
    # The offset correction distance. See calibration section (WIP) for more details.
    offset: 8mm
    # The corrected photon count in counts per second. See calibration section (WIP) for more details.
    crosstalk: 53406cps

  # Hardware pins
  pins:
    # Shutdown/Enable pin, which is needed to change the I2C address. Required with multiple sensors.
    xshut: GPIO3
    # Interrupt pin. Use to notify us when a measurement is ready. This feature is WIP.
    # This needs to be an internal pin.
    interrupt: GPIO1

# Roode people counting algorithm
roode:
  # Smooth out measurements by using the minimum distance from this number of readings
  sampling: 2

  # The orientation of the two sensor pads in relation to the entryway being tracked.
  # The advised orientation is parallel, but if needed this can be changed to perpendicular.
  orientation: parallel

  # This controls the size of the Region of Interest the sensor should take readings in.
  # The current default is
  roi: { height: 16, width: 6 }
  # We have an experiential automatic mode that can be enabled with
  # roi: auto
  # or only automatic for one dimension
  # roi: { height: 16, width: auto }

  # The detection thresholds for determining whether a measurement should count as a person crossing.
  # A reading must be greater than the minimum and less than the maximum to count as a crossing.
  # These can be given as absolute distances or as percentages.
  # Percentages are based on the automatically determined idle or resting distance.
  detection_thresholds:
    min: 0% # default minimum is any distance
    max: 85% # default maximum is 85%
    # an example of absolute units
    # min: 50mm
    # max: 234cm

  # The people counting algorithm works by splitting the sensor's capability reading area into two zones.
  # This allows for detecting whether a crossing is an entry or exit based on which zones was crossed first.
  zones:
    # Flip the entry/exit zones. If Roode seems to be counting backwards, set this to true.
    invert: false

    # Entry/Exit zones can set overrides for individual ROI & detection thresholds here.
    # If omitted, they use the options configured above.
    entry:
      # Entry zone will automatically configure ROI, regardless of ROI above.
      roi: auto
    exit:
      roi:
        # Exit zone will have a height of 8 and a width of number set above or default or auto
        height: 8
        # Additionally, zones can manually set their center point.
        # Usually though, this is left for Roode to automatically determine.
        center: 124

      detection_thresholds:
        # Exit zone's min detection threshold will be 5% of idle/resting distance, regardless of setting above.
        min: 5%
        # Exit zone's max detection threshold will be 70% of idle/resting distance, regardless of setting above.
        max: 70%

Also feel free to check out running examples for:

Sensors

People Counter

The most important one is the people counter.

number:
  - platform: roode
    people_counter:
      name: People Count

Regardless of how close we can get, people counting will never be perfect. This allows the current people count to be adjusted easily via Home Assistant.

Other sensors available

binary_sensor:
  - platform: roode
    presence_sensor:
      name: $friendly_name presence

sensor:
  - platform: roode
    id: hallway
    distance_sensor:
      name: $friendly_name distance
      filters:
        - delta: 100.0
    threshold_entry:
      name: $friendly_name Zone 0
    threshold_exit:
      name: $friendly_name Zone 1
    roi_height:
      name: $friendly_name ROI height
    roi_width:
      name: $friendly_name ROI width

text_sensor:
  - platform: roode
    version:
      name: $friendly_name version
  - platform: roode
    entry_exit_event:
      name: $friendly_name last direction

Threshold distance

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.

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.

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.

Example:

Mounting height:    2200mm
Door height:        2000mm
Person height:      1800mm
max_threshold_percentage: 80% = 1760
min_threshold_percentage: 10% = 200

All distances smaller then 200mm and greater then 1760mm will be ignored.

Algorithm

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. The concept of path tracking is the detecion of a human:

  • In the first zone only
  • In both zones
  • In the second zone only
  • In no zone

That way we can ensure the direction of movement.

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. 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.

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

ST Microelectronics define the values for the parameters as default like this:

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:

Set the center SPAD of the region of interest (ROI) based on VL53L1X_SetROICenter() from STSW-IMG009 Ultra Lite Driver

ST user manual UM2555 explains ROI selection in detail, so we recommend reading that document carefully. Here is a table of SPAD locations from UM2555 (199 is the default/center):

128,136,144,152,160,168,176,184,  192,200,208,216,224,232,240,248
129,137,145,153,161,169,177,185,  193,201,209,217,225,233,241,249
130,138,146,154,162,170,178,186,  194,202,210,218,226,234,242,250
131,139,147,155,163,171,179,187,  195,203,211,219,227,235,243,251
132,140,148,156,164,172,180,188,  196,204,212,220,228,236,244,252
133,141,149,157,165,173,181,189,  197,205,213,221,229,237,245,253
134,142,150,158,166,174,182,190,  198,206,214,222,230,238,246,254
135,143,151,159,167,175,183,191,  199,207,215,223,231,239,247,255

127,119,111,103, 95, 87, 79, 71,   63, 55, 47, 39, 31, 23, 15,  7
126,118,110,102, 94, 86, 78, 70,   62, 54, 46, 38, 30, 22, 14,  6
125,117,109,101, 93, 85, 77, 69,   61, 53, 45, 37, 29, 21, 13,  5
124,116,108,100, 92, 84, 76, 68,   60, 52, 44, 36, 28, 20, 12,  4
123,115,107, 99, 91, 83, 75, 67,   59, 51, 43, 35, 27, 19, 11,  3
122,114,106, 98, 90, 82, 74, 66,   58, 50, 42, 34, 26, 18, 10,  2
121,113,105, 97, 89, 81, 73, 65,   57, 49, 41, 33, 25, 17,  9,  1
120,112,104, 96, 88, 80, 72, 64,   56, 48, 40, 32, 24, 16,  8,  0 <- Pin 1

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

  +--------------+
  |             O| GPIO1
  |              |
  |             O|
  | 128    248   |
  |+----------+ O|
  ||+--+  +--+|  |
  |||  |  |  || O|
  ||+--+  +--+|  |
  |+----------+ O|
  | 120      0   |
  |             O|
  |              |
  |             O| VDD
  +--------------+

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

FAQ/Troubleshoot

Question: Why is the Sensor not measuring the correct distances?

Answer: This can happen in various scenarios. I try to list causes sorted by likelyhood

  1. You did not remove the protection film (most times its yellow)
  2. You did not connect the Sensor properly
  3. Light interference (You will see a lot of noise)
  4. Bad connections

Sponsors

Thank you very much for you sponsorship!

  • sunshine-hass

roode's People

Contributors

bookcasey avatar carsonf avatar dnl2023 avatar driv3r avatar gorbunovav avatar jcastro avatar lyr3x avatar therealwaldo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

roode's Issues

Provide Recalibration as button

As of 2021.12 ESPHome and HA support button entities which do a certain action on press. That is something that were missing to implement a proper recalibration, our counter reset button.

Rework ROI detection

The ROI detection needs to be reworked. It should find the best ROI settings defined by distance and target surface size.

Return the people count as a "sensor" instead of "number"

Is your feature request related to a problem? Please describe.
Currently, the output as a number displays the sliding bar when using it on lovelace.

Describe the solution you'd like
I would like to have the result of the counting as a sensor in order to display its value without the sliding bar on lovelace.

Describe alternatives you've considered
Tried to create a new sensor that capture the value of the output but its format is not compatible.

number:
  - platform: roode
    people_counter:
      id: count
      name: $friendly_name people counter

 sensor:
   - platform: template
     id: people_in_lab
     name: "People in Lab"
     lambda: !lambda |-
       return id(count);

I get an error during compilation saying that it can't convert from PersistedNumber to float

Hardware recommendations

Is your feature request related to a problem? Please describe.
I am interested to build the Room Detection solution and I am looking for some reliable hardware recommendations. The motivation to have reliable hardware is to avoid unexpected behavior down the road due to the fact that I have saved a couple of dollars on hardware.

Describe the solution you'd like
I would like to have a list of recommended hardware that proven to be reliable.
So far I have compiled the following hardware list but not sure which one to choose.
ESP32 boards:

  • esp32-s3-devkitc-1-n8r8 - pretty modern development boards and decent prices (around 15USD or 12 EUR or 13GBP at different shops - digikey.com, mouser.com, tme.eu etc.). As alternative, one can choose esp32-s3-devkitc-1-n8r2 or esp32-s3-devkitc-1-n8 - they are more often in stock at reputable retailers.
  • Wemos D32 Pro from wemos.cc
  • HUZAHH32 https://www.adafruit.com/product/3405 . It costs about 20USD
  • ESP32 Thing Plus from Sparkfun https://www.sparkfun.com/products/15663 . It costs about 22USD.

VL53L1X sensors:

Describe alternatives you've considered
I studied the open and closed issues for this git project and so far found only a mention from a user reporting that waveshare VL53L1X sensor proven to be much more reliable than cheaper versions bought from some other stores.

Additional context
I plan to buy hardware for room detenction for 5 doors in my house initially, hopefully later will extend to all other rooms.

Natural light interference

Hello!
Thanks so much for sharing this. I've been long testing other repos who tried to do same counting with this sensor but in all of these I've found the sensor is not reliable at certain wavelengths during day. Tried several different sensor manufacturers, cases, position in the door frame and so on, always with same result.

I've installed today this repo (it's night time for me now) with the hope that somehow it will work better and software will more or less compensate for the hardware issues this sensor has, so will report back!

In any case, I wanted to also ask you if you have ever considered using instead the thermal sensor AMG8833 for doing the counting, which it seems what they're using here https://www.hiome.com/. With this sensor it seems we won't have at least the natural light problem. There's already some repos trying to come up with person detection (not counting) but it could be useful for inspiration if you ever consider it https://github.com/TheRealWaldo/esp8266-amg8833

Thanks!

Just tested v1.3.3

i’ll just note what stuck out while testing it. not everything i conclude is meant as a feature request, it’s more a field report.

first off, my VL53L1X breakout board has an xhut pin, which needs to be set HIGH to work. i connected it to pin 23 and added the folowing yaml:

esphome:
  # ...
  on_boot:
    then:
      - output.turn_on: xshut

output:
  - platform: gpio
    pin: 23
    id: xshut

during my first tests, because of the missing xshut, roode "Failed to detect and initialize" the sensor and shut down because of a loop.

that’s kind of a pain, because it renders the esp32 useless and unable to over the air updates. logging the error and letting esphome do it’s thing would be much nicer.

next problem i had was the watchdog. as long as the API was configured calling calibration caused a watchdog induced reboot. disabling initial calibration

roode:
  # ...
  calibration: false

enabled esphome to run and loop, however there were constant API disconnections (every 1-2 seconds) . increasing the roode update_interval to ~ 200ms or 400ms helped a little, but the API still disconnected eveery few seconds.

removing the API entirely

#api:
#  password: !secret api_password
#  reboot_timeout: 60min
# ...

and unsing mqtt: helped: initial calibration ran through and an update_interval of 10ms was ok.

to substitute the API services, i configured mqtt subscribes:

mqtt:
  broker: !secret mqtt_broker
  username: !secret mqtt_username
  password: !secret mqtt_password
  port: !secret mqtt_port
  reboot_timeout: 20min
  
  on_message:
    - topic: ${devicename}/services/set_counter
      qos: 0
      then:
        - lambda: "id(roode_platform)->sendCounter(atoi(x.c_str()));"

    - topic: ${devicename}/services/reset_counter
      qos: 0
      then:
        - lambda: "id(roode_platform)->sendCounter(0);"

    - topic: ${devicename}/services/recalibrate
      qos: 0
      then:
        - lambda: "id(roode_platform)->recalibration();"

however calling id(roode_platform)->recalibration(); while roode is runing still calls the watchdog. setting and resetting the counter works fine this way.

since esphome 2021.11 there is a feature called entity_category (see esphome docs). it would be nice to make the following platform: roode sensors "diagnostic": distance_sensor, max_threshold_zone0,max_threshold_zone1,min_threshold_zone0,min_threshold_zone1,roi_height, roi_width and {"text_sensor":["platform":"roode", "version":[]]}

other than that roode works realy nice and reliably. i like how the auto-calibration works and the many diagnotic sensors for debugging and testing.

here are links to the parts i used:

Failed config platform not found 'sensor.vl53l1x' ESPHome V2022.1.2 and ESP8266

Describe the bug
Compiling fails on ESPHome V2022.1.2 and Roode 1.5.1.

To Reproduce
Steps to reproduce the behavior:

substitutions:
  devicename: roode8266
  friendly_name: $devicename

external_components:
  refresh: always
  source:
    type: git
    url: https://github.com/Lyr3x/Roode
    ref: master

esphome:
  name: $devicename
  platform: ESP8266
  board: nodemcuv2

wifi:
  networks:
    - ssid: !secret wifi_ssid
      password: !secret wifi_password
  use_address: $devicename
  fast_connect: True
  power_save_mode: none
  domain: .local

captive_portal:

api:
  reboot_timeout: 60min
  services:
    - service: recalibrate
      then:
        - lambda: "id(roode_platform)->recalibration();"

ota:
  password: !secret http_password

web_server:
  port: 80
  auth:
    username: admin
    password: !secret http_password

# Enable logging
logger:
  level: INFO

i2c:
# ESP8266
  sda: 4
  scl: 5
# ESP32
#   sda: 21
#   scl: 22

# VL53L1X sensor configuration is separate from Roode people counting algorithm
vl53l1x:
  calibration:
    # The ranging mode is different based on how long the distance is that the sensor need to measure.
    # The longer the distance, the more time the sensor needs to take a measurement.
    # Available options are: auto, shortest, short, medium, long, longer, longest
    ranging: auto

roode:
  id: roode_platform
  # Smooth out measurements by using the minimum distance from this number of readings
  sampling: 2
  # This controls the size of the Region of Interest the sensor should take readings in.
  roi: { height: 16, width: 6 }
  # The detection thresholds for determining whether a measurement should count as a person crossing.
  # A reading must be greater than the minimum and less than the maximum to count as a crossing.
  # These can be given as absolute distances or as percentages.
  # Percentages are based on the automatically determined idle or resting distance.
  detection_thresholds: # defaults for both zones. These also default to 0% & 85% as previously done.
    min: 100mm # absolute distance
    max: 80% # percent based on idle distance
  # The people counting algorithm works by splitting the sensor's capability reading area into two zones.
  # This allows for detecting whether a crossing is an entry or exit based on which zones was crossed first.
  zones:
    invert: true

button:
  - platform: restart
    name: $friendly_name Restart
    entity_category: config
  - platform: template
    name: $friendly_name Recalibrate
    on_press:
      - lambda: id(roode_platform)->recalibration();
    entity_category: config

number:
  - platform: roode
    people_counter:
      name: $friendly_name people counter

binary_sensor:
  - platform: status
    name: $friendly_name API Status
  - platform: roode
    presence_sensor:
      name: "$friendly_name presence"

sensor:
  - platform: roode
    name: Roode
    zones:
      entry:
        distance:
          name: $friendly_name Entry Distance
          filters:
            - delta: 100
      exit:
        distance:
          name: $friendly_name Exit Distance
          filters:
            - delta: 100
    max_threshold_entry:
      name: $friendly_name max zone 0
    max_threshold_exit:
      name: $friendly_name max zone 1
    min_threshold_entry:
      name: $friendly_name min zone 0
    min_threshold_exit:
      name: $friendly_name min zone 1
    roi_height_entry:
      name: $friendly_name ROI height zone 0
    roi_width_entry:
      name: $friendly_name ROI width zone 0
    roi_height_exit:
      name: $friendly_name ROI height zone 1
    roi_width_exit:
      name: $friendly_name ROI width zone 1
  - platform: vl53l1x
    error:
      name: Sensor Error
  - platform: wifi_signal
    name: $friendly_name RSSI
    update_interval: 60s

  - platform: uptime
    name: Uptime Sensor
    id: uptime_sensor
    update_interval: 60s
    internal: true
    on_raw_value:
      then:
        - text_sensor.template.publish:
            id: uptime_human
            state: !lambda |-
              int seconds = round(id(uptime_sensor).raw_state);
              int days = seconds / (24 * 3600);
              seconds = seconds % (24 * 3600);
              int hours = seconds / 3600;
              seconds = seconds % 3600;
              int minutes = seconds /  60;
              seconds = seconds % 60;
              return (
                (days ? String(days) + "d " : "") +
                (hours ? String(hours) + "h " : "") +
                (minutes ? String(minutes) + "m " : "") +
                (String(seconds) + "s")
              ).c_str();

text_sensor:
  - platform: roode
    version:
      name: $friendly_name version
  - platform: roode
    entry_exit_event:
      name: $friendly_name last direction
  - platform: template
    name: $friendly_name Uptime Human Readable
    id: uptime_human
    icon: mdi:clock-start

Logs:

INFO Updating https://github.com/Lyr3x/Roode@master
Failed config

sensor.roode: [source /config/esphome/esphome-pplcounter.yaml:105]
  platform: roode
  name: Roode
  
  [zones] is an invalid option for [sensor.roode]. Please check the indentation.
  zones:  [source /config/esphome/esphome-pplcounter.yaml:108]
    entry: 
      distance: 
        name: roode8266 Entry Distance
        filters: 
          - delta: 100
    exit: 
      distance: 
        name: roode8266 Exit Distance
        filters: 
          - delta: 100
  max_threshold_entry: 
    name: roode8266 max zone 0
  max_threshold_exit: 
    name: roode8266 max zone 1
  min_threshold_entry: 
    name: roode8266 min zone 0
  min_threshold_exit: 
    name: roode8266 min zone 1
  roi_height_entry: 
    name: roode8266 ROI height zone 0
  roi_width_entry: 
    name: roode8266 ROI width zone 0
  roi_height_exit: 
    name: roode8266 ROI height zone 1
  roi_width_exit: 
    name: roode8266 ROI width zone 1
sensor.vl53l1x: [source /config/esphome/esphome-pplcounter.yaml:134]
  
  Platform not found: 'sensor.vl53l1x'.
  platform: vl53l1x
  error: 
    name: Sensor Error

[1.0] Performance issue on arduino

Since moving to the new codebase we have an enormous performance issue with the arduino resulting in missing counts. We also reached the RAM limit which is another argument to switch to the ESP platform.
Investigating this issue and trying to make 1.0 running smooth again

Freezing on LOGO

Hello,
I'm trying to reproduce the project on WEMOS D1 mini Lite with VE53L0/1X and with oled disabled. Compiled OK, but after start i see on serial only Logo and nothing more.
What is the reason?


| / |_ / | ___ _ __ ___ ___ _ __ ___
| |/| | | | _
\ / _ \ _ \/ __|/ _ \|
_/ __|
| | | | |
| || | / | | _ \ _ | | _
|
| |
|_
, |/ ___|| ||/_/|| |/
|
__/ 2.3.1

With debug enabled I got:
72 MCO:BGN:INIT NODE,CP=RNNNE---,REL=255,VER=2.3.1
87 TSM:INIT
88 TSF:WUR:MS=0
95 !TSM:INIT:TSP FAIL
97 TSM:FAIL:CNT=1
99 TSM:FAIL:DIS
100 TSF:TDI:TSL
10103 TSM:FAIL:RE-INIT
10105 TSM:INIT
10111 !TSM:INIT:TSP FAIL
10113 TSM:FAIL:CNT=2
10115 TSM:FAIL:DIS
10117 TSF:TDI:TSL
20119 TSM:FAIL:RE-INIT
20121 TSM:INIT
20127 !TSM:INIT:TSP FAIL
20129 TSM:FAIL:CNT=3
20131 TSM:FAIL:DIS
20133 TSF:TDI:TSL
30135 TSM:FAIL:RE-INIT
30137 TSM:INIT
30143 !TSM:INIT:TSP FAIL
30145 TSM:FAIL:CNT=4
30147 TSM:FAIL:DIS
30149 TSF:TDI:TSL

Add service to manipulate thresholds without flashing a new FW

Is your feature request related to a problem? Please describe.
Original request by OriginalOwl: It might be nice if the thresholds could be tweaked without having to reflash

Describe the solution you'd like
Calling a service to set the new value calibrates roode again to have the new threshold active

FR: Manual mode switch

Is your feature request related to a problem? Please describe.
As is already known, the sensor does not work reliably (or at all) in a lot of light

Describe the solution you'd like
A practical solution would be if every Roode device had a "manual mode" switch. When this is activated, the sensor does nothing - but the number entity can still be controlled via correction automations for example via PIR or radar sensors.
That way I could automatically disable the device if the outdoor brightness is high and specific windows or window blinds are open, but still use the number entity for room automations.

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Add any other context or screenshots about the feature request here.

Entry and exit event sensors

Describe the solution you'd like
As the title implies. Maybe you can make an additional sensor entity that tells whether someone enters or leaves. So the actual count of people can be handled on a centralised home assistant entity of the counter domain. (counter.**) Also, with this method multiple sensors can be used in a room with, for example, more entrances.

Additional context
Keep up the good work!

WebUI for ESP

Implement a configuration WebUi for the ESP boards for easy Wifi, MQTT and Domoticz setup.

Continuous distance readings

Hi @Lyr3x,

It seems like I've been able to enable just the distance_sensor in order to get continuous readings by disabling the people counter sensor.

Is this a supported use-case? I see that the distance changes a lot even if the sensor is completely stable, which might indicate the distance mode is not correctly configured. Should I be manually configuring the sensor to mode 2 (in my case)?

Thanks,

FYI: made an esphome version of this

@Lyr3x based on your work i managed to convert this (the 1.0 version) into a working esphome configuration: https://github.com/diplix/esphome-configuration

i’m using two of these and they’ve been working quite reliably for a couple oof weeks now. one esp8266 tof-sensor is combined with a door sensor, the other one also reuses measured values for some kind oof lichtschranke to act before a count is registered. OTA updates are working (thanks to esphome) and on the fly calibartion should be doable as well.

ESP8266 WiFi not connecting

Describe the bug
Used the latest yaml example, the firmware is compiled just fine, I upload it without an issue and restart the module. On restart if the sensor is not connected the WiFi is connected properly after attempting to find the sensor. If the sensor is connected Wifi fails to connect.

To Reproduce
Connect the sensor to SDA & SCL

Expected behavior
The ESP8266 should connect to WiFi with sensor connected

Additional context
Attached 2 log files one with sensor online and one offline.
with_sensor.txt
without_sensor.txt

Preserve last calibration results between reboots

Is your feature request related to a problem? Please describe.

The calibration process requires some stable and predictable conditions.
The auto-calibration feature is useful since it allows to simplify the sensor setup.
Periodical re-calibration makes sense to adjust expectations to the changing environment.
Automatic re-calibration on boot is unpredictable.

Describe the solution you'd like

Preserve calibration results in some way. And don't perform automatic calibration on boot if data already present.
Re-calibration can be performed on schedule via the exposed service.

Describe alternatives you've considered

Use manual calibration (e.g. turn-on automatic method, grab values, fill into config).
Downsides:

  • each time sensor boots with some default values unrelated to the latest calibration results
  • more manual work

Compilation warning

The latest ESPhome update has a warning.
What does it mean?

INFO Reading configuration /config/esphome/roode8266.yaml...
INFO Updating https://github.com/Lyr3x/Roode@master
INFO Generating C++ source...
INFO Compiling app...
********************************************************************************
Obsolete PIO Core v5.2.4 is used (previous was 5.2.5)
Please remove multiple PIO Cores from a system:
https://docs.platformio.org/page/faq.html#multiple-platformio-cores-in-a-system
********************************************************************************
Processing roode8266 (board: d1_mini; framework: arduino; platform: platformio/espressif8266 @ 3.2.0)

Support for MQTT and ESP8266/ESP32

Thanks to the new codebase coming in the next major version it is possible to add support for the ESP8266 and ESP32 which will be the new base platform for Roode in the future. Introducing the new platoform we well switch from MySensors to MQTT.
Experimental support is already added in the dev branch https://github.com/Lyr3x/Roode/tree/v1.0

Add configurable OLED brightness

To change the OLED brightness we can use the sendCommand(uint8_t c) function.
First we need to send 0x81 and after that we can set the brightnes to values between 0 and 255.

oled.sendCommand(0x81);
oled.sendCommand(1); 

Two-way Counter

Implement a two way counter system to cover two rooms with one roode.

ESPHome config combination validation

Is your feature request related to a problem? Please describe.
Currently some configuration parameters are mutually exclusive. There is no validation and the correct options are silently applied. That currently leads to misconception at the user side

Describe the solution you'd like
A clear and concise warning or error should appear if a user configures invalid option combinations.

Use of external_components

Is your feature request related to a problem? Please describe.
It takes quite some configuring and moving files to get started with this. The advantage of esphome can be exploited more, I think.

Describe the solution you'd like
Instead of moving all the files over and stuff. Use external components.

external_components:
  - source: github://Lyr3x/Roode

Manual ROI causes read distance failure

Describe the bug
A clear and concise description of what the bug is.
All distance reads return 65535mm.

roi: auto

Doesn't produce this behavior

To Reproduce

# roi: 

Maybe use a new people counting algorithm

Is your feature request related to a problem? Please describe.
In this version, the counting algorithm is derived from gesture direction recognition algorithm. In some practical situations, it will be inaccurate. For example, if a person walks from the outside to the room, stays near the sensor, does not enter the room and then turns out, the sensor will mistakenly believe that someone has entered the room.

Describe the solution you'd like
Use st's people counting algorithm.

Describe alternatives you've considered
My coding is very bad.I tried to convert ST's stm32 people counting code to esp32 code,but I failed.
Maybe you can try this.

Additional context
FYI
St's source code: https://www.st.com/en/embedded-software/stsw-img010.html
stm32 to esp32 example:https://github.com/kazkojima/esp32-vl53l1x-test

Fix sensor orientation option

Describe the bug
Sensor orientation toggle is not changing all parts through the code.

If changing the orientation center points and ROI sizes must be adapted everywhere. Thus this must be implemented in a central part

Add MIN_DISTANCE

Add a configurable MIN_DISTANCE to make it possible to ignore e.g a door opening/closing. With that feature we are able to kind of ignore doors when Roode is installed on the ceiling. Thanks @jcastro for the feedback!

Weird bug with missing esphome/components/switch.h

Describe the bug
Just installed the external_component on ESPHome to try it out, first build I get:

fatal error: esphome/components/switch/switch.h: No such file or directory

Which is weird since this include seems perfectly valid according to ESPHome's documentation. I'm still unsure if it's something local to me or something else but I've cleaned my whole ESPHome directory (left only the YAML files) and this was still happening. I've searched the code and didn't see Roode using switch stuff, so I just commented the include and everything worked perfectly. Maybe a leftover?

To Reproduce
Steps to reproduce the behavior:

Include Roode via the following snippet:

external_components:
  - source: github://Lyr3x/Roode@master
    components: [ roode ]

Try to build your configuration. Build fails with

fatal error: esphome/components/switch/switch.h: No such file or directory

Expected behavior

Clean build.

Screenshots
N/A

Additional context
This might be a leftover include. Still unsure why it happens, glad removing it results in no issues so far.

Manual ROI / Auto Distance Calibration Threshold

Previously ROI height/width could be adjusted manually and still allow the distance calibration threshold to be automatically configured. With the config schema changes in 1.4 this is no longer possible.

how can I integrate the sensor into Home Assistant?

Hello, how can I integrate the sensor into Home Assistant? I only get an error message that it cannot find the platform root.

I need help please

Configuration incorrect

Platform error number.roode - Integration 'roode' not found.
Platform error sensor.roode - Integration 'roode' not found.
Platform error binary_sensor.roode - Integration 'roode' not found.

My configuration.yaml configuration.

Configure a default setup of Home Assistant (frontend, api, etc)

default_config:

Text to speech

tts:

  • platform: google_translate
    sensor:
  • platform: command_line
    name: RPi CPU Temperature
    command: "cat /sys/class/thermal/thermal_zone0/temp"
    value_template: "{{ value | multiply(0.001) | round(2) }}"

binary_sensor:

  • platform: roode
    presence:
    name: $friendly_name Presence
    zones:
    entry:
    presence:
    name: $friendly_name Entry Presence
    exit:
    presence:
    name: $friendly_name Exit Presence

sensor:

  • platform: roode
    zones:
    entry:
    distance:
    name: $friendly_name Entry Distance
    filters:
    - delta: 100
    exit:
    distance:
    name: $friendly_name Exit Distance
    filters:
    - delta: 100
    threshold_entry:
    name: $friendly_name Zone 0
    threshold_exit:
    name: $friendly_name Zone 1
    roi_height:
    name: $friendly_name ROI height
    roi_width:
    name: $friendly_name ROI width

number:

  • platform: roode
    people_counter:
    name: People Count

group: !include groups.yaml
automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml

Can you please describe to me how it works correctly?
Thank you very much

Adaptive threshold

Because the sensor is kind of sensible to temperature and sunlight (940nm) it makes sense to implement an adaptive threshold mechanism.

That mechanism should adapt the current thresholds by continuously calculating the SD on sample data. That way the threshold should be mirror the current situation more reliable

yaml doesn't compile services correctly

Describe the bug
I'm not able to compile the api with the actual settings.

To Reproduce
use following in the yaml:
api:
password: !secret api_password
reboot_timeout: 60min
services:
- service: recalibrate
then:
- lambda: "id(roode_platform)->recalibration();"
- service: set_max_threshold
variables:
newThreshold: int
then:
- lambda: "id(roode_platform)->set_max_threshold_percentage(newThreshold);id(roode_platform)->recalibration();"
- service: set_min_threshold
variables:
newThreshold: int
then:
- lambda: "id(roode_platform)->set_min_threshold_percentage(newThreshold);id(roode_platform)->recalibration();"

Error:
/config/esphome/peoplecountermg.yaml: In lambda function:
/config/esphome/peoplecountermg.yaml:48:23: error: 'class esphome::roode::Roode' has no member named 'set_max_threshold_percentage'
- lambda: "id(roode_platform)->set_max_threshold_percentage(newThreshold);id(roode_platform)->recalibration();"
^
/config/esphome/peoplecountermg.yaml: In lambda function:
/config/esphome/peoplecountermg.yaml:53:23: error: 'class esphome::roode::Roode' has no member named 'set_min_threshold_percentage'
- lambda: "id(roode_platform)->set_min_threshold_percentage(newThreshold);id(roode_platform)->recalibration();"
^
*** [/data/peoplecountermg/.pioenvs/peoplecountermg/src/main.cpp.o] Error 1
========================== [FAILED] Took 2.10 seconds ==========================

It's possible to compile if the lower to services are commented out.
Would be nice for releases to comment them out if they doesn't work.

Thanks

Platform not found: 'text_sensor.roode'

Describe the bug
There seem to be some changes in the text sensor in ESPHome v2022.2.0 (and v2022.2.1), that the platform 'text_sensor.roode' isn't found anymore. If I remove my text sensors, I can update the device.
I assume that it might have something to do with this PR: esphome/esphome#3172

To Reproduce
Steps to reproduce the behavior:

  1. Update ESPHome
  2. Click update on a Roode device with text sensors

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
If applicable, add screenshots to help explain your problem.

Additional context

INFO Reading configuration /config/esphome/az-people-counter.yaml...
INFO Updating https://github.com/Lyr3x/[email protected]
ERROR Unable to load component roode.text_sensor:
Traceback (most recent call last):
  File "/esphome/esphome/loader.py", line 162, in _lookup_module
    module = importlib.import_module(f"esphome.components.{domain}")
  File "/usr/lib/python3.9/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 790, in exec_module
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "/config/esphome/.esphome/external_components/cb683fcf/components/roode/text_sensor.py", line 25, in <module>
    cv.Optional(CONF_ICON, default="mdi:git"): text_sensor.icon,
AttributeError: module 'esphome.components.text_sensor' has no attribute 'icon'
ERROR Unable to load component roode.text_sensor:
Traceback (most recent call last):
  File "/esphome/esphome/loader.py", line 162, in _lookup_module
    module = importlib.import_module(f"esphome.components.{domain}")
  File "/usr/lib/python3.9/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 790, in exec_module
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "/config/esphome/.esphome/external_components/cb683fcf/components/roode/text_sensor.py", line 25, in <module>
    cv.Optional(CONF_ICON, default="mdi:git"): text_sensor.icon,
AttributeError: module 'esphome.components.text_sensor' has no attribute 'icon'
Failed config

text_sensor.roode: [source /config/esphome/az-people-counter.yaml:95]
  
  Platform not found: 'text_sensor.roode'.
  platform: roode
  version: 
    name: AZ PeopleCounter version
text_sensor.roode: [source /config/esphome/az-people-counter.yaml:98]
  
  Platform not found: 'text_sensor.roode'.
  platform: roode
  entry_exit_event: 
    name: AZ PeopleCounter last direction

Battery operated

Hi will this solution work on a battery i am using Home Assistant with ESPHome, if so what type of a battery and also how long do you think it will last. If not... as i am using the D1 mini i wonder if this can be put into deep sleep and use the count trigger to wake up the D1 mini to send the data. Maybe use a ATTiny for the interrupt (i am no expert i have seen someone else use this approach). But i guess the question there is how to trigger the ATtiny from the VL53L1X as the people counting is software. I guess the other issue would be how to get OTA to work, would it be possible to send data back to the controller from ESPHome maybe use that as a way to trigger the update when its awake?

Let me know if this is even a possibility.

FR: Count person in door frame

Is your feature request related to a problem? Please describe.
When you use Roode to control the light, the light only comes on when you are already in the room - so you walk into the darkness.

Describe the solution you'd like
Here a config option "count_person_in_doorframe" or "count_presence_detection" would be handy, which also counts up if a person is only standing in the doorframe and nobody else is in the room.

Describe alternatives you've considered
This is my current workaround. The presence sensor needs an off-delay, because otherwise it can happen that after passing through the door the counter goes from 1 to 0 and back to 1. The off-delay must be on an extra sensor, so that the normal count process is not delayed.
The workaround works, but is IMHO relatively complicated for such an easy and useful feature and can probably be solved more efficiently internally in Roode.

binary_sensor:
  - platform: roode
    presence_sensor:
      name: $friendly_name presence
      id:  presence_sensor
      internal: true
  - platform: template
    id: presence_sensor_delay_off
    internal: true
    lambda: 'return id(presence_sensor).state;'
    filters:
      - delayed_off: 100ms
    on_state:
      then:
        - component.update: number_peoplecounter
      
number:
  - platform: roode
    people_counter:
      id: master_peoplecounter
      internal: true
      on_value:
        then:
          - component.update: number_peoplecounter
  - platform: template
    name: $friendly_name
    id: number_peoplecounter
    min_value: 0
    max_value: 1000
    icon: "mdi:counter"
    step: 1
    lambda: |-
      if(id(presence_sensor_delay_off).state && id(master_peoplecounter).state == 0) { return 1; } 
      else{ return id(master_peoplecounter).state; }
    set_action:
      then:
        - number.set:
            id: master_peoplecounter
            value: !lambda "return x;"

Additional context
Add any other context or screenshots about the feature request here.

Manual sensor mode

If not using the calibration feature a user should be able to set the sensor mode manually

Random disconnects of the ESPHome API

Describe the bug
When controlling Roode from HA it come sometimes to an disconnect after a command is sent

To Reproduce
Steps to reproduce the behavior:
Sent recalibrate command

Expected behavior
Recalibration occurs, but after the recalibration started the esp disconnects for a few seconds

Discord link is expired

Describe the bug
The Discord invitation is expired in the readme file

To Reproduce
Steps to reproduce the behavior:
Click the discord button

Expected behavior
That the link is still valid.

Add max range mode

Is your feature request related to a problem? Please describe.
Currently the timing and inbetween times are set to be as fast as possible. However, this leads to a maximum usable range of 3.2m

Describe the solution you'd like
A config parameter which activates may range mode is added which modifies the timings to achieve the maximum of 4m

How do I add multiple i2c bus?

I'm trying to use Roode in my ESP32 and it works very good, but I also need to add an BH1750 Illuminance sensor which need i2c bus too, when I'm trying to define the i2c bus for both Roode and BH1750 I got this error note 'Too many candidates found for 'i2c_id' type 'i2c::I2CBus'', and if I only define the i2c bus for one device, then only the defined one will work.
So how could I use multiple i2c devices while I'm using Roode.
Thanks

Below is part of my .yaml
i2c:

  • sda: 21
    scl: 22

  • id: bus_a
    sda: 2
    scl: 15

vl53l1x:
roode:

sensor:

  • platform: bh1750
    name: "BH1750 Illuminance"
    address: 0x23
    i2c_id: bus_a
    update_interval: 2s

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.