Colour Names to HS values

I’m trying to convert a familiar human readable colour name (like ‘Red’) into HS values.

All the logic is sitting in HA core (https://github.com/home-assistant/core/blob/af5fd74d6f936b159dd06cd19770110ea0dd3d7e/homeassistant/util/color.py) but I cant see a way of getting at it from automation or script land…

A (very hacky) workaround (that I’m using) is to create a template light, set it’s colour with light.turn_on and specify the colour_name then read back the hue/sat values. The problem with that is it clearly creates a race condition on reading the values if you overuse this mechanism - and I really don’t want to create a whole bunch of fake lights per possible context.

The use case that I’m trying to solve is a colour is selected (by a human) from the usual CSS colour names (which work in all sorts of front end interfaces and can be spoken and read back through tts) - that is passed to a script that then mathematically manipulates colours to create interesting lighting effects across a group of lights (say by graduating them, or rotating them around a colour space).

Anyone have any suggestions - I could rewrite the colour.py logic at script-level (either through a template sensor or directly in a script with some helpers to capture the return value) - but that feels like a waste of time when it’s all sitting there inside HA :slight_smile:

or have I just reached the point where I need to get out the python scripts and go play inside HA somehow?

Great Idea…
Perhaps do a feature request for it?

There may be opportunities to build this into a custom jinja template or a blueprint to share it to others as well.

Update, I actually did that and released it the end of November now. Link to my Color-Multi-Tool at the bottom of this message.here.

Me too. Name to RGB or HS.

I was pointed at this: 🧯 Color-Multi-Tool
… I liked the approach but ended up doing my own version with more colours and slightly different logic - and a bit simpler to use: GitHub - Colour-Map
Still think this should be exposed via some HA primitives.

1 Like

Cool. You inspired me, and I inspired you back. Love when things work out.
I moved this topic to be a Feature request. And I voted for it. Native would be nicer for sure.

1 Like