Enable or disable custom sensor polling programatically

Hello,

I am converting a Ikea manual adjustable hight desk to an electric one. In short i’m controlling a motor with a relay and using a VL53L1X as height sensor, to both sense when the end stops are reached but also to be able to store positions.

The distance sensor is read by a custom sensor called like this in ESPHome.

sensor:
  - platform: custom
    lambda: |-
      auto my_VL53L1X_sensor = new VL53L1XCustomSensor();
      my_VL53L1X_sensor->set_update_interval(100); // define update interval
      App.register_component(my_VL53L1X_sensor);
      return {my_VL53L1X_sensor};
    sensors:
      id: height_sensor
      name: "Distance"
      accuracy_decimals: 0
      unit_of_measurement: "mm"
      internal: true 

I feel like its unneccesary for the sensor to keep polling at 100ms perodicity when the desk is not moving. So I was wondering if anyone has an idea on what I can do to only poll the sensor value when the motor is engaged?

How come you’re not just using the native component?

You can try to get the hardware standby working.

I could get it to shut down but not wake up again.

You could also check if you could power it via a gpio pin and user that as a switch (I think you can do that but not 100%).

I would also be planning for the situation when the tof fails/is unresponsive… I’ve had that happen with these sensors a little. Either add extra endstops, max timeouts, or only move if recent distance received etc.

Thanks, I tried that component but it does not seem to work for VL53L1X. I can get the sensor to go to sleep. My question was more how to stop the ESP function to stop polling for data.

1 Like

Right yes I see now.

I don’t really know.

I do know that you can set updates to “never” and just call them manually, so maybe you could do something with that? I don’t know if it’s relevant for your component though.

I do it here.

Thanks I’ll check it out.