Template expansion strips .0 decimal

Hi *,

I write a float value like “2.0” as string in an input_text entity.

input_text:
  text_thermostat_livingroom_default_day:
    name: text_thermostat_livingroom_default_day
    initial: "2.0"
--------8<--------
action:
    - service: input_select.select_option
      target:
        entity_id:
          - input_select.preset_thermostat_livingroom
      data:
        option: >
          {{ states('input_text.text_thermostat_livingroom_default_day') }}

When I evaluate the state of the input_text entity in a template expansion, the “.0” gets striped off.

Debugging output:

Executed: January 23, 2022, 08:44:32
Result:
params:
  domain: input_select
  service: select_option
  service_data:
    option: 2
    entity_id:
      - input_select.preset_thermostat_livingroom
  target:
    entity_id:
      - input_select.preset_thermostat_livingroom
running_script: false

Filtering {{ states( 'input_text.text_thermostat_livingroom_default_day') | string }} also makes no difference.
It does not happen with “2.5” for example.

Why is that?
And how can I prevent this?

Best
Ck

This is common with most (or perhaps all) programming languages.
If the value is something.0 then the .0 is removed.
What is this value used for?

Yes, if I store in a float value, but I am explicitly using string to avoid numerical evaluation.

I use this to select a preset with the name “2.0”, not the number.

You probably need something like:

{{ '{:.1f}'.format(states( 'input_text.text_thermostat_livingroom_default_day')) }}

I tried that but I get the error:
Error: Error rendering data template: ValueError: Unknown format code 'f' for object of type 'str'

Which obviously makes sense…

If I filter states as float, I have the same problem again. “.0” is striped.

{{ '{:.1f}'.format(states( 'input_text.text_thermostat_livingroom_default_day') | float) }}

btw I always use string for this property, throughout any automation and entity.

If I put the expansion in double quotes:

“.0” is not striped off, but I have extra qoutes.

Executed: January 23, 2022, 10:31:17
Result:
params:
  domain: input_select
  service: select_option
  service_data:
    option: '"2.0"'
    entity_id:
      - input_select.preset_thermostat_livingroom
  target:
    entity_id:
      - input_select.preset_thermostat_livingroom
running_script: false

and with single quotes:

Executed: January 23, 2022, 10:34:12
Result:
params:
  domain: input_select
  service: select_option
  service_data:
    option: '''2.0'''
    entity_id:
      - input_select.preset_thermostat_livingroom
  target:
    entity_id:
      - input_select.preset_thermostat_livingroom
running_script: false

While the same automation working for another room looks like this:

Executed: January 23, 2022, 10:34:12
Result:
params:
  domain: input_select
  service: select_option
  service_data:
    option: 2.5
    entity_id:
      - input_select.preset_thermostat_lab
  target:
    entity_id:
      - input_select.preset_thermostat_lab
running_script: false

I can’t see the same issue.

Yes, but you use an input_number instead of input_text.