How to change the format of an input.number prior to using it in an action?

I want to remove the decimal point in an input.number and the send the complete number including the fraction in the result of an action value.

By this I mean I have an input.number configured like:

input_number:
  solax_battery_charge:
    name: SolaX Battery Charge A
    initial: 20
    min: 0
    max: 20
    step: 0.1

I have it like this for easy visual reference to what the charge amps are.

So for example I want to set the charge rate at 16.5 on the slider.
But to send the value I need to reformat it as 165 before sending.
I know I could change the slider to 0 - 200

But is there any easy way to change the format prior to sending the value?
I also need to ensure 20 on the slider gets sent as 200

automation:
  - alias: House Battery Charge Rate
    trigger:
      platform: state
      entity_id: input_number.solax_battery_charge
    action:
    - service: modbus.write_register # Enter User Password
      data_template:
        hub: SolaX
        unit: '255'
        address: '0'
        value: '2014'
    - service: modbus.write_register # Battery Charge Amps
      data_template:
        hub: SolaX
        unit: '255'
        address: '36'
        value: "{{ trigger.to_state.state | int }}"

That’s the basic automation. It does work but when the slider is at 20 it’s only setting 2 Amps

If I manually set the value as 200 it sets it to 20 Amp
value: '200'

        value: "{{ trigger.to_state.state | float * 10}}"
1 Like

Can you not simply multiple the value by 10?

"{{ trigger.to_state.state | float * 10 | int }}"

Neither seem to send any value. I know you can only send int’s to modbus registers.

Cracked it

value: "{{ (trigger.to_state.state | float * 10) | int }}"

Thanks guys for pointing me in the right direction!

The | filter operator has higher precedence than multiply, so the expression will change 10 to an int, then multiply that by the state converted to float. So it should be:

"{{ (trigger.to_state.state | float * 10) | int }}"

Or it could also be done it like this:

"{{ trigger.to_state.state | float | multiply(10) | int }}"

Ouch :sweat_smile: totally forgot

I didn’t know | is a filter. Handy to know.

Anyway I want to thank you all for your quick responses.

here’s the freshly updated info on it (not merged yet)

It’s not. It’s the filter operator. int & float are filters. :slightly_smiling_face: See https://jinja.palletsprojects.com/en/master/templates/#filters

when I looked at the HA code I was surprised by this, hence my PR…

You didn’t point at the PR, so I can’t really tell what you changed.

Don’t confuse the float() function with the | float filter. Like many things in the Jinja implementation, a function that can’t interpret its input usually just returns the input unchanged. That’s not what the filter does; it returns a default value.

Here’s the PR is it makes things easier.