Expected float for dictionary value @ data['temperature']. Got None

Dear community,

I’m trying to write the helper script, which is only update the state of the entity, if it is not yet in this state.
(I do that by the way to prevent thermostats turning on the backlight in the night, each time the automation changes the target temperature).

I’ve defined the script like that:

script:
  set_heater_target_temperature:
    sequence:
      - if:
        - condition: template
          value_template: "{{ not is_state_attr(entity_id, 'temperature', temperature) }}"
        then:
        - service: climate.set_temperature
          target:
            entity_id: script.entity_id
          data:
            temperature: script.temperature
            hvac_mode: heat

And call manually for testing it like that:

service: script.set_heater_target_temperature
data:
  entity_id: climate.floor_heating_front_thermostat
  temperature: 27 | float

The call fails with the console message:

Failed to call service script.set_heater_target_temperature. expected float for dictionary value @ data['temperature']. Got None

Okey, so it want a float. No problem, I convert value to the float like with temperature | float:

script:
  set_heater_target_temperature:
    sequence:
      - if:
        - condition: template
          value_template: "{{ not is_state_attr(entity_id, 'temperature', temperature | float) }}"
        then:
        - service: climate.set_temperature
          target:
            entity_id: script.entity_id
          data:
            temperature: script.temperature
            hvac_mode: heat

Now the service call passes, but still not work. In Logs I see the following warning:

Error in 'if[0]' evaluation: In 'template' condition: ValueError: Template error: float got invalid input '27 | float' when rendering template '{{ not is_state_attr(entity_id, 'temperature', temperature | float) }}' but no default was specified

What do I wrong?

There is no need to add the float filter when calling the script. Try this

service: script.set_heater_target_temperature
data:
  entity_id: climate.floor_heating_front_thermostat
  temperature: 27

Hi Tom,

Thanks for pushing into right direction!

Through try and trials I’ve discovered several errors, which I’ve corrected as follow:

script:
  set_heater_target_temperature:
    sequence:
      - if:
        - condition: template
          value_template: "{{ not is_state_attr(entity_id, 'temperature', temperature) }}"
        then:
        - service: climate.set_temperature
          target:
            entity_id: "{{ entity_id }}"
          data:
            temperature: "{{ temperature }}"
            hvac_mode: heat

I basically incorrectly accessed passed to script variables (over script dictionary vs directly) and incorrectly assigned values to keys (directly vs over template).

The following service call correctly changes the target state of the thermostat:

service: script.set_heater_target_temperature
data:
  entity_id: climate.floor_heating_front_thermostat
  temperature: 11

Thanks a lot again!