I’m trying to create an automation which would allow me to be bit more dynamic in changing the light colours. Let’s call it a disco for now (although missing the 1sec timers here). I am using Ikea remote, Ikea rgb bulb and zigbee2mqtt. HA 0.114.4 and z2m 1.16.0.
And, well, it doesn’t work. I tried also to change that .py 1) replacing ’ by ", no effect 2) making more direct calls like row: rgb = [255, 0, 0], no effect.
Any hints? There is nothing in home-assistant.log. Just that the automation “Change light colours” has been triggered in the UI logbook. And by the way, my first python script
Automation:
- id: ChangeRGB
alias: 'Change light colours'
trigger:
platform: state
entity_id: sensor.ikea_remote_1_action
to: 'brightness_up_click'
action:
- service: python_script.random_colours
data:
entity_id: light.jalkalamppu
brightness: 255
python script (in /python_scripts/random_colours.py):
entity_id = data.get("entity_id")
brightness = data.get("brightness")
r = random.randint(0,256)
g = random.randint(0,256)
b = random.randint(0,256)
rgb = [r, g, b]
if entity_id is not None:
service_data = {'entity_id': entity_id, 'rgb_color': rgb, 'brightness': brightness}
hass.services.call('light', 'turn_on', service_data, False)
and obviously in configuration.yaml:
python_script:
This is based on descriptions and hints from https://www.home-assistant.io/integrations/python_script and [SOLVED] Python script, need to build a for loop to turn on a random number of lights