dreautall / ha-stromnetzgraz

Home Assistant Custom Component for Stromnetz Graz
MIT License
17 stars 1 forks source link

Adding Costs to Meter Consumption Data #8

Open sebinity opened 1 year ago

sebinity commented 1 year ago

Hi, thanks for the great integration - it's been showing up-to-date kWh consumption data on my Energy Dashboard in HA extremely reliably so far. Which is why I've decided to go the next step of including consumption costs based on market prices and - after collecting some data - move to a contract with dynamic pricing.

The problem is that, after selecting the stromnetzgraz:energy_consumption_XXX to the dashboard, adding costs to it is greyed out and not selectable any more: image

Trying to add a sensor tracking the EPEX spot price results in an error: image

Cannot specify stromnetzgraz:energy_consumption_XXXXXXXX more than once for dictionary value @ data['energy_sources'][0]['flow_from']. Got [{'stat_energy_from': 'stromnetzgraz:energy_consumption_XXXXXXXX', 'stat_cost': 'stromnetzgraz:energy_consumption_XXXXXXXX', 'entity_energy_price': None, 'number_energy_price': None}, {'stat_energy_from': 'stromnetzgraz:energy_consumption_XXXXXXXX', 'stat_cost': None, 'entity_energy_price': 'sensor.epex_spot_at_net_price', 'number_energy_price': None}]

My assumption is that since the values in the consumption sensor are backfilled and not live, they don't want to work with a live data sensor. So my question now would be, is there a way around this?

dreautall commented 1 year ago

The only way I can imagine right now is that the integration does it itself - i.e. you (somehow) specify a sensor name in the integration settings (just like you do with your username/password) and it then calculates the price in a separate sensor while it backfills data.

I need to check if there is a proper way to pass a (foreign) sensor to the integration. I think I haven't seen an integration so far which does this...

dreautall commented 8 months ago

After digging into this a bit, it looks like I found a way to make it work - currently still WIP here: https://github.com/dreautall/ha-stromnetzgraz/tree/prices

It will rely on another sensor that provides continuous price data (expected in EUR/kWh). When the twice daily fetch runs that updates the statistic sensor, it will also update a second statistic sensor with the price data. This seems to work in HA from my first tests.

Obviously the integration will only backfill data as long as the price sensor existed in the past. I do not plan on adding an option to backfill with a static price or something like that.

Not sure yet what to do when the price sensor gets changed afterwards by the user. I guess the sensible thing is to keep all old price data. The other option would be to delete all prices and recalculate them with the new sensor...

I still need to flesh this out a bit (especially the "UI" part where you can put in the price sensor).

sebinity commented 8 months ago

Hey, thanks a lot for your effort on this! Unfortunately, I don't have a way test it. Stromnetz Graz doesn't let me access my meter data since mid of January - so no data for me to test this on...

sebinity commented 6 months ago

Hey, so they have been able to get my smart meter back online so I can report back on the status and a few bits of feedback.

Overall, the price integration worked really well, it seems to calculate prices that are in the correct ballpark. I'll check exactly after this month when I get all data, but it seems to work. It updates well with each daily set of energy data. I'll stay on this branch until you'll merge it into main since I am quite happy with it. Thanks a lot for your work so far: image

The only little bug I found was that, for some reason, the selectors for the Price sensor seemed to multiply on my Home Assistant instance with each reinstall: image

A few bits and pieces of feedback that were a little confusing to me and may also be for new users that may be some additions for the documentation: