Calculate revenue and sold electricity by Co-Charger

Hi there,

I’ve started selling energy to my neighbour.
I have a car charger, he lives in a flat and has an electric car.
There’s this app called Co-Charger, that takes care of the bookings and payments.

I would like to input this revenue on the energy dashboard. Tools at our disposal are:

  • I have info of the total kWh sold (on a session by session basis)
  • I cannot communicate with my charger (without modifying it)
  • I know how much is the price/kWh charged.
  • Needs to be easy to input.
  • I can detect when my car is charging.
  • I can infer that another car is charging, if the house total electric usage goes above the 7.2 kW and my car is not charging.

Could do a clock, that triggers once the house usage is over 7.2kW AND my car is not charging, then multiply the clock for the price/kWh :thinking: could work…

Does anyone have any elegant idea idea of how to implement this?

I just saw you on discord with your template sensor and so I think this is where you’re going, and if it is then I agree it’s the right path, which is to do everything automated in HA with no manual entry.

  1. Create template sensor that is the assumed charge power of the car. Would be zero normally, and will be the expected charging power when you detect charging is happening.
  2. Create a Riemann sum integral to calculate the charge energy consumed. You will want to use the max_sub_interval since your power is a fixed number and won’t trigger updates to the sensor during the charging session.

Thank you for your help @mekaneck “Indentation matters!”
For future reference, in case anyone has the same need in the future:

  1. Getting Co Charger usage Power
    Create a template sensor, stored in “templates.yaml” that “measures” the charge power “7200 W” when the home electricity usage goes above 7200 W and the Car is not plugged to the Charger.
sensor:  
  - name: Co Charger Power
    unique_id: co_charger_power
    state: >
      {% if (states('sensor.local_load_power')|float > 7200) and 
        (is_state('binary_sensor.car_charger_plug', 'off')) %}
        {{ 7200 }}
      {% else %}
        {{ 0 }}
      {% endif %}
    unit_of_measurement: "W"
    device_class: power
  1. Convert the Power (W) into Energy (kWh)
    I used the PowerCalc integration to convert the power sensor created in step 1. in an energy sensor (kWh) and give me a couple of daily, weekly, monthly consumption stats.
    You can also use the Riemann sum integral like @mekaneck suggested. Might be a simple way but I had already gone the Powercal pathway.

  2. Calculate Revenue
    First created a Number Helper, with an input field I will use this to put the unit price of energy sold to Co Charger.
    Then, created another template sensor, to convert the number created into a sensor:

sensor:
  - name: CO Charger Cost
    state: "{{ states('input_number.co_charger_gbp_kwh') }}"
    unit_of_measurement: "GBP/kWh" 

With the help of Dynamic Energy Cost, use the “Cost sensor” you’ve just created and get the daily, weekly, monthly revenue with Co Charger.

  1. Incorporate this in your energy Dashboard
    Now that we have the Co Charger energy and the Co charger Cost, simply add this on your “Return to Grid” list of devices, with a cost that is linked to the entity Co Charger cost you’ve just created.

Uff… I bet there’s a simpler way to do this, but, for now, this will have to do.