Rhasspy automation - RGB Color Invalid

I am trying to feed commands from Rhasspy to my home assistant, but I am having issues with the automation.

I am able to read the trigger fine, but the rgb_color seems to be giving me an issue. I have read numerous posts with various examples, but none of them are working for me. I have tried referencing the individual values of rgb_color, parsing to build a list, and many variations with no success. I have even tried to use light.toggle with rgb_color and color_name since color_name is not available for the yeelight service.

I am also not sure how I can check to see what values the automation is actually seeing in the data template when it runsā€¦I did not see it in the homeassistant log file.

Here is the error I am getting with rgb_color: Invalid data for call_service at pos 1: expected int for dictionary value @ data[ā€˜rgb_colorā€™]

Here is my current config. Any help would be much appreciated.

- id: 'xxxxxx'
  alias: Rhasspy Lights
  trigger:
  - event_data: {}
    event_type: rhasspy_TriggerColor
    platform: event
  condition: []
  action:
  - data_template:
      brightness: 255
      rgb_color:
      - '{{ trigger.event.data.color.split()[0] | int }}'
      - '{{ trigger.event.data.color.split()[1] | int }}'
      - '{{ trigger.event.data.color.split()[2] | int }}'
    entity_id: light.yeelight1
    service: yeelight.set_color_scene

Any assistance is much appreciated.

it seems that the rgb_color data is in the wrong format:

        rgb_color: [255,0,0]

https://www.home-assistant.io/integrations/light/

so i guess it should be:

- id: 'xxxxxx'
  alias: Rhasspy Lights
  trigger:
  - event_data: {}
    event_type: rhasspy_TriggerColor
    platform: event
  condition: []
  action:
  - data_template:
      brightness: 255
      rgb_color: '[{{ trigger.event.data.color.split()[0] | int }},{{ trigger.event.data.color.split()[1] | int }},{{ trigger.event.data.color.split()[2] | int }}]'
    entity_id: light.yeelight1
    service: yeelight.set_color_scene

I saw in some of the documentation you can use either format (as a list with [x,x,x] or -x).

This works, just not with variables and data_template:

  - data:
      brightness: 100
      rgb_color:
      - 100
      - 100
      - 100
    entity_id: light.yeelight1
    service: yeelight.set_color_scene

I tried your example (even though I have tried this before posting) and get the following error:

  • [homeassistant.helpers.service] Error rendering data template: UndefinedError: list object has no element 1

I slightly modified your example to specify the delimiter for the split, but it still failed with this error (I already tried this before, but tried again to be thorough):

  • [homeassistant.components.automation] Error while executing automation automation.rhasspy_lights. Invalid data for call_service at pos 1: None for dictionary value @ data[ā€˜rgb_colorā€™]
- id: 'xxxxxx'
  alias: Rhasspy Lights
  trigger:
  - event_data: {}
    event_type: rhasspy_TriggerColor
    platform: event
  condition: []
  action:
  - data_template:
      brightness: 100
      rgb_color: '[{{ trigger.event.data.color.split(",")[0] | int }},{{ trigger.event.data.color.split(",")[1]
        | int }},{{ trigger.event.data.color.split(",")[2] | int }}]'
    entity_id: light.yeelight1
    service: yeelight.set_color_scene

try with this to debug

  action:
    - service: persistent_notification.create
      data_template:
        message: {{ trigger.event.data.color.split(",")[0] }}

suggests that the value you have is not an integer

Can you provide a few examples of what can be contained by this:

trigger.event.data.color

I assume it is in this format:

125,50,200

and there are always three numeric values and each one is in the range 0-255.

Let me try the debug message you noted.

I know the system is telling me it is not an int, I am just not sure why. It is a formatting error on my part, just not sure how to fix it.

Here is an example of the input coming from the trigger. I control the input, so I can make it whatever I want it to be. I have tried using common color names (blue, red, green, etc) as well as rgb values (255,0,0 for redā€¦0,255,0 for green, etc).

{
    "event_type": "rhasspy_TriggerColor",
    "data": {
        "light": "light.yeelight1",
        "color": "0,255,0"
    }
}

since the color value already has the ā€œ,ā€ you dont need the split

rgb_color: '[ {{ trigger.event.data.color}} ]'

You canā€™t do this:

rgb_color: '[ {{ trigger.event.data.color}} ]'

The outer single-quotes explicitly indicate it is to be handled as a string and that will be rejected because rgb_color expects a list.

The following is also invalid because the templateā€™s value will be treated as the first and only item in the list.

rgb_color: [ "{{ trigger.event.data.color}}" ]

In other words, if the templateā€™s result is "0,255,0" then the list will have one item like this:

['0,255,0']

I suggest you convert the red, green, and blue values into integers like this:

rgb_color: ['{{trigger.event.data.color.split(",")[0]|int}}', '{{trigger.event.data.color.split(",")[1]|int}}', '{{trigger.event.data.color.split(",")[2]|int}}']
1 Like

Continued thanks for helping me try to figure this out @lilbuh and @123.

@lilbuh This was a great suggestion to see what the value is.

service: persistent_notification.create
data_template:
  message: '{{ trigger.event.data.color.split(",")[0] }}'

I believe @123 is correct. I have tried just calling the value directly, but it tells me it is not an integer. It appears to be returning it as a string.

@123 I tried your solution before posting, but it appears my syntax must have been slightly off. You start to lose track of all the things you have tried after a while. :slight_smile:

I was able to get the following to work. Thank you so much @123.

data_template:
  brightness: 100
  rgb_color: ['{{trigger.event.data.color.split(",")[0]|int}}', '{{trigger.event.data.color.split(",")[1]|int}}', '{{trigger.event.data.color.split(",")[2]|int}}']
entity_id: light.yeelight1
service: yeelight.set_color_scene

It actually reformats it to:

data_template:
  brightness: 100
  rgb_color:
    - '{{trigger.event.data.color.split(",")[0]|int}}'
    - '{{trigger.event.data.color.split(",")[1]|int}}'
    - '{{trigger.event.data.color.split(",")[2]|int}}'
entity_id: light.yeelight1
service: yeelight.set_color_scene
1 Like