'Solar as a percentage of home usage' sensor

I’m trying to build a solar percentage sensor to show how much of the home usage was solar and how much from the grid.
I’m struggling with the template.
I’m trying to action…

100 / consumption * production

# Renewables Percentage Sensor
  - platform: template
    sensors:
      daily_solar_percent:
        value_template: '{{( int 100 | float * 1.0 ) / (states.sensor.enph_envy_daily_consumption.state | float | round(1) ) * (states.sensor.envoy_daily_production.state)}}'
        unit_of_measurement: '%'
        friendly_name: Daily Solar Percentage

not winning so far :open_mouth:
would welcome a little help if anything looks obvious or there is a better approach?

Thanks :slight_smile:

1 Like
"{{ ( 100 / ( states('sensor.enph_envy_daily_consumption')|float * states('sensor.envoy_daily_production')|float ) )|round(1) }}"

Though I don’t think this is the equation you want:

100 / consumption * production

I think you want:

100 * consumption / production

Which would be:

"{{ ( 100 * states('sensor.enph_envy_daily_consumption')|float / states('sensor.envoy_daily_production')|float )|round(1) }}"

This will give your consumption as a percentage of your production. Over 100% = grid import.

1 Like

Thanks Tom :slight_smile:
It works! :slight_smile:

Untitled

value_template: "{{ ( 100 / states('sensor.enph_envy_daily_consumption')|float * states('sensor.envoy_today_s_energy_production')|float )|round(1) }}"
1 Like

No, I think Tom is right

I have no idea of the dimensions of your entities but let’s say the first figure is what you get off grid and is 80kWh (let’s make the figures easy to work with) then the second figure is what you get from the solar array (20kWh)
So by your formula 100/80 * 20 = 25
Say they are 50 and 50
100/50*50 = 100 eh!
So use Tom’s 20/(80 + 20) * 100 = 20% of total usage
Or 20/80 * 100 = 25% of what you are buying in, this makes no sense, why does that matter, surely you want percentage of total consumption the 50/50 usage case would then go to 50/(50 sol + 50 grid) * 100 = 50%

I’m still not seeing how consumption multiplied by production gives you a ratio?

You need to divide one by the other for that.

I was shooting for
100 divided by consumption multiplied by production.
I think that’s the right calculation… :open_mouth:

ideally i’d want to discount export as well to get a true gauge of used solar, but one step at a time :wink:

I’m positive it isn’t. Lets try some examples:


Produced 100kWh
Used     60kWh  (i.e. used 60% of produced solar energy)

Your calc: 100 / (100 * 60) = 0.016%

My calc:   100 * (60 / 100) = 60%

Produced 100kWh
Used     120kWh  (i.e. imported 20kWh)

Your calc: 100 / (100 * 120) = 0.0083%

My calc:   100 * (120 / 100) = 120%

If it’s to complicated with the percentage then just have two charts.
One with production and one with usage.

But I do agree with Tom, that is how both modern and historic math used to calculate it.

Edit but then again, whatever value you get, as long as you can compare it with another value and it makes sense to you. Then we shouldn’t argue.
But just thinking about it makes me believe that your method will not give linear results so it could be harder to interpret.
But whatever you want is your choice

:woozy_face:

I think this thread gives great examples and reasons behind them, thanks so much for helping.
I think I should go back to school too! :laughing:

Hi, can you share the code please?

the sensor… and also how to play with a few different templates lol.
it seems to be giving me what I need but solar is always less than demand this time of year.
if you come up with a better solution, post it up :wink:

  - platform: template
    sensors:
      daily_solar_percent:
#       value_template: '{{(( states.sensor.enph_envy_daily_consumption.state | int / 100 ) * (( states.sensor.envoy_daily_production.state )) )}}'
# original       value_template: "{{ ( 100 * states('sensor.enph_envy_daily_consumption')|float / states('sensor.envoy_today_s_energy_production')|float )|round(1) }}"
        value_template: "{{ ( 100 / states('sensor.enph_envy_daily_consumption')|float * states('sensor.envoy_today_s_energy_production')|float )|round(1) }}"
#       value_template: "{{ ( 100 / states('envoy_today_s_energy_production')|float * states('sensor.enph_envy_daily_consumption')|float )|round(1) }}"
        unit_of_measurement: '%'
        friendly_name: Daily Solar Percentage

Hi all,

not sure if someone will be able to use it. but this is my calculation.
It uses the total (actual) output power in watt and the total (actual) consumption power in kW.

this way the sensor will always output a maximum of “100%”.

value_template: "{{ ((states('sensor.growatt_total_output_power')|float * 100) / ((states('sensor.power_consumption')|float * 1000) + states('sensor.growatt_total_output_power')|float))|round(1) }}"

Since this is not the normal way of calculating, you should probably explain what it does.

I mean what does 100% mean?
What does 0% mean? What is 50% and so on, so that we can understand what the output is.
Not that it bothers me since I don’t have solar panels or power monitoring…

It does exactly what the title says:
'Solar as a percentage of home usage’ sensor

So why bother?

And why is this not a normal way of calculating?! This is just an ordinary ratio table.

It shows how many % of the total energy produced by solar panels (output power) is part of the total home usage (consumption). So if all power in the home is used from solar is shows 100%. If more solar power is produced than the home uses, it still shows 100%.

If less solar power is produced than the home uses it show how much power the home uses from solar.

I should probably show my need for such a sensor.
I use home assistant and a variable load hot water service to try to use as much of my solar as possible during the day.
Power prices in Australia are high and solar ‘feed-in’ is low. Self-consumption is promoted, I’m just taking it to the logical next level.
I hope to use the percentage as a ‘scorecard’ to show how well both us in our habits and home assistant in her automation are doing.

No need to be angry.
But this is not what most others have.
Most other want to know how much electricity goes back in to the grid, this is not something your calculation can show since it caps off at 100%.

I am not angry.

Why would one need to know how many “percent” goes back in to the grid? What’s that usefull for?

I calculate that per pay in kWh.

I think you’re right, however I have a different problem regarding this.

In my specific case, the instant consumption sensor will get negative when my solar panels are producing more than the house is consuming, and by consequence the daily consumption sensor will stall. Meaning that this math won’t be truly valid since it doesn’t take into account all the effective consumption.

Does anyone have any idea on how to reach the purpose of this thread regarding my case?

Thanks!

Actually I must agree with you… if all daily (hourly) consumption is less then solar energy daily (hourly) production then ratio is 100%.
If daily use is greater then solar production then percentage is less then 100%.
If daily solar production is = 0 (let’s say in cold winter with snow falling with no sun) then percentage is = 0%.

So by my point of view I totaly agree with you…

My question is where to add this created sensor in HA:

Do I simply add another return [marked with red color] or how do you achieved that there is data in “own solar consumption percentage”…

How your settings looks?

Thank you for helping…