esphome / esphome/feature-requests

multiple VL53L0X sensors

Open
#738 60 comments 5 reactions 0 assignees View on GitHub
component: sensor component: vl53l0x good first issue
Dominant language
No language data
Stars
450
Forks
29
PR merge metrics
No merged PRs in 30d

Description

**Describe the problem you have/What new integration you would like**

I would like to support 2 or more VL53L0X sensors

**Please describe your use case for this integration and alternatives you've tried:**

There might be two way to do this:
1. **Put two (or more) VL53L0X sensors on the same i2c bus**: but currently this is not possible as they would have the same address. The VL53L0X supports address change, but this would require disabling one both sensors via the SXHUT pin, and then enabling one sensor at a time and changing its address before enabling the next one. Currently it looks like ESPHome does not support the XSHUT pin.
2. **Put two (or more) sensors on separate i2c buses**: I tried this but it seems like the current release doesn't support more than 1 instance of the sensor. I say this because when I try to read both sensors synchronously (same _update_interval_), I can only read one at a time, and when thry to read them asynchronously (different _update_interval_), they assume the same value even though they should not. Correct me if I am wrong.

**Additional context**

VL53L0X is not necessarily very precise but I see it is often used as a presence sensor or beam break sensor alternative.
I want to use two of them to make a "door direction sensor" (please have mercy, I don't know how they are called XD). Here is a "high quality" picture to explain what I want to do: after a person crosses the two sensors in one direction a message is sent to Home Assistant (or any automation hub) to notify that a person has "changed room".
![image](https://user-images.githubusercontent.com/65572579/82389799-53edd700-9a3d-11ea-918f-0b7d1d3c1869.png)

This is my yaml: I made so that the sensor value is saved in a template sensor as a binary value. Sometimes the VL53L0X reads "0": in that case the lambda function does not update the value (I had issues with _return {};_)
```
esphome:
name: door_sensor
platform: ESP8266
board: d1_mini

wifi:
ssid: "SSID"
password: "PASS"

# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Door Sensor Fallback Hotspot"
password: "fbksfmcaOX2x"

web_server:

captive_portal:

# Enable logging
logger:
# level: DEBUG
# logs:
# vl53l0x: ERROR
# sensor: ERROR

# Enable Home Assistant API
api:

ota:

i2c:
- id: bus_a
sda: D2
scl: D1
scan: True
- id: bus_b
sda: D6
scl: D7
scan: True

sensor:
- platform: template
name: "Template Sensor 1"
id: template_sens_1
update_interval: 100ms
on_value:
- then:
- logger.log:
format: "sens1 = %d"
args: ['id(template_sens_1).state']
tag: 'AAA'

- platform: template
name: "Template Sensor 2"
id: template_sens_2
update_interval: 100ms
on_value:
- then:
- logger.log:
format: "sens2 = %d"
args: ['id(template_sens_2).state']
tag: 'BBB'

- platform: vl53l0x
name: "Sensor 1"
id: sens_1
i2c_id: bus_a
address: 0x29
update_interval: 70ms
signal_rate_limit: 1
on_value:
- sensor.template.publish:
id: template_sens_1
state: !lambda |-
if (id(sens_1).raw_state == 0) {
return id(template_sens_1).state;
} else if (id(sens_1).raw_state > 0) {
return 1;
} else {
return 0;
}

- platform: vl53l0x
name: "Sensor 2"
id: sens_2
i2c_id: bus_b
address: 0x29
update_interval: 90ms
signal_rate_limit: 1
on_value:
- sensor.template.publish:
id: template_sens_2
state: !lambda |-
if (id(sens_2).raw_state == 0) {
return id(template_sens_2).state;
} else if (id(sens_2).raw_state > 0) {
return 1;
} else {
return 0;
}
```
Thanks for all your great work! ;)

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.