-
Notifications
You must be signed in to change notification settings - Fork 98
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
Comments
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}}" |
Think I have solved it. I'll paste my code when I have tested over a couple of weeks. |
following |
I'm currently using https://github.com/bramstroker/homeassistant-powercalc for it. :) |
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. |
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. |
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. |
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. |
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!
The text was updated successfully, but these errors were encountered: