Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request :D (total energy consumption) #258

Open
devslash0 opened this issue Mar 6, 2024 · 10 comments
Open

Feature request :D (total energy consumption) #258

devslash0 opened this issue Mar 6, 2024 · 10 comments
Labels
enhancement New feature or request

Comments

@devslash0
Copy link

How about creating a sensor for total energy consumption? I would love to track energy consumtion in home assistant energy dashboard. Have tried to make my own sensor but without luck.

If anyone else has done this, please share. But the best would be a feature in this module.

Thanks. Have a nice day!

@wigster
Copy link

wigster commented Mar 6, 2024

Not sure it's the right place but here is the sensor I have -- it's based on the energy efficiency being reported by the short trip sensor, which now no longer seems to in the API. I have a hybrid, so I do some calculations for EV vs ICE in different modes, so this is a bit more complex than it needs to be.

  - name: Smurf total battery consumption
    unique_id: "eryiukesspueorccthuloprth"
    icon: mdi:ev-station
    device_class: energy
    unit_of_measurement: kWh
    state_class: total_increasing
    state: >
      {% set current = this.state |float(0) %}
      {% set increment = 0|float %}
      {% if tripID != 0 %}
      {% set lastTripID = this.attributes.get('last_trip_id',0)%}
      {% set last_batt = this.attributes.get('last_batt_consumed',0)%}
      {% if tripID == lastTripID %}
      {% set increment = batt_consumed - last_batt%}
      {% else %}
      {% set increment = batt_consumed%}
      {%endif%}
      {%endif%}
      {{(current + increment)|round(3)}}
    attributes:
      last_trip_id: >
        {% set lastTripID = this.attributes.get('last_trip_id',0)%}
        {{tripID if (tripID!=0) else lastTripID}}
      last_batt_consumed: >
        {% set lastTripID = this.attributes.get('last_trip_id',0)%}
        {% set last_batt = this.attributes.get('last_batt_consumed',0)%}
        {{batt_consumed if (tripID!=0) else last_batt}}
  trigger:
    - platform: state
      entity_id: sensor.smurf_trip_short_current
      not_to:
        - "unknown"
        - "unavailable"
        - "None"
    - platform: event
      event_type: "SMURF_TRIP"
  action:
    variables:
      tripID: >-
        {%set tripID = state_attr('sensor.smurf_trip_short_current','tripID')%}
        {{tripID if tripID|is_number else 0}}
      is_gas_trip: "{{state_attr('sensor.smurf_trip_short_current','averageFuelConsumption')|float>states('input_number.smurf_ev_trip_threshold')|int}}"
      is_ev_trip: "{{state_attr('sensor.smurf_trip_short_current','averageFuelConsumption')|float<=states('input_number.smurf_ev_trip_threshold')|int}}"
      mileage: "{{state_attr('sensor.smurf_trip_short_current','mileage')|float}}"
      gas_consumed: "{{state_attr('sensor.smurf_trip_short_current','averageFuelConsumption')|float*mileage/100}}"
      batt_consumed: "{{state_attr('sensor.smurf_trip_short_current','averageElectricEngineConsumption')|float*mileage/100}}"

@devslash0
Copy link
Author

Think I have solved it. I'll paste my code when I have tested over a couple of weeks.

@oleg-d
Copy link

oleg-d commented Mar 14, 2024

following

@Kolbi
Copy link
Contributor

Kolbi commented Apr 2, 2024

I'm currently using https://github.com/bramstroker/homeassistant-powercalc for it. :)

@devslash0
Copy link
Author

Kolbi, how? I have powercalc installed and new stuff usually pops up automatically.

So far this i my best solution:

image

  • a helper

and customizing the helper with:

image

Works 95% good. But since Audi does not allow 1 minut update I loose alot of data :/

I wonder if the API itself has the values we/I want :D

@devslash0
Copy link
Author

image

Values from today :-)

@wigster
Copy link

wigster commented Apr 2, 2024

Kolbi, how? I have powercalc installed and new stuff usually pops up automatically.

Well you could take your power meter as you have defined it in the template up there and then use powercalc to create an energy meter from that -- you'd need to create an "Energy from a real power sensor" sensor on the Powercalc integration page.

@wigster
Copy link

wigster commented Apr 2, 2024

Kolbi, how? I have powercalc installed and new stuff usually pops up automatically.

Well you could take your power meter as you have defined it in the template up there and then use powercalc to create an energy meter from that -- you'd need to create an "Energy from a real power sensor" sensor on the Powercalc integration page.

One thing to say here -- you'll notice there is about a 20% difference in the amount of energy you use to charge your car and the amount of energy that car will report to have used if you look at the trip data. Those are the losses during charging and they are real. The car only reports the net figure in its kWh/100km statistics.

@oleg-d
Copy link

oleg-d commented Apr 8, 2024

I use an HA helper called Riemann sum integral to gather the total kWh consumption, the source being the audi charging rate (kW), you can set this source as another template sensor if you wish to. The Riemann sum integral gathers the kWh consumption for you without the need for additional integrations.

And then an utility sensor (monthly in my case) with the source as the riemann integral sensor.

@coreywillwhat coreywillwhat changed the title Feature request :D Feature request :D (total energy consumption) Apr 8, 2024
@coreywillwhat coreywillwhat added the enhancement New feature or request label Apr 8, 2024
@coreywillwhat
Copy link
Contributor

coreywillwhat commented Apr 15, 2024

FYI - Trip data should be fixed in #382 . I know this doesn't solve the original enhancement request, but its part of the issue so providing for awareness.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

5 participants