Hi All,
I made an RGB-clock that is accessible through REST-commands to set foreground-color, background color, extra modes, brightness and some other settings. I already made a rest-API that seems to be working that is currently linked to an input_number for brightness and the background-color.
The background color is represented as RGB number: 0xRRGGBB
.
Currently, I’m trying to put the entire clock as one light entity. I already managed to link the on/off and brightness settings to it but I’m currently trying to wire up the background color. It seems the Template Light can only accept Hue and Saturation so to comply to these rules, I’m trying to convert my RGB-integer to an HS-tupple. I’ve found some usefull functions to convert RGB to HS(V) but it seems I can’t access them through the templates.
Anyone have any idea if it’s possible to access these functions? Or any idea how I can make this more efficient in the first place (instead of using RGB-to-HSV conversion etc)? Open for any suggestions!
my current template-light looks like this:
light:
- platform: template
lights:
clock_light:
friendly_name: "Clock"
value_template: "{{ is_state('switch.bf6b12fc4fc285cd3e6hhm', 'on') }}"
level_template: "{{ states('input_number.clock_brightness') | int }}"
color_template: "{{ homeassistant.util.color.color_RGB_to_hs( '0x{r:02X}{g:02X}{b:02X}'.format( states('input_number.clock_background_color') ) ) }}"
turn_on:
- service: switch.turn_on
entity_id: switch.bf6b12fc4fc285cd3e6hhm
turn_off:
- service: switch.turn_off
entity_id: switch.bf6b12fc4fc285cd3e6hhm
set_level:
service: input_number.set_value
data:
value: "{{ brightness }}"
entity_id: input_number.clock_brightness
set_color:
- service: input_number.set_value
data:
value: "{{ '0x{r:02X}{g:02X}{b:02X}'.format( color_hs_to_RGB( h, s ) ) | int(base=16) }}"
entity_id: input_number.clock_background_color
Also notice the color_template still has the entire path to the helper function but the set_value only has the function itself. This is because I already tested removing the keywords in front of the function.