Call_service at pos 1: expected float for dictionary value @ data['brightness_pct']

Hello there, I’m not sure what is wrong here. But I can’t get this script to run. I am getting this error:

call_service at pos 1: expected float for dictionary value @ data['brightness_pct']

I want the value of brightness_pct to change to 25 or 10 depending on the if else time condition.

This is the script:

dim_living_room_lights_script:
  alias: Dim Living Room Lights
  sequence:
  - service: light.turn_on
    data_template:
      entity_id: light.orb_light
      transition: '60'
      kelvin: '2700'
      brightness_pct: >-
        {% if (now().hour >= 22) and (now().hour < 2) %}
          25
        {% elif (now().hour >= 2) and (now().hour < 3) %}
          10
        {% else %}
          script.dead
        {% endif %}
  mode: single

However, my other script that has brightness_pct works fine. It has an identical structure, but with now() in the if else statement, I’m getting an error.

This is the script that works:.

bedroom_lights_on_script:
  alias: Bedroom Lights Script
  sequence:  
  - service: light.turn_on
    data_template:
      entity_id: group.bedroom_lights
      transition: '300'
      kelvin: '3500'
      brightness_pct: >-
        {% if (is_state('media_player.sony_bravia_tv', 'playing') or is_state('media_player.apple_tv', 'playing')) %}
          10
        {% else %}
          65
        {% endif %}

Can anybody tell me what is going on here and how I can fix it?

Thanks.

“script.dead” is not a float. Or any kind of number.

2 Likes

Changing the script.dead to a numerical value of 55 made the script work.

But I don’t understand it. I have some scripts with the script.dead in the {% else %}, but they work ok.

Here is one example:

dim_upstairs_lights_script:
  alias: Dim Upstairs Lights
  sequence:
  - service: light.turn_on
    data_template:
      entity_id: group.upstairs_lights
      transition: '120'
      kelvin: '3000'
      brightness_pct: >-
        {% if (now().hour >= 0) and (now().hour < 5) %}
          25
        {% elif (now().hour >= 5) %}
          0
        {% else %}
          script.dead
        {% endif %}
  mode: single

I mean I can go away by changing the script.dead to a numerical value. But I just don’t understand why that doesn’t work, while the other with similar structure works?

Maybe because the template has never gotten past all of the “if” statements and ended up at the “else”?

if it never tries to render that portion of the template the service has nothing to complain about.

That makes sense. So basically, with data_template, you can’t use a script in if-else?

You can but the specific service you are trying to call has certain requirements.

the “light.turn_on” service expects a number for “brightness_pct:” not a string. “script.dead” is a string not a number.

If you call a different service (like “script.turn_on”) then putting “script.dead” as an “else” option would be perfectly acceptable.

the point is you can’t just mix and match options outside of what the service expects for data.