I have a sensor that I have made up in ESPhome in this I have a dht22 to give me temp and humidity, I have also added a RGB LED and what I am trying to do is have the colour of the LED change depending on the temp of the room.
I know the LED is working as I can control it within Home assistant but I am trying to get it to work without home assistant if possible.
this is the first time I am trying to do anything like this in ESPhome and I am probably missing something really simple but I cant for the life of me see it.
Can you post your full yaml (specially the light: part in your case).
Also what does your esphome logs show? You can probably “force” a temperature change by covering the sensor with your hands to force it to heat up to the next value you have configured and monitor the logs at the same time…
I got a lot of help to create this and have used some stuff I found on the forums so I can’t take credit for the work you see, I’ve also removed some wifi details but all the rest is there.
I did this today using Claude AI, here’s working yaml that blends from blue to red for 15c - 28c, adjust as needed. You’ll need to change id, entity names, etc.
- id: '<insert your id here>'
alias: Change WLED Color Based on Temperature
description: Changes WLED color based on room temperature reading
trigger:
- platform: state
entity_id: sensor.mydht22_temperature
- platform: time_pattern
seconds: /10
action:
- choose:
- conditions:
- condition: numeric_state
entity_id: sensor.mydht22_temperature
below: 15
sequence:
- target:
entity_id: light.wled
data:
effect: solid
brightness: 128
rgb_color:
- 0
- 0
- 255
action: light.turn_on
- conditions:
- condition: numeric_state
entity_id: sensor.mydht22_temperature
above: 28
sequence:
- target:
entity_id: light.wled
data:
effect: solid
brightness: 128
rgb_color:
- 255
- 0
- 0
action: light.turn_on
default:
- target:
entity_id: light.wled
data:
effect: solid
brightness: 128
rgb_color: '{% set temp = states(''sensor.mydht22_temperature'')
| float %} {% set normalized = (temp - 15) / (28 - 15) %} {% set red = (normalized
* 255) | int %} {% set blue = ((1 - normalized) * 255) | int %} [{{ red
}}, 0, {{ blue }}]
'
action: light.turn_on
The problem is that this is an esphome group where people are typically seeking esphome based solutions.
You may say, “well, this HA automation works so who cares?” and thats true, it may work fine but, the problem is the temp sensor and RGB light are both running from the esp board while light effects and automations are somewhere else.
Its generally not the best idea to split things up like that, especially when the effects/automations can be run from the esp board and you can keep the esp board as a standalone device that’s not dependent on HA.
Sorry for the delay in replying to you, I did get it working and posted the full working Yaml file but the part that does the colour changing (that suits my needs) is this