I’m building an indicator that sets a red, yellow, or green light to illuminate depending on the state of a distance sensor. I have that part working well, but what I’d like to do is to only enable the leds when the light to that room is on in Home Assistant so the leds aren’t on all day or night long when no one is there. Here’s my yaml where I’m having trouble getting the switch value from Home assistant, can anyone point me in the right direction to get this working? Thanks
esphome:
name: dust-collector-level
esp8266:
board: d1_mini
# Enable logging
logger:
# Enable Home Assistant API
api:
encryption:
key: "111111111111111="
ota:
password: "11111111111"
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Dust-Collector-Level"
password: "11111111"
web_server:
port: 80
time:
- platform: homeassistant
id: homeassistant_time
captive_portal:
i2c:
globals:
- id: led_enabled
type: bool
restore_value: no
initial_value: "false"
switch:
- platform: restart
name: "dust-collector-level Restart"
light:
- platform: binary
name: dust-light-green
output: dust_light_output_g
id: light_green
- platform: binary
name: dust-light-yellow
output: dust_light_output_y
id: light_yellow
- platform: binary
name: dust-light-red
output: dust_light_output_r
id: light_red
output:
- id: dust_light_output_g
platform: gpio
pin: D5
- id: dust_light_output_y
platform: gpio
pin: D6
- id: dust_light_output_r
platform: gpio
pin: D7
sensor:
- platform: uptime
name: dust-collector-level Uptime
- platform: wifi_signal
name: dust-collector-level WiFi Signal
update_interval: 60s
- platform: homeassistant
id: led_switch
entity_id: switch.garage_light
internal: false #switch this to true once it's working
on_value:
then:
- globals.set:
id: led_enabled
value: !lambda return id(led_switch).state;
#I'm getting an error grabbing the value here
- platform: vl53l0x
name: dust-collector-level-fill
id: dc_measure_level
update_interval: 1s
filters:
- sliding_window_moving_average:
send_every: 5
window_size: 10
on_value:
then:
- if:
condition:
lambda: |-
return id(led_enabled).state == false;
then:
- light.turn_off: light_red
- light.turn_off: light_yellow
- light.turn_off: light_green
else:
- if:
condition:
lambda: |-
return id(dc_measure_level).state > 0.35;
then:
- light.turn_off: light_red
- light.turn_off: light_yellow
- light.turn_on: light_green
else:
- if:
condition:
lambda: |-
return id(dc_measure_level).state < 0.18;
then:
- light.turn_off: light_green
- light.turn_off: light_yellow
- light.turn_on: light_red
else:
- light.turn_off: light_green
- light.turn_off: light_red
- light.turn_on: light_yellow
text_sensor:
- platform: version
name: dust-collector-level ESPHome Version
- platform: wifi_info
ip_address:
name: dust-collector-level IP
ssid:
name: dust-collector-level SSID
bssid:
name: dust-collector-level BSSID