本帖最后由 dianxin11 于 2024-4-13 22:23 编辑
比较简单,就不详细介绍了。
大致逻辑就是通过VL53L0X判断写字台前是否坐人,然后通过mos开关控制led灯开关。
substitutions:
device_name: "vl53l0x01"
esphome:
name: ${device_name}
friendly_name: ${device_name}
esp8266:
board: esp01_1m
# Enable logging
logger:
# Enable Home Assistant API
api:
encryption:
key: ""
ota:
password: ""
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Vl53L0X01 Fallback Hotspot"
password: ""
captive_portal:
# Enable I²C bus
i2c:
sda: 4
scl: 5
switch:
- platform: gpio
name: "Light Switch"
id: light_switch
pin: 14
sensor:
- platform: vl53l0x
name: "VL53L0x Distance"
address: 0x29
update_interval: 1s
long_range: true
id: sensor_1
filters:
- lambda: !lambda |-
if(isnan(x)) return 100;
return x;
- throttle_average: 5s
- platform: template
name: "Distance everage"
update_interval: 5s
lambda: |-
ESP_LOGD("main", "everage value is %f", id(sensor_1).state);
return (id(sensor_1).state);
on_raw_value:
- if:
condition:
lambda: return x > 90;
then:
- switch.turn_off: light_switch
- if:
condition:
sensor.in_range:
id: sensor_1
below: 2.0
then:
- switch.turn_on: light_switch
|