For a "poor man's ambilight with smart bulp": Is there a way to calculate the average of a color (over time) in Home Assistant? Aka smooth colors? #2040
rugk
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Use case
I use Hypherion/HypherHDR (a fork of Hypherion) with a custom HACS Hyper-HA integration to get the average color of my TV screen.
Now, the aim is to do a poor mans ambilight with just a smart light that shines somewhat the correct light.
Of course, this is more of a fun project and to test out whether that is actually useful or how it works. Of course, I totally see and would recommend to use a proper LED stripe and directly let it control via that. But well… here we go for just a ambient room I may say. 🙃
But well… maybe with the right tuning it turns out to be useful. 😅
Approach
The integration exposes the "average screen color" already as a HEX value:

I guess that is most useful to use here.
Code so far
With some AI help and trying out stuff, I was able to generate some working automation:
This works surprisingly well already, though one can often feel it "lags behind" the TV image. As indicated above, I already added some "smoothing". To properly do that over longer time spans without wild color changes, "smoothing" over a longer time span would be needed. Aka, mathematically speaking, calculating the average of the color over time?
In my imagination, this would capture the "scene" over a longer period of time, maybe even dunno, the last, 10 seconds or so? Then a nature documentary in a jungle would be primarily green while something else would be different.
As said, it's kind of an experiment. 😅
Question
Now obviously Home Assistant does have an average function: That said, again obviously, calculating an average of a color obviously is harder, but possible. Apparently, depending on the color space/representation you use, there are also a lot of different algorithms.
Cross-posted here from the HA community as the community here might be interested about this too. 🙃 Or have some ideas/insight into that.
All reactions