Xy_color random

Hello, I have a tradfri RBG bulb running on zigbee2mqtt and I am trying to get it to come on nightly with a random color. Note, these bulbs only use xy_color (no rgb_color I think). After searching a bit, I am first sandboxing with a simple call service to test. The call service data I tried returns the following error: “expected float for dictionary value @ data[‘xy_color’]”. Weird, bc I thought my code would produce float. My data is:

xy_color: ['{{ range(1,10000)|random/10000|float }}','{{ range(1,10000)|random/10000|float}}']

Note the light’s xy_color range is in decimals, so integer based code doesn’t work. Appreciate any help! Total noob here.

Just in case anyone is interested in this topic and was running into the same issue, I have figured out a working solution. Albeit there are likely easier solutions out there. I wrote a quick python script, Python Script and linked my automations to the script in order to get the Ikea light bulb to randomly change color when turned on.

entity_id = data.get("entity_id")
xy_color = [random.uniform(0, 1), random.uniform(0, 1)]
if entity_id is not None:
    service_data = {"entity_id": entity_id, "xy_color": xy_color}
    hass.services.call("light", "turn_on", service_data, False)
1 Like

Well a solution is a solution. And I’m and much more noob than you so I will copy paste to my config ! :slight_smile:

Thank you for sharing!