Decimal point not Working

Hello everyone,
I’m fairly new to Hass.io.
I’ve already made a few templates, but I’m overwhelmed here :slight_smile:

This ist my Sensor Device :

  • platform: mqtt
    name: “PV Stromnetz”
    state_topic: “fhem/Solaranlage/status-grid_power”

Its around a nummer over 10000 like 14204 Today.

Now i will have a number like 14.20

This is what i test :

  • platform: template
    sensors:
    PV_Stromnetz:
    friendly_name: “Stromnetz”
    value_format: “{{ (states(‘sensor.pv_tageseinkauf’) | float / 1000 | round(2) }}”

I think what I did there is a bunch of shit :slight_smile:

Thanks for help

You’re only rounding the 1000, not the entire equation. Parenthesis are your friend. EDIT: Also make sure each opening parenthesis has a closing one. I.e. ( ( ) is invalid where ( ( ) ) is not invalid.

That’s right, shame.

But that doesn’t work at all

Well, I’m pretty sure your spacing is off, but I can’t help because you haven’t formatted your code in your post.

Make sure you read the FAQ, specifically point 11 to properly format code so that it looks correct on forum posts.

  - platform: template
    sensors:
      PV_Stromnetz:
        friendly_name: "Stromnetz"
        value_format: "{{ (states(‘sensor.pv_tageseinkauf’) | float / 1000 | round(2) }}"

that needs to be all lowercase

Those quotes need to be replaced with '. Fancy quotes are not allowed in templates.

That does not have a closing parenthesis. Hint: the closing parenthesis should go between the 1000 and the |

  - platform: template
    sensors:
      pv_stromnetz:
        friendly_name: "Stromnetz"
        value_template: "{{ states('sensor.temperature') | float / 10 | round(2) }}"

That works. value Format doenst work to. 

Thank you for your time

Because you’re only rounding the last number… again, you have to use wrap the entire division in parenthesis in order for the round to be applied to the whole equation. It’s just being applied to the 10.

I just noticed it after the reboot. I don’t understand exactly what you mean in the cde. Can you please correct me in the code?

order of operations matter.

For example:

4 + 4 / 2 = 6

however, if you add parenthesis…

(4 + 4) / 2 = 4

it completely changes the meaning.

right now you essentially have

x / 10 | round(2)

you’re only rounding the 10. So how do you round the entire x / 10?

(x / 10) | round(2)

i understand it !!! THX men

That make me crazy . When i put it in Brackets it doesnt work

value_template: "{{ states('sensor.pv_tageseinkauf_2') | (float / 10) | round(2) }}"`

I will not waste your time

is that your entire equation? What about the whole states(‘sensor.pv_tageseinkauf_2’) part? WHy is that not included in the parenthesis?

I understand you might be frustrated here, but if I give you the answer, you’ll be back here asking the same question. It’s best you actually learn how this works. states('sensor.pv_tageseinkauf_2') | float is the entire value of your sensor. That’s equivalent to x in my previous response.

I suggest you start to use the template editor as well. Developer tools → templates. You can test any template there and see the result.

iam not a Programmer. I will learn .

Thanks oyu and a nice eventing, sorry for wasting your time

You’re not wasting my time. I’m trying to help you learn.

use the template editor in develop tools → template. Paste your template there and play around until you get the expected answer.

iam in and iam trying.

Thx you

{{ ((states('sensor.pv_tageseinkauf_2')| float) / 1000) | round(2) }}

Thats it, thanks for your patience

1 Like