Calculating gCO2 from grid - quick how to

I couldn’t find a solution to calculating the gCO2 from the electricity grid and many people asking how to do it. This may not be the best way to do it, but here it is.

Key is sensor.energy_real_consumed_fronius_meter_0_fronius_lan is the sensor on my network which is a monotonically increasing sensor that measure my grid usage in wh. (hence the /1000 to convert to kwh in step3).

Assumes you have the Electricity Maps integration already configured and working.

Where I live the grid is dispatched every 5mins so the Electricity Maps CO2 number can’t update any more frequently than 5mins, hence choice of 5mins in the automation.

Needs 10mins or so to copy the figures through.

Step 1:

  • create two input_number helpers.

    input_number.fronius_grid_now
    input_number.fronius_grid_5mins_ago

set the max to a high number, make sure you set them to zero to start.

Step 2:

Automations to allow you to keep track of the usage in the last 5mins.

- id: '1691721512948'
  alias: Fronius Grid Usage Update
  description: ''
  trigger:
  - platform: time_pattern
    minutes: /5
  condition: []
  action:
  - service: input_number.set_value
    data:
      value: "{{ states('input_number.fronius_grid_now') }}"
    target:
      entity_id: input_number.fronius_grid_5mins_ago
  - service: input_number.set_value
    data: 
      value: "{{ states('sensor.energy_real_consumed_fronius_meter_0_fronius_lan')}}"
    target:
      entity_id: input_number.fronius_grid_now
  mode: single

Step 3: the template sensor:

template:
  - trigger:
      - platform: state
        entity_id:
        - input_number.fronius_grid_now
    sensor:
      - name: "grid import co2"
        unique_id: gridimportco2
        unit_of_measurement: gCO2
        device_class: power
        state: >
               {% set froniusnow = states('input_number.fronius_grid_now')|float(0.0) %}
               {% set fronius5ago = states('input_number.fronius_grid_5mins_ago')|float(0.0) %}
               {% set kwhconsumed = (froniusnow - fronius5ago)/1000 %}
               {% if fronius5ago < 2.0 %}
               {% set kwhconsumed = 0 %}
               {% endif %}
               {% set gramsCO2 = kwhconsumed * states('sensor.electricity_maps_co2_intensity')|float(0.0) %}
               {% set currentCO2 = states('sensor.grid_import_co2')|float(0.0) %}
               {{ (currentCO2 + gramsCO2) | round(2) }}

Nice work,

I have a similar approach starting with Electricity Maps;

image

I then multiply the emissions intensity by the grid power consumption to get my rate of carbon emissions.

    co2_emissions_displaced_rate:
      unit_of_measurement: gCO2eq/h
      value_template: "{{states('sensor.qld1_emission_factor')|float(0)*states('sensor.apf_grid_entity')|float(0)}}"
      unique_id: 44ef59fd-c3d4-4e44-83a6-d6d74e6173b3

image

Which I then use in integral to get my emissions:

- platform: integration
  source: sensor.co2_emissions_displaced_rate
  name: co2_emissions_displaced
  unit_prefix: k
  round: 1
  method: left
  unique_id: 73047c1c-28e7-4fcd-b575-81b487f94289

image

1 Like

nice - what’s your apf_grid_entity sensor derived from? I thought about different ways of doing this and maybe my ability to maths that gone.

The apf_grid_entity is just my power flow to/from the grid.

Very good approach @markpurcell . I also created a sensor today using your instructions.
But could it be that you have an error in your formula for the “co2_emissions_displaced_rate” given here?

co2_emissions_displaced_rate:
      unit_of_measurement: gCO2eq/h
      value_template: "{{states('sensor.qld1_emission_factor')|float(0)*states('sensor.apf_grid_entity')|float(0)}}"
      unique_id: 44ef59fd-c3d4-4e44-83a6-d6d74e6173b3

That would give me values that are too high for the consumption examples you have given here. Example:

700 gCO2eq/kWh * 10,000 W = 7,000,000 gCO2eq/h

So I think you should convert the grid consumption from W to kW as a supplement to your formula?

700 gCO2eq/kWh * 10 kW = 7000 gCO2eq/h

Yes you are correct.

Thanks

Hi Mark,
I try to do the same as you but I’m a complete HA beginner. Could you describe your method a bit more step by step? Do you also create helpers or do you put this code in your configuration.yaml? Thanks!

