Send rgb color values to HA

Hi @all,

I’m kind of struggling to get my Intent ChangeColorLight working correctly with HA.

That’s the situation:
sentences.ini:
(licht | lampe) $names{name} $colors{color} --> example: light peter red
color slot:
(rot):255,0,0

HA automation:

- id: '1586777187958'
  alias: rhasspy change color light RED
  description: changes the light of the incoming name to the corresponding color
  trigger:
  - event_type: rhasspy_ChangeColorLight
    platform: event
  condition:
  - condition: template
    value_template: "{{ not trigger.event.data.name.value == ''}}"
  action:
    data_template:
      rgb_color: ['{{ trigger.event.data.color.value}}']
      entity_id: '{{ trigger.event.data.name.value }}'
    service: light.turn_on

The problem is that HA is saying: Error while executing automation automation.rhasspy_change_color_light. Invalid data for call_service at pos 1: None for dictionary value @ data['rgb_color']

So I’ve tried to change the slot from above to:
(rot):255 ,0 ,0 --> with spaces
training with is working as expected, but rhasspy isn’t recognizing the slot afterwards anymore. Not sure why.
Then I’ve tried to change the slot to:
(rot):[255, 0, 0] --> because HA needs this value anyway as array
So far so good, rhasspy throws an error during training: AssertionError: Expected group preceeding optional
The error makes sense for me. Rhasspy expects the values in ‘[ ]’ to be optional values like in the sentences.ini I guess.

Has anyone hints on how to solve this?

I’m aiming to have one automation in HA and rhasspy is sending the rgb_color values as well as the entity_id values.
Entity_id is working like a charm.

Thanks in advance

EDIT: I’m sure there’s a way to call in HA a script before calling the automation and convert or transform the values to the correct format. But that’s an ugly solution in my mind.

You could try creating a custom converter for the conversion you want to do. https://rhasspy.readthedocs.io/en/latest/training/#converters

You could use a substitution here, instead of using rgb_color you could use color_name, there is a huge list of colors that HA understands, it is what I use i.e.:

action:
  - service: light.turn_on
    data_template:
      entity_id: 
        - "{{ trigger.event.data['light'] }}"
      transition: 2
      color_name: "{{ trigger.event.data['color'] }}"

Hope this helps.