# Solar production minus Electric usage

Hi,

Does anyone know how to create a graph which shows the total solar energy production and the total electric consumption. I like to know how much energy there is left for me to use without paying extra.

And if possible from a specific date because I got my solar panels half of February.

Better will be just one value showing for example +126kWh (in green) if I have power left or when I used more than I produced: -150kWh in red.

EDIT:
I can read my total solar energy production from:

And I can read my total power import:
sensor.p1_meter_3c39e72f22ca_total_power_import

But my total power import is like 20.000 kWh so I need to read the total from a specific date when my solar panels where installed so I can check what my usage will be.

At the end I want to have a formula like:
total-energy-production - total-energy-import = some_value

Hope someone can help me getting this working.

Thanks!

Are you sure this is how your energy company actually bills you? Usually you can not consume power from the grid for free which you returned to the grid at an earlier point in time. Rather you would look at what you are producing at this very moment and if you are producing more then you consume, you can use the delta without paying extra.
There might be some country where what you describe is actually practised, but just making sure

In my country (The Netherlands), your total solar energy is viewed per year and deducted from your total consumption. Everything you still have in the plus after that, you get back at a certain rate that is lower than what you would pay yourself.

So if your yearly solar energy production is 4500kwh and your total consumption from the net is 3000, the company will pay you 1500*0,16 = 240 euro. My contract is from march till march, that is why I need to show it from a specific date.

My guess is that this user lives in The Netherlands. There is a law stating that the energy deliverd to the grid can be use at a later time with no additional costs.

On topic. the user could create an input_number stating the correct start value from when the panels were installed.

Ok, I thought I had heard about such a system, but it almost seems too good to be true

To set it up correctly the billing question remains: is the delta calculated over lifetime, or does it reset at defined intervals (monthly, yearly)?

I have created a template with the help of my brother:

``````energie_usage_this_year_color:
friendly_name: Verbruik dit jaar
value_template: >-
{% if states('sensor.import_energie_dit_jaar')|float > states('sensor.envoy_122244026326_lifetime_energy_production')|float %}
-{{ ((states('sensor.import_energie_dit_jaar') | float ) - (states('sensor.envoy_122244026326_lifetime_energy_production') | float )) | round(3) }}
{% elif states('sensor.envoy_122244026326_lifetime_energy_production')|float > states('sensor.import_energie_dit_jaar')|float %}
+{{ ((states('sensor.import_energie_dit_jaar') | float ) - (states('sensor.envoy_122244026326_lifetime_energy_production') | float )) | round(3) }}
{% endif %}
unit_of_measurement: "kWh"
icon_template: mdi:transmission-tower
``````

But that is for this year starting at 1 January, but Iâ€™m already a step further. The only thing I need now is to start it on the 19th of February and show it in a red color when I used more than I produced and show in green when I produced more than I used

Do you have your starting value for your â€śThis Yearâ€ť import sensor on the day your Solar PV went liveâ€¦you could just use your Template to subtract this from the reported This Year sensor value and then youâ€™d have an import value from 19th Feb onwardsâ€¦
Iâ€™m sure there are better solutions to this but crude at this is it will prob do what you needâ€¦

Isnâ€™t this about â€śreturn to the gridâ€ť value which we can get from the p1 meter? That would be the excess electricity from the solar production we donâ€™t use.

That value minus the total electricity consumption would be the value you are looking for.

Thatâ€™s my understanding.

Oh, and I live in the Netherlands as well.

Yes, you are right. Iâ€™m using the Homewizard P1 meter and I think that should be able to show me the export energy.

I have powerwall with solar and I have my energy set up to display daily, weekly, monthly and yearly energy usage. See below:

Here is my code for the custom card:

``````type: custom:plotly-graph
entities:
- entity: sensor.daily_kwh_produced
- entity: sensor.daily_kwh_from_grid
- entity: sensor.daily_kwh_to_grid
- entity: sensor.daily_kwh_usage
hours_to_show: 48
refresh_interval: 10
title: Daily Energy Usage
``````

Here are my sensors, utility meters and templates

