Error passing variable to a script

Hi,

I have been chasing a bug for a while and have narrowed it down to this piece of code. Both entity_light and entity_sensor_brightness are variables where I pass in a light and a sensor entity respectively.

What am I doing wrong? This code causes the following error:

Invalid config for [automation]: not a valid value for dictionary value @ data[‘action’][17][‘entity_id’]. Got None. (See /config/configuration.yaml, line 254).

2:59:20 PM – config.py (ERROR) - message first occurred at 2:36:37 PM and shows up 3 times

  main_floor_light_binary_set:
    alias: "Main floor light binary set"
    sequence:
      - service: >
          {% if states(entity_sensor_brightness) > 0 %}
            light.turn_on
          {% else %}
            light.turn_off
          {% endif %}
        entity_id: "{{ entity_light }}"

Thanks much for your help!

Your error message refers to an automation, but the code you’ve posted is a script.

Sorry not sure how that got there, here is the actual error:

2021-01-02 17:36:57 ERROR (MainThread) [homeassistant.config] Invalid config for [script]: not a valid value for dictionary value @ data[‘sequence’][0][‘entity_id’]. Got None. (See /config/configuration.yaml, line 255).

Yup, still going to need to see an automation. Specifically the automation that calls this script and passes it the variables.

Thanks. This script is called by another script. Note that if i comment out the above script - I do not get an error at start up - i will get an error when the below script cannot find the above script. However, if i include the script in my first post - i get the error right at start-up and also a notification that ‘script’ platform failed to load. Thanks a lot for your help!

  main_floor_dynamic_light_adjust:
    alias: 'Main floor dynamic light adjust'
    sequence:
      - condition: template
        value_template: "{{ not is_state(entity_select_dynamic_mode, 'off') }}"
      - condition: template
        value_template: "{{ is_state(entity_occupancy_sensor, 'on') }}"
      - service: >
          {% if is_state('entity_select_dynamic_mode', 'gradient') %}
            script.main_floor_light_gradient_set
          {% elif is_state('entity_select_dynamic_mode', 'binary') %}
            script.main_floor_light_binary_set
          {% else %}
            script.main_floor_error_log
          {% endif %}
        data:
          entity_sensor_brightness: sensor.target_brightness_accent_lamp
          entity_light: light.dining_room_table_lamp

And the script I just posted is called by an automation like this

      - service: script.main_floor_dynamic_light_adjust
        data:
          entity_select_dynamic_mode: input_select.front_foyer_pot_lights_dynamic_select
          entity_occupancy_sensor: binary_sensor.main_floor_occupancy_med
          entity_sensor_brightness: sensor.target_brightness_ambient_light
          entity_light: light.front_foyer_pot_lights

Also, this other script I call from main_floor_dynamic_light_adjust does not throw an error

  main_floor_light_gradient_set:
    alias: "Main floor light gradient set"
    sequence:
      - service: light.turn_on
        data_template:
          brightness_pct: >
            {{ states(entity_sensor_brightness)|int }}
          entity_id: "{{ entity_light }}"

This might have been it! I think the data_template missing below service caused it :frowning:

  main_floor_light_binary_set:
    alias: "Main floor light binary set"
    sequence:
      - service: >
          {% if states(entity_sensor_brightness) > 0 %}
            light.turn_on
          {% else %}
            light.turn_off
          {% endif %}
        data_template:
          entity_id: "{{ entity_light }}"

Doesn’t need data_template (that’s deprecated), but it does need data. For some reason the templates don’t work with the shortcut.

Thanks! Didn’t know that - both that the data_template is deprecated and that templates don’t work with the shortcut. Fixed now.

1 Like