Cheerlights Integration

I’m trying to get a light to change colour in sync with Cheerlights ( and although I have a sensor configured to see wheat the resent hex colour is, I would appreciate any guidance as to how I may convert that to RGB values.

My local MQTT server is connected to the cheerlights feed and makes it available locally. I put this into the Mosquitto configuration:

connection cheerlights
cleansession true
topic cheerlightsRGB in

and I have created a Home Assistant sensor which I can use to display the value for the time being:

  - platform: mqtt
    state_topic: cheerlightsRGB
    name: CheerLights

and I actually display the present value on one of my tabs. That works fine, and the value updates as people change the colour from wherever they are in the world.

The part I need some pointers for is how to change that hex value into RGB. At the moment I have an automation that triggers whenever the color changes - but all I can do is make a fixed colour show up (for now, at least!).

    alias: setCheerlightsColour
      platform: mqtt
      topic: cheerlightsRGB
      service: light.turn_on
        - light.arilux_lc03_rgb_led_controller_00185c1b
        rgb_color: [255, 0, 0]  #<<< This is what I need to get from the hex value of the sensor.

Right now I’m driving an RGB strip (see, but I’d also like to be able to set a Lifx bulb with the appropriate colour. From this example you can see that I can only turn things red (or whatever I hardcode in!).

Can anyone point me at an example or suggest how I might complete this project? I have 'till Christmas to get this working, but will share the final solution - if I succeed.

Thanks in advance for any help or guidance

Hardcoded template? CheerLights seems to only support 11 colors so not a super hard task.

Something like

{%- if ([YOUR HEX INPUT]) == ("#FF0000") -%}rgb(255,0,0)
{%- elif ([YOUR HEX INPUT]) == ("#008000") -%}rgb(0,128,0)
{%- else -%}blah{%- endif %}

Thanks for the response.
That’s definitely a good lead and something to help me move forward. Am also looking at a response to a question for changing the colour of a light in response to a weather condition which is very similar that has come up this evening.
Thanks again.

If you use a data_template, you can convert hex into decimal with something like {{ rgb[2:4] | int(base=16) }} (for each color component).

coming back to this as it was the only ‘cheerlights’ topic I could see - I finally solved this myself and posting the response for others:

    platform: mqtt
    topic: cheerlightsRGB
    service_template: light.turn_on
      brightness_pct: 50
        - "{{ trigger.payload[1:3] | int(0,16) }}"
        - "{{ trigger.payload[3:5] | int(0,16) }}"
        - "{{ trigger.payload[-2:] | int(0,16) }}"
        - light.gloworb

Also worth noting that since June 2019 you can connect directly to the cheerlights MQTT server ( so I have the following in my mosquitto.conf

connection cheerlights
topic cheerlights in
topic cheerlightsRGB in

Hi Love the idea, but have zero experience with MQTT.
Can you please help me set this up.

I have coonected my smartlights and installed Mosquitto after this i’m blank and have no clue.
Maybe somthing like a step by step will really help me.

Thank You in advance

PS: this is a clean install so I only have mosquitto installed and running and a light.