Multiply two sensors after dividing the first one with 100

Hi all,

I am completely new to Home Assistant and I am trying to calculate the kWh of my battery based on the SOC sensor and its designed capacity sensor.
The State of charge must be first transformed in to a 0.something
I have already achieved this by using the following I found
{{ states(‘sensor.byd_battery_box_premium_hv_state_of_charge’) | float / 100 * 11059 }}

However when I replace the 11059 (which is the current capacity of the battery) with its sensor it looks like the below
{{ states(‘sensor.byd_battery_box_premium_hv_state_of_charge’) | float / 100 * states(‘sensor.byd_battery_box_premium_hv_maximum_capacity’) }}
but doesn’t give a preview so I don’t save it to avoid errors.

Can you please advice how to formulate the script.
Thank you all in advance.

{{ (states(‘sensor.byd_battery_box_premium_hv_state_of_charge’) | float / 100 ) * (states(‘sensor.byd_battery_box_premium_hv_maximum_capacity’) | float ) | round(1) }}

And please “Format” your Code when you post it in the Forum
How to help us help you - or How to ask a good question. (PT.11)

PS: Paste/test your templates in /Developer Tools/Templates !

Because boheme61 copied your unformatted text it contains “fancy” quotes. These will cause errors and need to be replaced with “straight” quotes. There were also some extraneous parentheses that were not required as the normal order of operations (multiplication and division are performed left to right) will ensure it does what you want:

{{ ( states('sensor.byd_battery_box_premium_hv_state_of_charge') | float / 100  * states('sensor.byd_battery_box_premium_hv_maximum_capacity') | float ) | round(1) }}
1 Like

Upps :blush: , did saw they looked peculiar, but i guess i was to fast to get out of the Forum
Thanks for “stepping in”
Just watched “Gentleman Thief Thomas Crown” (again) , of to bed now

Thank you both for the feedback.
I will test it and get back with results.
Also duly noted regarding pasting code, will do it correctly next time.

Hi again,
works great, thank you for the help.