Hi all,
I’m fairly new to HA, migrating over from openHAB. I’m having some trouble creating some of my smart home behaviors.
I have an rgb led strips that I want to have some presets I can change through but also to update it on the fly form the Lovelace UI.
I defined my light in configuration.yaml
and managed to define two scenes like so:
# snippet from scenes.yaml
- name: sink_lights_day_mode
icon: "hass:weather-sunny"
entities:
light.sink_lights:
state: "on"
rgb_color: [255,255,178]
brightness: 255
- name: sink_lights_night_mode
icon: "hass:weather-night"
entities:
light.sink_lights:
state: "on"
rgb_color: [255,36,0]
brightness: 223
In order to cycle between them I than defined an input boolean with the following automation:
#snippet from automations.yaml
- alias: "Sink Lights Day Mode"
trigger:
- platform: state
entity_id: input_boolean.sink_lights_toogle
to: "on"
action:
- service: scene.turn_on
target:
entity_id: scene.sink_lights_day_mode
- alias: "Sink Lights Night Mode"
trigger:
- platform: state
entity_id: input_boolean.sink_lights_toogle
to: "off"
action:
- service: scene.turn_on
target:
entity_id: scene.sink_lights_night_mode
So far so good- I have a switch in Lovelace that I can switch on to turn the light to “Day” mode and off for “Night”.
But what I can’t seems to do is dynamically change those RGB and Brightness values for the scene. What I would like to do is have another button that I can press and set whatever color that is on right now as one of those scenes.
I tried to create a new scene on the fly with this automation:
#snippet from automations.yaml
- alias: "Update Sink Light Day Scene"
trigger:
- platform: state
entity_id: input_boolean.test_switch
to: "on"
action:
- service: scene.create
data_template:
scene_id: sink_lights_day_mode_runtime
entities:
light.sink_lights:
state: "on"
rgb_color: "{{state_attr('sink_lights','rgb_color')}}"
brightness: "{{state_attr('sink_lights','brightness')}}"
And then activate it with another input boolean and this automation:
#snippet from automations.yaml
- alias: "Sink Lights Runtime Scene"
trigger:
- platform: state
entity_id: input_boolean.runtime_scene_switch
to: "on"
action:
- service: scene.turn_on
target:
entity_id: scene.sink_lights_day_mode_runtime
I get the following error:
2021-05-03 13:18:05 ERROR (MainThread) [homeassistant.components.automation.sink_lights_runtime_scene] Sink Lights Runtime Scene: Error executing script. Invalid data for call_service at pos 1: expected int for dictionary value @ data['brightness']
2021-05-03 13:18:05 ERROR (MainThread) [homeassistant.components.automation.sink_lights_runtime_scene] Error while executing automation automation.sink_lights_runtime_scene: expected int for dictionary value @ data['brightness']
Now from what I could understand in this thread it shouldn’t happen but I also tried with |int
filter for the brightness
value and it didn’t work as well.
I got the following error:
2021-05-03 13:22:40 ERROR (MainThread) [homeassistant.components.automation.sink_lights_runtime_scene] Sink Lights Runtime Scene: Error executing script. Invalid data for call_service at pos 1: None for dictionary value @ data['rgb_color']
2021-05-03 13:22:40 ERROR (MainThread) [homeassistant.components.automation.sink_lights_runtime_scene] Error while executing automation automation.sink_lights_runtime_scene: None for dictionary value @ data['rgb_color']
So my questions are:
- Is this even the right approach? Like I said I’m new to HA and have a feeling I’m going at it the wrong way.
In OH what I did was to store the relevant color configuration to an item (like a global variable and that is persisted through reboots) and when I wanted to update it I just overwrite it with the current color configuration.
What would be the best way to do this in HA? - In case this is the right approach, what am I doing wrong here?
This YAML syntax is also new for me so I’m sure I messed up all sot of things there…
Thank you all in advance…