Solar Daily Energy Template Help

Hey

im dipping my tow into the world of templates.

Im wanting to convert my daily solar production to kwh. This is as far as i got. i dont have a clue how i would convert this 74833.2 to 74.8kWh?

state: "{{ states('sensor.energy_day_fronius')|float * +1.23 }}"

I’m not sure where that +1.23 comes from or what you want to do with that. Do you just want to divide the value by 1.000? From Wh to kWh?

Then your template could look like this:

{{ states('sensor.energy_day_fronius')|float(0) / 1000 }}

i looked up float and was just reading lol

thank you though! helps to see examples that mean something to me

This is my yaml code, and its saying Incorrect Type. expected “string”. as i said nfi about this sort of stuff.

template:
  - sensor:
      - name: "Fronius Day Energy kWh"
        unit_of_measurement: "kWh"
        state: {{ states('sensor.energy_day_fronius')|float(0) / 1000 }}

You need quotes around the template definition:

template:
  - sensor:
      - name: "Fronius Day Energy kWh"
        unit_of_measurement: "kWh"
        state: "{{ states('sensor.energy_day_fronius')|float(0) / 1000 }}"
1 Like

ok ok good to know! thank you again!

Sorry again, how to do round too the nearest whole number?

Try this:

state: "{{ (states('sensor.energy_day_fronius')|float / 1000)  | round(0)}}"

And with one decimal:

state: "{{ (states('sensor.energy_day_fronius')|float / 1000)  | round(1)}}"

1 Like

Thanks mate :slight_smile: Its still showing for example state: “1.8589”. i have tried changing the rounding number, but its not doing anything?

Sorry i missed parenthesis. These are now added in my original post

sweet! thank you! just the little things

1 Like

hey me again

Im getting an error now for the other template. I just applied the same logic for the one you showed me

state: "{{ (states('sensor.energy_year_fronius')|float / 1000)  | round(0)}}"
Invalid config for [template]: invalid template (TemplateSyntaxError: unexpected ')') for dictionary value @ data['sensor'][1]['state']. Got "{{ states('sensor.energy_year_fronius')|float / 1000) | round(0)}}". (See /config/configuration.yaml, line 345).

This is my yaml code

template:
  - sensor:
      - name: "Fronius Day Energy kWh"
        unit_of_measurement: "kWh"
        state: "{{ (states('sensor.energy_day_fronius')|float / 1000)  | round(0)}}"
      - name: "Fronius Yearly Energy kWh"
        unit_of_measurement: "kWh"
        state: "{{ (states('sensor.energy_year_fronius')|float / 1000)  | round(0)}}"
      - name: "Fronius Total Energy MWh"
        unit_of_measurement: "MWh"
        state: "{{ (states('sensor.energy_total_fronius')|float / 1000000)  | round(0)}}"

But the error

unexpected ')'     
"{{ states('sensor.energy_year_fronius')|float / 1000) | round(0)}}"

doesn’t match your current version

state: "{{ (states('sensor.energy_year_fronius')|float / 1000)  | round(0)}}"

Seems like you added the missing parenthesis before states. Right?

This is my yaml.

template:
  - sensor:
      - name: "Fronius Day Energy kWh"
        unit_of_measurement: "kWh"
        state: "{{ (states('sensor.energy_day_fronius')|float / 1000)  | round(0)}}"
      - name: "Fronius Yearly Energy kWh"
        unit_of_measurement: "kWh"
        state: "{{ (states('sensor.energy_year_fronius')|float / 1000)  | round(0)}}"
      - name: "Fronius Total Energy MWh"
        unit_of_measurement: "MWh"
        state: "{{ (states('sensor.energy_total_fronius')|float / 1000000)  | round(0)}}"

error message

Invalid config for [template]: invalid template (TemplateSyntaxError: unexpected ')') for dictionary value @ data['sensor'][1]['state']. Got "{{ states('sensor.energy_year_fronius')|float / 1000) | round(0)}}". (See /config/configuration.yaml, line 345).

And the error message?

updated previous message

But as i mentioned earlier.
Notice that in the error message there is no “(” before “state”,

Got "{{ states('sensor.energy_year_fronius')|float / 1000) | round(0)}}"

so it does not match your current version!

state: "{{ (states('sensor.energy_year_fronius')|float / 1000)  | round(0)}}"

When do you get the error?
Is it when you do “Check configuration” on the settings page?

Did you remember to save the file from which you copied the yaml code?

Hey sorry, so i updated this based on the error, then i went and check config, no issues. I ahve tested in Deveoper Tools, No issues
I then did YAML configuration reloading just for Template Entities and then when it gives me an error

Logger: homeassistant.config
Source: config.py:454
First occurred: 08:52:31 (1 occurrences)
Last logged: 08:52:31

Invalid config for [template]: invalid template (TemplateSyntaxError: unexpected ')') for dictionary value @ data['sensor'][1]['state']. Got "{{ states('sensor.energy_year_fronius')|float / 1000) | round(0)}}". (See /config/configuration.yaml, line 345).

ok i think i figured it out. my yaml file was not saved as i had a few yaml tabs open in Studio code!. thats fixed it!
IM so sorry! and thank you

1 Like