Input_text acting as a float problem

This might be a bug I think… I’m trying to make a keypad with numbers 0-9 and a decimal. This is working fine until I use the decimal. If I enter 1 and then press the decimal, I get 1.0 so impossible to enter 1.5 as the system added the 0 by itself. I’m sure it is some sort of internal decision to automatically convert it to a number (some sort of AI ). It is strange to do that with an entity called INPUT_TEXT.

I use custom buttons. like this:

type: custom:button-card
color_type: icon
entity: input_text.keypad_input
aspect_ratio: 1/1
show_label: true
show_name: false
show_icon: false
show_state: false
tap_action:
  action: call-service
  service: script.keypad_input_2
  service_data:
    number: "7"
size: 80%
name: ""
label: "7"
styles:
  card:
    - border-radius: 10%
    - padding: 10%
    - font-size: 80px
    - text-shadow: 0px 0px 5px black
  name:
    - font-size: 40px
    - text-transform: uppercase
    - letter-spacing: 0.5em
    - font-familly: cursive
    - padding: 0px 5px

The “Service_data Number” is set to the digit I want. Same thing for the decimal place. The script.keypad_input_2 is as follow:

data_template:
  entity_id: input_text.keypad_input
  value: |
    {% set current_value = states('input_text.keypad_input') %}
    {% if current_value != 'None' and current_value != 'unknown' %}
      {{ current_value ~ number | string }}
    {% else %}
      {{ number | string }}
    {% endif %}
action: input_text.set_value

if I press 1, I get 1
then I press . I get 1.0
but if I press again ., I get 1.0.
I clear
I press . I get .
I press 2 I get 0.2

It means that I the text entered is valid number, it format it as a number. So if I put a letter at the beginning, then it stays as a text.

Anyone has a solution to bypass this bug?

Can’t really answer your question, but why are you using an input text helper instead of an input number helper, if all you really need are 0-9 & .?

It’s not input text doing this, but your template, that’s what the template engine does when you render something that looks numberlike.

Try reformatting your script as such to workaround, you can pass the entire data object as a single object to avoid the template changing the datatype.

action: input_text.set_value
target:
  entity_id: input_text.keypad_input
data: >
    {% set current_value = states('input_text.keypad_input') %}
    {% if current_value != 'None' and current_value != 'unknown' %}
      {{ {'value' : current_value ~ number } }}
    {% else %}
      {{ {'value' : number} }}
    {% endif %}
1 Like

SUPER!! Yes, that worked. Thanks.

Got to learn more these syntax.

Good question @ShadowFist , probably because I started by thinking I was going to enter time in format 01:00 but then thing just evolved :wink:

Lol glad you worked around your issue, but I suspect you could have avoided all this datatype hassle if you used a number helper in the first place