Trouble with input_number in automation

With the .107 release I wanted to make a configuration dashboard where e.g. setpoint for a TRV is configured.

The automation that sets the setpoint is as follows:

data:
  entity_id: climate.spirit_veranda
  temperature: {{ states('input_number.verwarming_veranda_setpoint_high') | float }}
service: climate.set_temperature

For some reason it does not work, I don’t see any log messages either. First I had “| int” instead of float, which in the log msgs indicated that the service expected a float. When I put that template line in the Dev Tools Template input, it shows the value correctly (i.e. 19.5).

Any ideas?

Need to use data_template: instead of data:

1 Like

Also you need to put the template in quotes, otherwise the curly braces will be interpreted by the YAML parser as dictionary operators. And lastly, you don’t need the float filter. Input number entities are already numbers, and like all states, are string representations. So by using the float filter you’ll be taking the string representation of a float and converting it to a float. But then the output of a template is always a string, so it will just be converted back to a string. So basically the float filter in this case effectively does nothing.

data_template:
  entity_id: climate.spirit_veranda
  temperature: "{{ states('input_number.verwarming_veranda_setpoint_high') }}"
service: climate.set_temperature
2 Likes

Using

data_template:
  entity_id: climate.spirit_veranda
  temperature: '{{ states(''input_number.verwarming_veranda_setpoint_high'') }}'
service: climate.set_temperature

gives me error:

 Verwarming Living Hoog: Error executing script. Invalid data for call_service at pos 3: expected float for dictionary value @ data['temperature']
4:59:28

What makes it even more interesting if I do add the “| float” part, I don’t get any error but the setpoint doesn’t get applied.

What does this result in if you put it in the Template Editor:

{{ states('input_number.verwarming_veranda_setpoint_high') }}

As mentioned in my first post, the correct value:

Could you post the entire automation?

I changed the automation back to using hard values, but obviously the 19.5 was replaced with the template when I was testing:

- id: '1579630960715'
  alias: Verwarming Living Hoog
  description: ''
  trigger:
  - entity_id: input_boolean.heating_living
    platform: state
    to: 'on'
  condition: []
  action:
  - data:
      entity_id: switch.ikea_verwarming
    service: switch.turn_on
  - data_template:
      entity_id: climate.spirit_veranda
      temperature: 19.5
    service: climate.set_temperature
  - data_template:
      entity_id: climate.spirit_living
      temperature: 17
    service: climate.set_temperature

Wait, so what was the automation when you got the error? It’s kind of hard to help without consistent data. I need to see the automation that caused the error.

Alright, then it’s:

- id: '1579630960715'
  alias: Verwarming Living Hoog
  description: ''
  trigger:
  - entity_id: input_boolean.heating_living
    platform: state
    to: 'on'
  condition: []
  action:
  - data:
      entity_id: switch.ikea_verwarming
    service: switch.turn_on
  - data_template:
      entity_id: climate.spirit_veranda
      temperature: '{{ states(''input_number.verwarming_veranda_setpoint_high'') }}'
    service: climate.set_temperature
  - data_template:
      entity_id: climate.spirit_living
      temperature: '{{ states(''input_number.verwarming_living_setpoint_high'') }}'
    service: climate.set_temperature

So the third step in the automation actions does not use the input_number you’ve been asking about. It’s using input_number.verwarming_living_setpoint_high. What is its state?

EDIT: Also, when you use the automation with the hard coded values (i.e., not template), do you still get the error?

Using hardcoded values, everything works fine.

Thanks.

So when you use the templates instead of hard coded values, do you get the error every time the automation triggers, or just the first time? E.g., if you were to turn input_boolean.heating_living off and back on (to make it trigger), do you get the error every time? And do you get the error for each step that uses a template?

try double quotes:

temperature: "{{ states('input_number.verwarming_veranda_setpoint_high') }}"

or

temperature: "{{ states('input_number.verwarming_veranda_setpoint_high') |int }}"

The way it was quoted is not common, but it isn’t wrong, and changing that will have no effect. And adding the int filter will just cause it to lose fractional degrees, which is probably not wanted. And, before you ask, adding a float filter will have no effect either.

It was for trying to help, I have little knowledge about it, in fact, you have saved my ass several times I hope I have not offended you :upside_down_face:

Nope, just trying to clarify. No worries. Hope I have not offended you.

of course not, I hope I can thank you more times
:stuck_out_tongue_winking_eye:

1 Like

Could anyone give perhaps an example yaml config for an automation using the input_number helpers?

It would be helpful if you could answer these questions:

What you had should have worked. It’s unclear why you’re getting that error. I was trying to help you figure out where the real problem was.

1 Like