I’m trying to set up an automation that advances the color of a Hue bulb through a predefined list of colors each time and cannot get my approach to work, so I’m wondering if there is another way to go about it. The method I’m attempting is:
Check the rgb_color attribute of the light in question
Compare the value received to the predefined list
If it’s in the list then advance the list index by one or loop back to 0 if the end has been reached
If it’s not in the list, then go to the first color of the list
The problem is that the value returned by the rgb_color attribute is never exactly what I set it to, so the automation always tries to change the color to the first list entry. I’ll post a different topic to try and figure out that issue; my question in this topic is just if there is a different method to accomplish my end goal.
Here’s my code:
- alias: Double Press
description: ""
trigger:
- device_id: 5e63c76894a53aeeeeee4c2e7ea8d834
domain: zha
platform: device
type: remote_button_double_press
subtype: remote_button_double_press
condition: []
variables:
color_cycle:
- [0, 255, 0]
- [123, 123, 123]
- [255, 167, 90]
- [255, 0, 0]
- [0, 255, 0]
- [0, 0, 255]
action:
- service: light.turn_on
data_template:
entity_id: light.bedside_table
rgb_color: >
{% set current = state_attr('light.bedside_table', 'rgb_color')|list %}
{% set idx = color_cycle.index(current) + 1 if current in color_cycle else 0 %}
{% set color = color_cycle[idx] %}
[{{color[0]-}}, {{color[1]-}}, {{color[2]}}]
mode: single
Set a random color on a light
He has a cycle version as well, otherwise I would think using scenes as a better approach.
(Note: That trying to get the current colour state of more than one entity @ A time is problematic).
But you could add A input_select helper & have the script, change that; so you have A pre-set variable.
I still need to modify it to keep the current brightness level and only change the color, but otherwise it seems to do the trick. Thanks for pointing me in the right direction!