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'
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 }}"
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.