Service_template error

Yes, it works perfectly, but only without passing parameters, because of what @walrus_parka said about issues with lists.

So the problem isn’t the use of light.toggle but the inability to pass a list as a parameter (for rgb_color)?

This is the post I found. It needs to pass the template data to a script and the script will call the rgb data. I don’t have enough coffee yet to do it quickly but I’m working on it.

Good find but Ouch!

I think the issue is that everything is handled as a string so this list [255, 132, 2] is effectively passed as this "[255, 132, 2]" and the receiving end doesn’t like it because it expects a list.

The ‘call a script’ solution works because the list’s elements are passed individually, as strings. However, at the expense of a fair bit of (unavoidable) overhead.

If that is working for you we will go with that. You will need to create a script named set_color in the following example.

Automation service call:

  - service: script.set_color
    data_template:
      brightness: >
        {%- set ts = as_timestamp(states.sun.sun.attributes.next_rising) -%}
        {%- set light = is_state('light.lenta_gostinaia', 'off') -%}
        {% if ts -86400 < as_timestamp(now()) and light %}127
        {% else %}10
        {% endif %}
      colors: >
        {%- set ts = as_timestamp(states.sun.sun.attributes.next_rising) -%}
        {%- set light = is_state('light.lenta_gostinaia', 'off') -%}
        {% set arg = ts -86400 < as_timestamp(now()) and light %}
        {% set r = 255 %}
        {% if arg %}{% set g = 255 %}{% else %}{% set g = 132 %}{% endif %}
        {% if arg %}{% set b = 255 %}{% else %}{% set b = 2 %}{% endif %}
        {{ r | int }},{{ g | int }},{{ b | int }}

Script:

set_color:
  sequence:
  - service_template: "{{ 'light.turn_on' if is_state('light.lenta_gostinaia', 'off') else 'light.turn_off' }}"
    data_template:
      entity_id: light.lenta_gostinaia
      rgb_color: [ "{{ colors.split(',')[0]|int }}", "{{ colors.split(',')[1]|int }}", "{{ colors.split(',')[2]|int }}" ]
      brightness: "{{ brightness }}"

I don’t think, that it’s a list problem, because i tried to do this with lists, and also i tried to change rgb_color to color_name, which goes in text string.

Well, i solved that puzzle with three separate scripts. It’s not very elegant solution, but it works for me.

  - data_template:
      entity_id: '{%- set sca = is_state(''sun.sun'', ''above_horizon'') -%} {%- set
        scb = is_state(''sun.sun'', ''below_horizon'') -%} {%- set light = is_state(''light.test_spot'',
        ''off'') -%} {% if sca and light %}script.light_day {% elif scb and light
        %}script.light_evening {% else %}script.light_off {% endif %}'
    service: script.turn_on

  alias: light_evening
  sequence:
  - data_template:
      entity_id: light.test_spot
      brightness: 1
      rgb_color: [255, 230, 220]
    service: light.turn_on

  alias: light_day
  sequence:
  - data_template:
      entity_id: light.test_spot
      brightness: 100
      rgb_color: [255, 255, 255]
    service: light.turn_on

  alias: light_off
  sequence:
  - data_template:
      entity_id: light.test_spot
    service: light.turn_off

In this case arguments are passed correctly. There is more work to do, because i want to make this scrips universal and pass entity_id from automation to scripts, maybe i’ll do it later. Thank you for your help.