Esphome: RGBLed not changing color when in same range

Hi Guys,

I tried to build a simple temperature and humidity-sensor with an integrated status LED to read out the current humidity-state with a single color.
green: ok
yellow: meh
red: too high

In the beginning I noted that the LED keeps the color it had on bootup, which might be problematic for many reasons. Therefore I added a “bootstate color” to indicate that it is not ready yet and to prevent a “frozen” state which might lead to misunderstandings for example.

My Issue:

In my case it does not change back the color it had before blue, if the value_range is the same before the boot.
It seems to look like my value range does not change and therefore it does not trigger the service calls.
If it suddendly changes the range, the other colors are triggered without a problem.

Is there any way to “reset” the value_range or even force the sensor to retrigger?

esphome:
  name: esp-temp-humidity
  friendly_name: esp_temp_humidity

  on_boot:
    priority: 550
    then:

      - light.turn_on:
          id: humidity_led_state
          brightness: 40%
          red: 0%
          green: 0%
          blue: 100%

esp8266:
  board: esp01_1m

# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: "---"

ota:
  password: "---"

wifi:
  ssid: "---"
  password: "---"

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: ""---""
    password: "---"

captive_portal:



light:
  - platform: rgb
    name: "RGB LED"
    id: "humidity_led_state"
    red: output_red
    green: output_green
    blue: output_blue


output:
  - platform: esp8266_pwm
    id: output_red
    pin: GPIO14
  - platform: esp8266_pwm
    id: output_green
    pin: GPIO12
  - platform: esp8266_pwm
    id: output_blue
    pin: GPIO13



sensor:
  - platform: dht
    pin: GPIO16
#    model: dht22
    temperature:
      name: "Multisensor Temperature"


    humidity:

      name: "Multisensor Humidity"
      id: multisensor_humidity
      on_value_range:

        - below: 55
          then:
            - light.turn_on:
                id: humidity_led_state
                brightness: 40%
                red: 0%
                green: 100%
                blue: 0%
        - above: 55
          then:
            - light.turn_on:
                id: humidity_led_state
                brightness: 40%
                red: 100%
                green: 100%
                blue: 0%
        - above: 60
          then:
            - light.turn_on:
                id: humidity_led_state
                brightness: 40%
                red: 100%
                green: 0%
                blue: 0%
    update_interval: 10s

I couldnt find anything else in the docs.
I also searched for threads but noone seems so have this issue at all.
Thanks.

You need to add a “below” value if there is a next above, otherwise you have an “open range” and that is valid from the above value till infinity :slight_smile: See also: Sensor Component — ESPHome

Thanks for your reply, but the problem is NOT the switching between the colours green (G) yellow (Y) red (R).
I make an example:

I currently have 54% which is GREEN - now i reboot → it becomes BLUE → after boot the sensor needs some time and records 54% again (which is in the “green range”) and it still stays blue.


IF it would have been 61, it would have easily changed to YELLOW, but it looks like it wont change when the range stays the same.

I also changed the config and made it rockroslid to prevent an “open range”

sensor:
  - platform: dht
    pin: GPIO16
#    model: dht22
    temperature:
      name: "Multisensor Temperature"


    humidity:

      name: "Multisensor Humidity"
      id: multisensor_humidity
      on_value_range:

        - above: 1  # <---- added
          below: 55
          then:
            - light.turn_on:
                id: humidity_led_state
                brightness: 40%
                red: 0%
                green: 100%
                blue: 0%
        - above: 55
          below: 60  # <---- added
          then:
            - light.turn_on:
                id: humidity_led_state
                brightness: 40%
                red: 100%
                green: 100%
                blue: 0%
        - above: 60
          below: 100  # <---- added
          then:
            - light.turn_on:
                id: humidity_led_state
                brightness: 40%
                red: 100%
                green: 0%
                blue: 0%
    update_interval: 10s

To verify my “ranges/triggers” are working, I blowed into the sensor to make humidity skyrocket, forcing the sensor to go to the “red range”:

[18:40:35][D][dht:048]: Got Temperature=22.7°C Humidity=66.0%
[18:40:35][D][sensor:126]: 'Multisensor Temperature': Sending state 22.70000 °C with 1 decimals of accuracy
[18:40:35][D][sensor:126]: 'Multisensor Humidity': Sending state 66.00000 % with 0 decimals of accuracy
[18:40:35][D][light:035]: 'RGB LED' Setting:
[18:40:35][D][light:050]:   Brightness: 40%
[18:40:35][D][light:057]:   Red: 100%, Green: 0%, Blue: 0%
[18:40:35][D][light:084]:   Transition length: 1.0s
[18:40:45][D][dht:048]: Got Temperature=24.6°C Humidity=76.0%
[18:40:45][D][sensor:126]: 'Multisensor Temperature': Sending state 24.60000 °C with 1 decimals of accuracy
[18:40:45][D][sensor:126]: 'Multisensor Humidity': Sending state 76.00000 % with 0 decimals of accuracy
[18:40:55][D][dht:048]: Got Temperature=24.5°C Humidity=76.0%

Now I waited a bit and humidity is normalizing:

[18:42:35][D][sensor:126]: 'Multisensor Temperature': Sending state 22.30000 °C with 1 decimals of accuracy
[18:42:35][D][sensor:126]: 'Multisensor Humidity': Sending state 60.00000 % with 0 decimals of accuracy
[18:42:35][D][light:035]: 'RGB LED' Setting:
[18:42:35][D][light:050]:   Brightness: 40%
[18:42:35][D][light:057]:   Red: 100%, Green: 100%, Blue: 0%
[18:42:35][D][light:084]:   Transition length: 1.0s
[18:42:45][D][dht:048]: Got Temperature=22.3°C Humidity=58.0%
[18:42:45][D][sensor:126]: 'Multisensor Temperature': Sending state 22.30000 °C with 1 decimals of accuracy
[18:42:45][D][sensor:126]: 'Multisensor Humidity': Sending state 58.00000 % with 0 decimals of accuracy

Now I waited a bit and humidity is normalizing to green

So it is def. not a problem of the ranges

Found a fix for this.
I just added a “reset” lambda Call which turns the sensor to 0%.
I made it somehow “fancy” and added a cycle of colors to it:

esphome:
  name: esp-temp-humidity
  friendly_name: esp_temp_humidity

  on_boot:
    priority: 600
    then:

      - light.turn_on:
          id: humidity_led_state
          brightness: 40%
          red: 0%
          green: 100%
          blue: 0%

      - delay: 1s

      - light.turn_on:
          id: humidity_led_state
          brightness: 40%
          red: 100%
          green: 100%
          blue: 0%

      - delay: 1s

      - light.turn_on:
          id: humidity_led_state
          brightness: 40%
          red: 100%
          green: 0%
          blue: 0%

      - delay: 1s

      - light.turn_on:
          id: humidity_led_state
          brightness: 40%
          red: 0%
          green: 0%
          blue: 100%
      - lambda: |-
          id(multisensor_humidity).publish_state(0);
      - delay: 1s

I then also added a “state” for 0% for blue

    humidity:

      name: "Multisensor Humidity"
      id: multisensor_humidity
      on_value_range:
        - below: 1
          then:
            - light.turn_on:
                id: humidity_led_state
                brightness: 40%
                red: 0%
                green: 0%
                blue: 100%