``````# ---------------------------------------------------------------------------------------------
# Average produced over the last hour
# ---------------------------------------------------------------------------------------------
- platform: statistics
name: "Average kW Produced Last Hour"
entity_id: sensor.powerwall_solar_now
state_characteristic: mean
max_age:
hours: 1
sampling_size: 720
precision: 3
# ---------------------------------------------------------------------------------------------
# Average over the last 24 hours
# ---------------------------------------------------------------------------------------------
- platform: statistics
name: "Average kW Produced Last 24 Hour"
entity_id: sensor.powerwall_solar_now
state_characteristic: mean
max_age:
hours: 24
sampling_size: 17280
precision: 3

# ---------------------------------------------------------------------------------------------
# Average over the last hour
# ---------------------------------------------------------------------------------------------
- platform: statistics
name: "Average kW Used Last Hour"
state_characteristic: mean
max_age:
hours: 1
sampling_size: 720
precision: 3

# ---------------------------------------------------------------------------------------------
# Average over the last 12 hours
# ---------------------------------------------------------------------------------------------
- platform: statistics
name: "Average kW Used Last 12 Hour"
state_characteristic: mean
max_age:
hours: 12
sampling_size: 8640
precision: 3

# ---------------------------------------------------------------------------------------------
# Average over the last 24 hours
# ---------------------------------------------------------------------------------------------
- platform: statistics
name: "Average kW Used Last 24 Hour"
state_characteristic: mean
max_age:
hours: 24
sampling_size: 17280
precision: 3

# ---------------------------------------------------------------------------------------------
# Minimum over the last 24 hours
# ---------------------------------------------------------------------------------------------
- platform: statistics
name: "Minimum kW Used Last 24 Hour"
state_characteristic: value_min
max_age:
hours: 24
sampling_size: 17280
precision: 3

# ---------------------------------------------------------------------------------------------
# Maximum over the last 24 hours
# ---------------------------------------------------------------------------------------------
- platform: statistics
name: "Maximum kW Used Last 24 Hour"
state_characteristic: value_max
max_age:
hours: 24
sampling_size: 17280
precision: 3
``````

Utility Meters:

``````#  ------------------------------------------------------------------------------------
#  Energy Consumed
#  ------------------------------------------------------------------------------------
daily_energy:
source: "sensor.energy_consumed"
name: "Daily kWh Usage"
cycle: daily

weekly_energy:
source: "sensor.energy_consumed"
name: "Weekly kWh Usage"
cycle: weekly

monthly_energy:
source: "sensor.energy_consumed"
name: "Monthly kWh Usage"
cycle: monthly

yearly_energy:
source: "sensor.energy_consumed"
name: "Yearly kWh Usage"
cycle: yearly

#  ------------------------------------------------------------------------------------
#  Solar Energy Produced
#  ------------------------------------------------------------------------------------
daily_energy_produced:
source: "sensor.solar_energy_produced"
name: "Daily kWh Produced"
cycle: daily

weekly_energy_produced:
source: "sensor.solar_energy_produced"
name: "Weekly kWh Produced"
cycle: weekly

monthly_energy_produced:
source: "sensor.solar_energy_produced"
name: "Monthly kWh Produced"
cycle: monthly

yearly_energy_produced:
source: "sensor.solar_energy_produced"
name: "Yearly kWh Produced"
cycle: yearly

#  ------------------------------------------------------------------------------------
#  Energy to Battery
#  ------------------------------------------------------------------------------------
daily_energy_battery_to:
source: "sensor.energy_to_battery"
name: "Daily kWh to Battery"
cycle: daily

weekly_energy_battery_to:
source: "sensor.energy_to_battery"
name: "Weekly kWh to Battery"
cycle: weekly

monthly_energy_battery_to:
source: "sensor.energy_to_battery"
name: "Monthly kWh to Battery"
cycle: monthly

yearly_energy_battery_to:
source: "sensor.energy_to_battery"
name: "Yearly kWh to Battery"
cycle: yearly

#  ------------------------------------------------------------------------------------
#  Energy from Battery
#  ------------------------------------------------------------------------------------
daily_energy_battery_from:
source: "sensor.energy_from_battery"
name: "Daily kWh from Battery"
cycle: daily

weekly_energy_battery_from:
source: "sensor.energy_from_battery"
name: "Weekly kWh from Battery"
cycle: weekly

monthly_energy_battery_from:
source: "sensor.energy_from_battery"
name: "Monthly kWh from Battery"
cycle: monthly

