audi_connect_ha
audi_connect_ha copied to clipboard
Feature request :D (total energy consumption)
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!
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. :)
Kolbi, how? I have powercalc installed and new stuff usually pops up automatically.
So far this i my best solution:
- a helper
and customizing the helper with:
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
Values from today :-)
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.
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.
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.
This issue is stale because it has been open for 45 days with no activity. Are you still experiencing this issue?
This issue was closed because it has been inactive for 15 days since being marked as stale.