martinarva / dynamic_energy_cost

62 stars 13 forks source link

Add support for different currencies #8

Closed dunxd closed 5 months ago

dunxd commented 5 months ago

This looks awesome. I'm trying to calculate the cost of charging my car each night, and this is currently non-trivial for people without a degree in mathematics and a deep deep understanding of Home Assistant (I'm five years in and this has me stumped).

It would be great if I could choose which currency to use - I'm in the UK so would love GBP or £.

martinarva commented 5 months ago

As for now the integration is using EUR as hardcoded currency, but you can feed in your GBP/h as price entity. Result cost sensors unit_of_measurement is EUR, but the value is correct. It's in my to do to make logic that will take the unit of measurement from the inserted energy cost sensor. Meanwhile, you can change the unit of measurement manually in UI.

martinarva commented 5 months ago

@dunxd

When using energy sensor (kwh) currency will be extracted from the price sensor now.

Adding it to the power sensor flow is still in todo

Release: https://github.com/martinarva/dynamic_energy_cost/releases/tag/v0.2.3

dunxd commented 5 months ago

I'm not seeing that reflected in the sensor since updating this integration half an hour ago.

The current rate sensor from the Octopus Energy integration reports the rate as GBP/kWH. It does not have a separate currency attribute as far as I can tell.

dunxd commented 5 months ago

I had a hunch that the currency was detected when the device added, and created new devices and it is now detecting GBP on devices created with energy sensors.

Are you using Reimann integration to calculate cost for energy when given power input?

martinarva commented 5 months ago

Hi!

The dynamic currency is done only for energy (kWh) sensors for now. If you use power sensor as an input dynamic currency is not implemented yet, because I had some issues with it and did not have time yesterday to solve it.

As of calculating cost from power, yes I'm using Reiman Sum logic, but that's not as precise as calculating from energy input. So my recommendation is to use the energy input if it's available.

There are some nice features when energy input is used compared when power input is used:

I will do these tings for power based sensors as well, but for some reason code for these are fragile and will break every time I try to do something with it. It uses a bit different way of communicating to Home Assistant.

dunxd commented 5 months ago

Great. Since I don't only have a power sensor I will probably use the Energy sensor as input based on your advice.

Since I am using this to calculate things relating to my EV there is something else I am trying to achieve which perhaps this sensor can help with.

I want to see the average of the maximum charge added over a month, based on noon till noon. This will help me choose a better figure for telling my charger what to add by default each night. My car cannot tell my charger it's level of charge so I can't say "fill to 80%". I have to make that calculation every day. An average would probably be good enough for most days.

martinarva commented 5 months ago

I want to see the average of the maximum charge added over a month, based on noon till noon. This will help me choose a better figure for telling my charger what to add by default each night. My car cannot tell my charger it's level of charge so I can't say "fill to 80%". I have to make that calculation every day. An average would probably be good enough for most days.

Could you describe a bit more what you try to achieve. Also which car you have.

dunxd commented 5 months ago

All my sensors have switched to EUR since the last update, even the ones that started out as GBP.

dunxd commented 5 months ago

I have a Nissan Leaf. This doesn't allow direct access - HA has to go to the Nissan Connect service via an integration. The sensors from that integration replicate what is available in Nissan's own app. The app doesn't update very frequently so I don't think it is capable of giving better than summary data.

The Myenergi integration is where I get all the stats relating to charging, as HA can query it directly.

Initially I'm trying to make a dashboard that tells me the status of the car, how far it is driven, how much energy is used per day, how much I am putting in for the last charge, average for week and month, and how much it costs. I'd like to see how much energy I typically use so I can better configure the Zappi to charge the amount I typically need rather than just set it to 100% which actually takes about twice as long as charging to 80%. It is not possible for the Zappi to be set to charge to 80% as it cannot see the current charge in the car due to Nissan's locked down system - rather I can set the amount of kWh to put in. It allows scheduling - I want the average kWh figure to use for most nights schedule.

If I can report all these things, there are opportunities to automate but I'm starting with capturing data.

Your integration allowed me to calculate costs quickly and easily, without resorting to Reimann integrations or Utility Meters which I am finding very hard to understand. I think it could be extremely useful to drivers of many EVs that are often hampered by similarly locked down APIs to Nissan's.

dunxd commented 5 months ago

I set up some new integrations using energy input that initially reported GBP as per the rate input, but these have all changed to EUR, so I don't think this is resolved.

dunxd commented 5 months ago

Ok - I got the latest version and it has gone back to GBP 👍