Expected float for dictionary value @ data['above' error with input_number

Hi I recently started using HA. Now, I want to do some “custom” stuff. For that, I need to use the YAML. I don’t completely understand it, but here’s what I’ve done so far.

My problem remains in the trigger part. I get the following error :

Message malformed: expected float for dictionary value @ data[‘above’]

I want to use an input_number (from helpers) as the condition. If i replace all

“{{ states(‘input_number.temperature_set_point’)|float }}”

by a simple int, the automation works, but I want it more dynamic.

I know I have improvement to do in the action part, but I’m doing block by block and now I’m stuck in the first one !

alias: Partir chauffage serre
description: ""
trigger:
  - platform: numeric_state
    entity_id:
      - sensor.esp32_serre_temperature_serre
    above: "{{ states('input_number.temperature_set_point')|float }}"
condition: []
action:
  - type: turn_on
    device_id: 243dab86afce3d551505a657d44898b6
    entity_id: da16146e7374399c83c12ecd84e61a10
    domain: switch
  - type: turn_off
    device_id: f8818c077f8a59e7a5314cab1b8804ef
    entity_id: e7391e7b20a731e2810c520360a4c3f6
    domain: switch
mode: single

Thanks

The line with your template result is producing a string due to the " "s

{{ states('input_number.temperature_set_point')|float }}   # renders  (12.6)
"{{ states('input_number.temperature_set_point')|float }}" # renders ("12.6")

No Idea why, but this worked

    below: input_number.temperature_set_point

Good for you! Glad you got it sorted.

That worked because the above: or below: fields only accept numbers or entities; they do not accept templates.

The numeric state trigger docs explain your options.

That part got me mixed up, why this part seems to accept template ?

 changes.
      value_template: "{{ state.attributes.value - 5 }}"
      # At least one of the following required
      above: 17
      below: 25

It’s that way because the docs say so. Every field has different requirements for what it can and cannot accept.

In the case of the numeric state trigger, the above: or below: fields only accept numbers or entities while the value_template: field only accepts templates.

Even without the quotes, I get the same error. I want to do something like that

below: {{ states(‘input_number.temperature_set_point’)|float - 1.5}}

but it doesn’t work.

We’ve established that this will not work since you cannot use templates in the below field:

trigger:
  - platform: numeric_state
    entity_id:
      - sensor.esp32_serre_temperature_serre
    below: "{{ states('input_number.temperature_set_point')|float - 1.5 }}"

But since we can put templates into the value_templates field, you could instead do this to achieve the intended result:

trigger:
  - platform: numeric_state
    entity_id:
      - sensor.esp32_serre_temperature_serre
    value_template: "{{ state.state | float + 1.5 }}"
    below: input_number.temperature_set_point

Unrelated, but you may want to choose a default for the float filter so that you do not get errors when the esp32 sensor goes to unavailable or unknown. For example, you could use float(100) so that the trigger doesn’t fire in that scenario.

1 Like