Can you add gesture control to the VL6180?
Opened this issue · 2 comments
There is an example with WLED here https://github.com/Aircoookie/WLED/blob/main/usermods/VL53L0X_gestures/usermod_vl53l0x_gestures.h
Can you add these functions as well? Basically like:
swipe under the sensor turn on/off
pause under the sensor up and down for dimming brightness on an LED pwm strip etc
anything else fun you can think of for a gesture?
Thank you.
I'm not quite sure if I understand your request.
Do you want me to add support for the VL6180 sensor to WLED? If so, then I would suggest to ask for this on the WLED Github page.
Or, do you want to implement gestures in an ESPHome device with the VL6180 sensor? In this case, I would probably not add this to this custom component, because gestures should sit on a higher software layer. This custom component provides the raw distance value, and you would then use automations in ESPHome to detect gestures. For example, you could add a template binary sensor that uses the distance value to determine its own on/off state.
The later,
Had a go with some nudges from ssieb
esphome:
name: t-energy-008
friendly_name: T-Energy-008
includes:
- "vl6180x_sensor.h"
libraries:
- SPI
- Wire
- adafruit/Adafruit BusIO @ 1.9.6
- "Adafruit_VL6180X"
esp32:
board: esp32dev
framework:
type: arduino
# Enable logging
logger:
#psram:
# mode: quad
# speed: 40MHz
# Enable Home Assistant API
api:
encryption:
key: !secret encryption_key006
ota:
password: !secret ota_pass006
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
use_address: !secret use_address_wifi006
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "T-Energy-008 Fallback Hotspot"
password: !secret fallbackhotspot006
captive_portal:
web_server:
i2c:
sda: 21
scl: 22
#id: bus_a
output:
- platform: ledc
pin: GPIO19
id: led_output
#frequency: 19531Hz
light:
- platform: monochromatic
name: "Gesture Controlled Light"
output: led_output
id: gesture_light
sensor:
- platform: custom
lambda: |-
auto vl6180x_sensor = new VL6180XSensor();
App.register_component(vl6180x_sensor);
return {vl6180x_sensor->distance_sensor};
sensors:
- name: "VL6180X Distance"
unit_of_measurement: mm
accuracy_decimals: 0
id: distance_sensor
filters:
- filter_out: nan
on_value:
then:
- if:
condition:
lambda: 'return id(gesture_brightness).state;'
then:
- lambda: |-
// Map the distance range to brightness range
float brightness = (200 - id(distance_sensor).state) * (255.0 / 160);
id(led_output).set_level(brightness);
- homeassistant.service:
service: light.turn_on
data:
entity_id: light.sengled_e11_n1ea_light_2
brightness: !lambda "return (int)((1 - ((id(distance_sensor).state - 40) / (160))) * 255);"
- if:
condition:
lambda: 'return !id(gesture_brightness).state && (id(distance_sensor).state < 40);'
then:
- homeassistant.service:
service: light.toggle
data:
entity_id: light.sengled_e11_n1ea_light_2
binary_sensor:
- platform: template
name: "Gesture On/Off"
id: gesture_on_off
lambda: 'return !id(gesture_brightness).state && (id(distance_sensor).state < 40);'
- platform: template
name: "Gesture Brightness Control"
id: gesture_brightness
# Hand is within the sensor range for more than 2 seconds
filters:
- delayed_on_off:
time_on: 3s
time_off: 4s
lambda: 'return (id(distance_sensor).state <= 190 && id(distance_sensor).state >= 40);'
Any way for you to get this sensor wrapped into https://esphome.io/components/sensor/vl53l0x.html
Thank you.