Working Automation but breaks server check (preventing classic restart)

I have this piece of code to help me randomize all the color change for my bulbs. It’s a purely aesthetic thing but I like having all the lights go to random colors. They’ve all been working.

    - service: light.turn_on
      entity_id: light.kitchen
      data_template:
        hs_color:
          - "{{ (30 + (state_attr('light.kitchen', 'hs_color')[0] or 0)) % 360 }}"
          - 100
        brightness_pct: 100
        transition: 1

However my config check on it always spits out this error

Invalid config for [automation]: invalid template (TemplateSyntaxError: unexpected '}', expected ')') for dictionary value @ data['action'][0]['data_template']. Got None. (See /config/configuration.yaml, line 9). 

Now it passes if I change the {{ brackets to (( but then the automation doesn’t work. Not if I try to call it or if I try to execute it.

This is confusing I’m still fairly new to this stuff. Should I just let the error keep happening, I can’t restart my server though. I guess I could do it from the terminal but it’d definitly satisfy my OCD if I can get the automation actually working without the Check Configuration borking it.

I am running HomeAssistant OS 0.118.5 on a RPI4. HassOS 4.15

Thank you for any and all help

I created a script containing what you posted. It passes Check Configuration. :man_shrugging:

test2:
  sequence:
    - service: light.turn_on
      entity_id: light.kitchen
      data_template:
        hs_color:
          - "{{ (30 + (state_attr('light.kitchen', 'hs_color')[0] or 0)) % 360 }}"
          - 100
        brightness_pct: 100
        transition: 1

I’m using 0.118.4 but I doubt the different patch version is responsible for the script passing Check Config.

What’s the rest of the automation/script where this is used?

BTW, since version 0.115, the data_template option has been deprecated and the data: option serves the same purpose. In fact, if you check the Log at startup, you may see messages concerning this modification.

- id: CC_kitchen_east
  alias: StoveCC
  trigger:
  - minutes: /31
    platform: time_pattern
    seconds: '0'
  condition:
  - after: '10:30:00'
    before: 03:00:00
    condition: time
  - condition: state
    entity_id: light.stovetop
    state: 'on'
  action:
  - data_template:
      brightness_pct: 100
      hs_color:
      - '{{ range(360)|random }}'
      - '{{ range(80,101)|random }}'

Sorry! This is the code I meant to paste. The other code above is the new one but I already troubleshooted that it wasn’t the issue.

This version doesn’t call any service in action. It will fail Check Config.