Hi everybody,
I recently got into AppDaemon
and already love how much simpler it makes things. I would call myself a beginner at best when it comes to Python, yet I’d like to try writing a few simple scripts myself - which seems to be harder than I expected.
The ad-media-lights-sync script enables us to use “some” color from the currently playing track of a media_player
entity as color for a light
entity, which is pretty awesome. However, I do not like the way the script actually defines the color (hence I emphasized “some” color). For example, if the current song has a corresponding cover image that is mostly blue, but has some red parts in the center of the image, this script might use red as the color value, not blue. I would prefer to use the dominant color, even if it is not in the center of the image.
I wrote a little python script that will do just this
from colorthief import ColorThief
import sys
# for local testing: pass file to use as command line parameter
datei = sys.argv[1]
# global variable to use color values (ergebnis) outside the function
glob_ergebnis = 0
def klau_farbe():
color_thief = ColorThief(datei)
ergebnis = color_thief.get_color()
global glob_ergebnis
glob_ergebnis = ergebnis # could have written to this straight away, but writing this script was a process ;)
klau_farbe()
print(glob_ergebnis)
When I use this image (amazon direct link to image file), the script will output (31, 96, 77)
; this looks about right (though I actually expected something orange-ish instead of green/mint, but it is still a realistic value considering the original image).
Would somebody be so kind to get me started how I’d have to construct an AppDaemon script that will do the following (assuming similar configuration in apps.yaml
as ad-media-light-sync):
- query current cover image from
media_player
entity - run my script above on this image
- write the output to something like
sensor.klau_farbe
(just as a test, later this value should be used directly via the appdaemon script and set the light entity accordingly)
Unfortunately, I cannot just read the linked script from above and know how to do this (as I said, python beginner here). It is too much and too complex (and yeah, I can see that it is only a few lines, but still ) for me to adapt it to what I need.
But hopefully, if somebody can help me here, I can build on that and then create a script that will work similar to the one linked above. I would like to implement things that the creator of the original script is not planning on integrating in their script, so I am not trying to rebuild an existing solution - I want to modify this solution to my needs (of course I’d still share it if anybody is interested once it is done).
Thank you for your help