Helpers would be easier and can be configured using the UI.

Two steps from above and this two helpers required:

. Emissions displacement rate - template helper
Multiply the emissions factor * grid consumption

. Emissions displaced - integration helper

1 Like

I think it is important to realize that, while the Electricity Maps CO2 number is a good approximation of how well countries do with the production of carbon friendly energy production, it is in no way a good way to calculate how green the energy is that any individual household consumes. This has to do with how the energy market and carbon emission rights work. The HA energy dashboard, which does similar calculations, is making the same false assumption that you can use production percentages for consumption.

Let me try to explain why. In my country, the Netherlands, each consumer can choose to take a contract for a certain minimum amount of “green” energy. That green energy must be produced without fossil fuel. In my case, I chose a 100% green contract, so I pay to force my energy company to buy all CO2 free energy. The production percentage for the Netherlands is way below 100%, but my consumtion percentage is 100% because I payed extra for it. It means other must get less.

Add to that: Unfortunately, the Netherlands does not produce enough green energy.So my energy company needs to buy green energy abroad, for instance from Norway, which produces way more green energy than the Netherlands (kudos to them).

People who do not explicitly buy green energy (we call it gray energy) are told they get a mix of green and not green. But in reality, if people like me have already payed for all the green energy that is produced in the Netherlands, it cannot be that others in the Netherlands can also claim apart of their use as green.

In Norway, if a part of green energy produced is sold to abroad, that part of green production can also not be claimed by Norwegians. I do not know how energy contracts are sold there, but the international energy market is making it so that the percentage green energy produced is not the percentage that is consumed locally, because the energy company sold at least parts to other countries.

I actually disagree with you on this.

Whilst it is great you are paying for green energy and it is also great they are bringing additional green energy to the Netherlands to satisfy your demand this does reduce the carbon intensity of the Netherlands grid and if everyone did that you would have 100% renewable energy.

But unless you have a hardwired connection to those renewable energy generators (such as your own solar panels or a wind generator on your roof) then when you consume energy from the grid, even if you have paid for green energy, you are still consuming energy that has been generated from the mix of sources which are feeding the grid at that time, including fossil fuels. The company is unable to select which set of electrons you receive via your network connection.

Looking at the data for NL from yesterday, you have impressive solar and wind generation entities, but in the evening when the sun goes down that generation is being supplemented by gas generators with a high carbon intensity. If you are drawing from the grid at that time you are contributing to those CO2 emissions. Again looking at the data from yesterday during the solar peak the minimum carbon intensity during the day was still 123 gCO2e/ kWh. Which is a lot better than my network here which only gets down to a minimum of 400 gCO2e/ kWh.

1 Like

You are absolutely right that the actual energy delivered comes from local sources. Those can be green or grey sources depending on time of day and all sorts of other factors. The actual energy I use is always local and not always green. The production figures are calculated on a national scale. But if you live near a gas plant, chances are you consume 100% fossil. That is my whole point. National figures are not applicable on a personal scale.

But you do have to look at who is paying for the windmills and the gas plants. It is not fair that people who are paying low prices (that can only be achieved by using fossil fuel) feel good about themselves because they live in the vincinity of a windmill that is only feasible because others were prepared to pay extra.

But I do applaude people that try to balance their use based on moments when green energy is abundant though. That only applies if you really act on what the percentages say, not if you just look and do not change your behavior. Responsible energy use behavior benefits every one, regardless of what you paid. So I will give it to you that it is not clear cut. The numbers have their good use if interpreted right.

Local energymix might indeed vary but if you live next to the Eemshaven coal powerplant you also live near Drenthe which has abundant solarpanels. So it’s not automatically the case that if you live next to a coal powerplant you consume grey energy.
I have 16 solarpanels and consume about 40% of this energy right away in my all-electric house. You could say this produces 0 kg of CO2 (the panels were made with carbon naturally). I’m interested in the amount of CO2 I still consume from the grid which varies enormously during the day. It’s quite a simple sum as Marc describes, the problem is that I’m a nood at yaml coding :stuck_out_tongue_winking_eye:
I basically need yaml I can copy paste or need more time to learn yaml haha.
Thanks anyways. I hope HA will implement CO2 in the energydashboard since it’s such a big theme and a lot of people have no idea how much they produce

1 Like