Time of Flight sensor on ESPHome?

Is there any way to use a time of flight sensor like the VL53L1X via an ESPHome-flashed NodeMCU? I know HA now has native support for this sensor, but that requires a physical connection between the sensor and the HA server. I have an application where this type of sensor would be great, but it’s remote from the server (plus my server isn’t an RPi anyway, so no easy way to connect i2c) so I need to be able to send the data over wifi in some way.

Could the generic i2c sensor platform be used in ESPHome and then the the data be parsed at the HA end? Or would a custom platform have to be written?

1 Like

Why not use MQTT?

From what I can see any howto on this chipset uses an arduino library from the likes of polulu or sparkfun. I would think that you would need to include that library ie as a custom component.

If that is beyond you (and it is certainly beyond me) perhaps a feature request here? https://github.com/esphome/feature-requests/issues

So the D1 Mini with ESPHome does have i2c support. You specify the pins in the YAML. Unfortunately, I can’t get the D1 Mini to flash once I set up the YAMl.

During flashing this is all I get:
image

Documents on i2c for ESPHome:


Time of flight sensor:

The spec sheet on the TOF sensor shows that the address is: 0x52 so I have that set in my ESPHome YAML.


i2c:
  sda: D2
  scl: D3
  scan: True

sensor:
  - platform: vl53l0x
    name: "VL53L0x Distance"
    update_interval: 10s
    address: 0x52

I did see a feature request for another model of the TOF sensor that looks like its being worked on and fairly recently.
https://github.com/esphome/feature-requests/issues/113

and that references this:
https://github.com/esphome/esphome/pull/644

There is someone that posted they got it working with their own code on the first issue so I may give that a shot. Unfortunately I am very new to all the DIY items and this is only my second Arduino project so I very well could be doing something wrong.

Are you sure that first log in your post is during flashing? It looks like flashing has completed and it is now running, albeit with an error.

Try the default i2c address 0x29. There is no answer on 0x59.

Perhaps posting your full log (text, not a picture!!) And your complete yaml might help.

Thanks for the response! I thought I was sure, as the D1 Mini never would connect to wifi, but after trying the code that was posted in the feature request GITHub, I believe your right. His code has a message that clearly shows “Failed to boot VL53L0X”

I also forgot to mention that I went to the dev branch of ESPHome as it looks like that is where the changes were put in place (If I am reading the GITHub info correctly)

I did try with the default 0x29 and got the same message. For transparency, I have the following sensor.
https://www.amazon.com/gp/product/B07Q5Y3G4C/ref=ppx_yo_dt_b_asin_title_o02_s00?ie=UTF8&psc=1

My full YAML:

esphome:
  name: test
  platform: ESP8266
  board: d1_mini

wifi:
  ssid: "WIFIAP"
  password: "Passwords"

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

captive_portal:

# Enable logging
logger:

# Enable Home Assistant API
api:
  password: "Passwords"

ota:
  password: "Passwords"

i2c:
  sda: D2
  scl: D3
  scan: True

sensor:
  - platform: vl53l0x
    name: "VL53L0x Distance"
    update_interval: 10s
    address: 0x29


    

And confirmation that you are right, flashing seems to have went without an issue, boot appears to be the issue:

Using ‘COM4’ as serial port.
Connecting…
Detecting chip type… ESP826 %)Writing at 0x00044000… (100 %)Wrote 414992 bytes (284231 compressed) at 0x00000000 in 6.3 seconds (effective 523.0 kbit/s)…
Hash of data verified.

Leaving…
Hard Resetting…
Done! Flashing is complete!

Showing logs:
[18:53:58][I][logger:156]: Log initialized
[18:53:58][C][ota:364]: There have been 8 suspected unsuccessful boot attempts.
[18:53:58][I][app:028]: Running through setup()…
[18:53:58][W][i2c:070]: Received NACK on transmit of address 0x29
[18:53:58][W][i2c:070]: Received NACK on transmit of address 0x29
… forever and forever

Ultimately I want to replace my very flaky ultrasonic sensor in my water softener tank with this. Its right next to my washer and dryer and when in use, readings go all over.

1 Like

I suspect you shouldn’t be using D3, according to this it is GPIO0

1 Like

I did see some documentation that also said the default is D1 and D2, the way I read the ESP documentation made me think I could pick any.

Ill give that a shot, I was lazy and never soldered D1 to the header… but I am inclined to think this may be the issue.

By the way once you get i2c working the scan should show up something like this, which tells you what addresses it finds other i2c devices on. This is on an esp32, but I imagine it shows scan results on esp8266 as well