yearly_energy_battery_from:
source: "sensor.energy_from_battery"
name: "Yearly kWh from Battery"
cycle: yearly

#  ------------------------------------------------------------------------------------
#  Energy to Grid
#  ------------------------------------------------------------------------------------
daily_energy_grid_to:
source: "sensor.energy_to_grid"
name: "Daily kWh to Grid"
cycle: daily

weekly_energy_grid_to:
source: "sensor.energy_to_grid"
name: "Weekly kWh to Grid"
cycle: weekly

monthly_energy_grid_to:
source: "sensor.energy_to_grid"
name: "Monthly kWh to Grid"
cycle: monthly

yearly_energy_grid_to:
source: "sensor.energy_to_grid"
name: "Yearly kWh to Grid"
cycle: yearly

#  ------------------------------------------------------------------------------------
#  Energy from Grid
#  ------------------------------------------------------------------------------------
daily_energy_grid_from:
source: "sensor.energy_from_grid"
name: "Daily kWh from Grid"
cycle: daily

weekly_energy_grid_from:
source: "sensor.energy_from_grid"
name: "Weekly kWh from Grid"
cycle: weekly

monthly_energy_grid_from:
source: "sensor.energy_from_grid"
name: "Monthly kWh from Grid"
cycle: monthly

yearly_energy_grid_from:
source: "sensor.energy_from_grid"
name: "Yearly kWh from Grid"
cycle: yearly
``````

And My templates

``````
#--------------------------------------------------------------------------------------------------
# For Grid to Home/Battery pricing - Usage price I pay from the grid
#--------------------------------------------------------------------------------------------------
- sensor:
- name: "grid_to_home_energy_price"
unique_id: "Grid to Home Energy_Price"
state: >-
{% if states('sensor.powerwall_site_now') | float(0) > 0.001 %}
{{ state('input_number.kwh_cost_from_grid') }}
{% else %}
0.000
{% endif %}
unit_of_measurement: "USD/kWh"

#--------------------------------------------------------------------------------------------------
# For Solar to Grid pricing - Generation price I sell to the grid
#--------------------------------------------------------------------------------------------------
- sensor:
- name: "solar_to_grid_energy_price"
unique_id: "Solar to Grid Energy_Price"
state: >-
{% if states('sensor.powerwall_site_now') | float(0) < -0.001 %}
{{ states('input_number.kwh_revenue_to_grid') }}
{% else %}
0.000
{% endif %}
unit_of_measurement: "USD/kWh"

#--------------------------------------------------------------------------------------------------
# Power to Grid - Make Positive
#--------------------------------------------------------------------------------------------------
- sensor:
- name: "Power to Grid"
unique_id: "Power to Grid"
state: >-
{% if states('sensor.powerwall_site_now') | float(0) < -0.0001 %}
{{ states('sensor.powerwall_site_now') | float(0) | abs}}
{% else %}
0.000
{% endif %}
unit_of_measurement: "kW"

#--------------------------------------------------------------------------------------------------
# Power from Grid - Make Positive
#--------------------------------------------------------------------------------------------------
- sensor:
- name: "Power from Grid"
unique_id: "Power From Grid"
state: >-
{% if states('sensor.powerwall_site_now') | float(0) > 0.001 %}
{{ states('sensor.powerwall_site_now') }}
{% else %}
0.000
{% endif %}
unit_of_measurement: "kW"

#--------------------------------------------------------------------------------------------------
# Power to Battery  - Make Positive  sensor.powerwall_battery_now
#--------------------------------------------------------------------------------------------------
- sensor:
- name: "Power to Battery"
unique_id: "Power to Battery"
state: >-
{% if states('sensor.powerwall_battery_now') | float(0) < -0.001 %}
{{ states('sensor.powerwall_battery_now') | float(0) | abs}}
{% else %}
0.000
{% endif %}
unit_of_measurement: "kW"

#--------------------------------------------------------------------------------------------------
# Power from Battery  - Make Positive  sensor.powerwall_battery_now
#--------------------------------------------------------------------------------------------------
- sensor:
- name: "Power from Battery"
unique_id: "Power from Battery"
state: >-
{% if states('sensor.powerwall_battery_now') | float(0) > 0.001 %}
{{ states('sensor.powerwall_battery_now') }}
{% else %}
0.000
{% endif %}
unit_of_measurement: "kW"

``````
3 Likes