LED Bar Combo in ESPHome

In ESPHome, I just implemented a new Combo Bar option for the LEDs, where it uses different segment to indicate the CO2, PM2.5 and VOC levels, as well as an option to have the bars fade out to the side. If interested, check out the latest ESPHome config
MallocArray/airgradient_esphome: ESPHome definition for an AirGradient DIY device to send data to HomeAssistant and AirGradient servers (github.com)

4 Likes

That’s very interesting, thanks for your work.
I am using your code from some months ago (December 2023) to control each LED to have a color representation of the CO2 level.
If level < 800, then all LED green.
If 800 < level < 818, then the first LED goes to orange.
If 818 < level < 836, then the second LED goes to orange.
And so on until 1000 < level all LED become orange.
Then if the CO2 level keep increasing, the first LED becomes red and then the second…

It is very useful to know which just a glance the current CO2 level. And you can see the effect of each LED changing color one by one when we are too many in the same room.

However my current code is very cumbersome.
I am wondering if coding such a similar behavior would be much easier with your current code ?

Thanks again

@MallocArray it looks great. Actually we just discussed something similar internally for our stock firmware a couple of days ago.

Did you consider also adding NOx?

I’m not sure where/how to also reflect NOx. Could do 3 for CO2 and PM2.5, and then 1 for VOC and NOx, but not sure if I like that.
I’ve only ever seen NOx go above 1 for a series of 3 nights in my Outdoor sensor, and never on my indoor ones (no gas stove) and not sure what levels would be indicative of an issue.

You could take a look at how I’m doing it and see if it would be any more efficient than what you have, but right now I’m not thinking of a formula that would do what you described in 3 or less conditions.
With what I have done, it is figuring a percentage of how close you are to the stated level and then blending the colors, so if you are halfway between a set level, then it turns lights on 50%

With yours, I think you would still have to have a condition for each of those events, but depending on how you are accomplishing it, the light.addressable_set and specifying the range of LEDs you are wanting.

But maybe you could come up with a formula something like

  • set all LEDs to green
  • Set color to Yellow but the range_to number is based on a formula that would take the CO2 level and return a whole number between 1 and 10. Copilot suggested return 1.0 + (co2 - 800.0) / 20.0; but that would need to make sure it was a whole number and not sure what happens once you are higher than 1000
  • Do a similar thing for color Red and a formula for range_to at your desired level