I’m working on a simple air quality sensor with a “dummy light” for easy reading. When the device boots up, I want the light to turn blue until it finishes its first reading, then it should correspond to the command in the value_range under the sensor.
Unfortunately, it appears that sometimes when the device re-reads, it’s running the on_boot routine again, and switching the light back to blue. Then when the on_value routine runs, but it hasn’t actually moved out of range, the light is just staying blue until the reading moves it into another range. What’s the best way to remedy? Should I just do a nested If-Then on the reading to run commands based on result?
On_boot:
esphome:
name: kk-air-quality-sensor-3
friendly_name: KK Air Quality Sensor 3
on_boot:
priority: 600
then:
#turn on blue light
- light.turn_on:
id: status_light
brightness: 50%
red: 0.0
green: 0.0
blue: 1.0
sensor > on.value
sensor:
- platform: sds011
update_interval: 2min
pm_2_5:
name: "PM 2.5µm"
id: "pm25"
filters:
offset: 1 #this was to test issues coming from a 0 value
on_value_range:
- above: 0.0
below: 11.9
then:
#green
- light.turn_on:
id: status_light
brightness: 50%
red: 0.0
green: 1.0
blue: 0.0
- above: 12
below: 34.9
then:
#yellow
- light.turn_on:
id: status_light
brightness: 50%
red: 1.0
green: 1.0
blue: 0.0
- above: 35
below: 54.9
then:
#orange
- light.turn_on:
id: status_light
brightness: 50%
red: 1.0
green: 0.65
blue: 0.0
#etc, etc, etc