[solved] Failed to create automation with trigger numeric value from input_number

Hi
I have a numeric value (from slider)

  boiler_save_temperature:
    name: Save Temperature
    initial: 50
    min: 40
    max: 70
    step: 10

I can view it’s value using tamplate:

> {{ states('input_number.boiler_save_temperatur') | float }}
I’ve tried to use this value in automation:

- id: '1580322266512'
  alias: Boiler set on
  description: ''
  trigger:
  - below: "{{ states('input_number.boiler_save_temperatur') | float }}"
    entity_id: sensor.boiler_ds18b20_temperature
    for: 0:00:05
    platform: numeric_state
  condition:
  - condition: state
    entity_id: switch.boiler
    state: 'off'
  - below: "{{ states('input_number.boiler_save_temperatur') | float }}"
    condition: numeric_state
    entity_id: sensor.boiler_ds18b20_temperature
  action:
  - data:
      entity_id: switch.boiler
    service: switch.turn_on

this is the error i get:

Invalid config for [automation]: expected float for dictionary value @ data['condition'][1]['below']. Got None
expected float for dictionary value @ data['trigger'][0]['below']. Got None. (See /config/configuration.yaml, line 151)

It is reporting that it expected to get a numeric value for below in condition and below in trigger but it did not get one. That’s because you entered a template and assumed below supports templates. However, the documentation does not indicate below, or above, support templates.

2 Likes

You’re going to need a template trigger…as 123 says, ‘above’ and ‘below’ won’t work with templates.

automation:
  trigger:
    platform: template
    # Need something to evaluate to true
    value_template: "{% if (states('sensor.boiler_ds18b20_temperature') | float) < (states('input_number.boiler_save_temperatur') | float) %}true{% endif %}"
    for: "00:00:05"

Same thing for the condition. Use a template condition in the exact same way.

1 Like

The suggested value_template reports when the result is true but overlooks to report when it’s false.

The simplest way to have it support both states is to eliminate the if and reduce it to this:

{{ (states('sensor.boiler_ds18b20_temperature') | float) < (states('input_number.boiler_save_temperatur') | float) }}

The automation ends up looking like this:

- id: '1580322266512'
  alias: Boiler set on
  description: ''
  trigger:
    platform: template
    value_template: "{{ (states('sensor.boiler_ds18b20_temperature') | float) < (states('input_number.boiler_save_temperatur') | float) }}"
    for: "00:00:05"
  condition:
    condition: state
    entity_id: switch.boiler
    state: 'off'
  action:
    service: switch.turn_on
    data:
      entity_id: switch.boiler
2 Likes

I guess I assumed a non true or null return value would be interpreted as ‘false’. Though I just made it up and haven’t ever tried it.

In addition, your template is returning a string value of “true” and not a binary value of “true”.

Paste this into the Template Editor and experiment with it.

{% if false %}
  {{true}}
{% else %}
  {{false}}
{% endif %}
  • Change the initial test {% if false %} to {% if true %} and observe how Jinja2 interprets {{true}} as a binary value (True and False). Put the initial test back to {% if false %}.
  • Remove the surrounding “{{ }}” from {{true}} and {{false}} and observe how the result changes from True and False (Jinja2 interprets them as binary values) to true and false (Jinja2 interprets them as strings).
  • Remove the entire else section and notice how if the test is for false there will be no result produced.