kia_uvo icon indicating copy to clipboard operation
kia_uvo copied to clipboard

feat: EV sensors for average consumption & energy used

Open rsegers opened this issue 2 years ago ā€¢ 6 comments

This PR adds two sensors for EV's:

  • Average Energy Consumption (30 day moving average)
  • Total Energy Consumption

The average shows in watt per kilometer (mile) the average usage of the past 30 days. The total consumption shows in kwh the total energy consumption since the vehicle was connected to Bluelink. This sensor can be used in conjuction with the Home Assistant Energy dashboard as an individual device, allowing one to see daily, weekly, monthly statistics. The sensor also includes as attributes other information such as recuperation energy and climate usage (in watt).

This code has been running for more than a month now in my setup.

There are three considerations:

  1. Only tested in EU
  2. Only tested with EV. Not sure if the same / comparable api is available for fuel cars
  3. It requires two additional api calls. This counts towards the api limit. In my current setup this hasn't been an issue (6 min scan interval / 780 min force update / no black blackout). It is best to only make this call when doing a force update, however I've been unable to figure out to code this in a manageable way. Suggestions are welcome.

image image

rsegers avatar Mar 16 '22 14:03 rsegers

Could we have a few people test this out? My only worry would be calling it each refresh may impact total API calls. It seems like something we should only call if mileage has changed.

cdnninja avatar Apr 15 '22 01:04 cdnninja

It does impact the total API calls indeed. But as mentioned, my setup is 6 min scan interval + 13 hours force update + no blackout. These settings give me no issues with API limits.

I identified an issue with this sensor last week. The total consumption is only the sum of the last 92 days. So I need to rework this to a monthly sensor and utilise the last_reset attribute.

rsegers avatar Apr 15 '22 10:04 rsegers

Sounds great Looking forward to it being implemented šŸ‘

Symbiot78 avatar May 30 '22 20:05 Symbiot78

I'm eagerly waiting for this to be merged... I have set up a dashboard in Grafana (using InfluxDB) and have odometer metric and some battery metrics for my E-Niro. However would really like to be able to correlate this with energy used so I can get e.g. a monthly average. :)

patriknoomi avatar May 31 '22 09:05 patriknoomi

Since the API only returned the last 92 days, the sensor for total consumption wasn't working as expected. A moving total sum was returned, and the sensor was therefore able to decrease as well.

I'm now testing a monthly sensor, which should reset to 0 every month. However, I'm unsure whether the sensor entity should have the attribute 'last_reset' or not: I don't think it is necessary.

rsegers avatar Jun 11 '22 19:06 rsegers

The monthly sensor works perfect. The sensor now energy consumption sensor now only includes this month's usage. It resets on your first drive of the month (limitation of the API).

HA long term stats continues to accumulate after the reset and shows the all time total usage. The sensor is shown as expected in the HA energy dashboard.

I'd say it is good to go

rsegers avatar Jul 05 '22 19:07 rsegers

It does impact the total API calls indeed. But as mentioned, my setup is 6 min scan interval + 13 hours force update + no blackout. These settings give me no issues with API limits.

13h forced update seems oddly specific and not the default 4h - what's your logic there? I'm hoping to learn from it.

alexwhittemore avatar Oct 04 '22 01:10 alexwhittemore

It does impact the total API calls indeed. But as mentioned, my setup is 6 min scan interval + 13 hours force update + no blackout. These settings give me no issues with API limits.

13h forced update seems oddly specific and not the default 4h - what's your logic there? I'm hoping to learn from it.

In my opinion, force updates are not really necessary. Typically the car will connect to BlueLink if it has relevant data. Therefore, my scan interval is several minutes. But to be sure, the force update occurs always once a day, but never at the same time.

rsegers avatar Oct 04 '22 11:10 rsegers

In my opinion, force updates are not really necessary. Typically the car will connect to BlueLink if it has relevant data. Therefore, my scan interval is several minutes. But to be sure, the force update occurs always once a day, but never at the same time.

Ahh interesting strategy, I like that! Iā€™m experimenting with 0 forced updates right now because every 4 hours definitely prevents the car from going into deep sleep, and my aux battery saver + has stopped working, so under the constant 3W drain, my car needs a jump after 3 days or so idle. But the maximum setting available seems to be 999 minutes.

alexwhittemore avatar Oct 04 '22 13:10 alexwhittemore

Hi all,

After reading the release notes I noticed that 2 sensor's should have been added but I can only see the "Average Energy Consumption" one, "Total Energy Consumption" isn't showing up, not after reloading the integration or reconfiguring it.

Could someone please point me in the right direction what I should try next?

Thanks for the work!

edit: Car is a Ioniq 5. (EU based - Belgium)

dc911x avatar Oct 04 '22 18:10 dc911x

Look for Monthly energy consumption (Love the car!!)

Symbiot78 avatar Oct 04 '22 19:10 Symbiot78

Before I upset my API that just started giving me car battery measurements again - is this update only tested in EU or is it definitely not applicable in other markets?

alexw-im avatar Oct 04 '22 19:10 alexw-im

Look for Monthly energy consumption (Love the car!!)

Right, got it... Should have just opened the energy dashboard and looked in that list as it only shows fields that can be used in the dashboard...

I was looking at the sensors in the integration and focused to much on this screenshot afbeelding

Thanks again and kuddos for the people maintaining this!

dc911x avatar Oct 04 '22 20:10 dc911x

@rsegers - can we agree that you did NOT add a sensor showing the total amount of kW used from day 1 the car was added to bluelink? We have monthly usage & average consumption ( I do not know if this is average since day 1 of bluelink )

Symbiot78 avatar Oct 05 '22 16:10 Symbiot78

@rsegers - can we agree that you did NOT add a sensor showing the total amount of kW used from day 1 the car was added to bluelink? We have monthly usage & average consumption ( I do not know if this is average since day 1 of bluelink )

Yes, that is correct. BlueLink does not provide a total metric. However, the monthly sensor is configured in HA as a statistic and will thus calculate a total amount from the current month onwards for this sensor.

rsegers avatar Oct 05 '22 17:10 rsegers

Before I upset my API that just started giving me car battery measurements again - is this update only tested in EU or is it definitely not applicable in other markets?

I have only tested it in EU. You can of course always donate me a US car šŸ˜…

rsegers avatar Oct 05 '22 17:10 rsegers

for Average Energy Consumption (30 day moving average)

you can do the following to get km pr. kwh same calculation for mi pr. kwh

note: sensor.ioniq_5_average_energy_consumption is MY sensorname - change it to match yours!

- platform: template sensors: ioniq_km_kwh: friendly_name: Ioniq - Km pr Kwh value_template: "{{ (1 / (states('sensor.ioniq_5_average_energy_consumption') | float / 1000)) | round(2) }}"

Symbiot78 avatar Nov 30 '22 21:11 Symbiot78

Github doesn't add code well ..

  • platform: template sensors: ioniq_km_kwh: friendly_name: Ioniq - Km pr Kwh value_template: "{{ (1 / (states('sensor.ioniq_5_average_energy_consumption') | float / 1000)) | round(2) }}"

Symbiot78 avatar Nov 30 '22 21:11 Symbiot78