[02:18:00][C][i2c:028]: I2C Bus:
[02:18:00][C][i2c:029]:   SDA Pin: GPIO5
[02:18:00][C][i2c:030]:   SCL Pin: GPIO4
[02:18:00][C][i2c:031]:   Frequency: 50000 Hz
[02:18:00][I][i2c:033]: Scanning i2c bus for active devices...
[02:18:00][I][i2c:040]: Found i2c device at address 0x3C
1 Like

You are 100% correct. That was the issue. All is working, thank you very much for the assistance!

[21:21:15][I][i2c:033]: Scanning i2c bus for active devices…
[21:21:15][I][i2c:040]: Found i2c device at address 0x29

[21:22:25][D][sensor:092]: ‘VL53L0x Distance’: Sending state 0.24100 m with 2 decimals of accuracy
[21:22:35][D][vl53l0x:242]: ‘VL53L0x Distance’ - Got distance 0.231 m
[21:22:35][D][sensor:092]: ‘VL53L0x Distance’: Sending state 0.23100 m with 2 decimals of accuracy
[21:22:45][D][vl53l0x:242]: ‘VL53L0x Distance’ - Got distance 0.306 m
[21:22:45][D][sensor:092]: ‘VL53L0x Distance’: Sending state 0.30600 m with 2 decimals of accuracy
[21:22:55][D][vl53l0x:242]: ‘VL53L0x Distance’ - Got distance 0.220 m
[21:22:55][D][sensor:092]: ‘VL53L0x Distance’: Sending state 0.22000 m with 2 decimals of accuracy

Now to see if I can document this better somewhere to assist others! Again, very much appreciated!

Great, and good to see success with esphome. It is a wonderful piece of software. Way easier than trying to jigsaw libraries together yourself.

1 Like

There is always esphome-configs.io

The site has a new URL https://www.esphome-devices.com/

Yes, very much agreed! Its the only reason I had decided to give these DIY sensors a shot. ESPHome has and will make so many things much easier to integrate into HA.

Did not even know esphome-configs.io existed. Will definitely look into adding this info there. Thanks again for the help. I have seen you around, and I am sure your previous posts have definitely help me out as well!

There are far more knowledgeable people than me on here, but I do what I can :slight_smile:

Well, adding to http://esphome-configs.io will take some reading up on exactly how to do it. So, Ill add my working configuration here:

VL53L0X with a D1 Mini

ESPHome YAML:

esphome:
  name: Softener
  platform: ESP8266
  board: d1_mini

wifi:
  ssid: "YourWifiSSID"
  password: "YourWifiPassword"
  manual_ip:
    static_ip: 10.0.0.59
    gateway: 10.0.0.1
    subnet: 255.255.255.0
  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Softener Fallback Hotspot"
    password: "YourPassword"

captive_portal:

# Enable logging
logger:

# Enable Home Assistant API
api:
  password: "YourPassword"

ota:
  password: "YourPassword"

i2c:
  sda: D2
  scl: D1
  scan: True

sensor:
  - platform: vl53l0x
    name: "Water Softener Salt"
    update_interval: 10s
    address: 0x29
    unit_of_measurement: "Inches"
    filters:
      - multiply: 39.37    

as nickrout pointed out, you must use D1 and D2 as those are the SCL and SDA pins (GPIO5 and GPIO4) on the D1 Mini. I did confirm that this works on the production ESPHome and no need to be using the dev version.

2 Likes

Yes this component was in esphome 14.0 release, which is fairly new.

So could we get HA to do what you see in the video in this post?

That would be awesome.

At this moment with current code, no. It’s just possibility which must be programmed “from scratch”(means it’s not just about “movement_direction: enable” option in ESPhome config file).

If the movement direction works though I think we could use the counter component …

This should get us to the next step and a couple automations later we could be there unless I’m misunderstanding something. (Quite possible)
Displaying the info in lovelace may take some more work… haven’t thought about that yet.

Hi.
I use a nodemcu & Arduino IDE to get values from 2 differents VL53L0X sensors with only one I²C Bus (using the Xshut pin and the “vl53l0x_dual” script example by Adafruit). It works great.

I tried to use ESPHome & its awesome integration in hassio to get those 2 sensors values, but was able to get only one value (sensor1), using this code :

sensor:
  - platform: vl53l0x
    name: "sensor1"
    update_interval: 1s
    address: 0x29
  - platform: vl53l0x
    name: "sensor2"
    update_interval: 1s
    address: 0x29

I understand that the 2nd sensor has to have its own adress.
Does anyone know how to set the address of the 2nd sensor using ESPHome ?

Thanks