T3m3z / spotprices2ha

Simple copy-paste approach to fetch data from api.spot-hinta.fi (see https://spot-hinta.fi) to Home Assistant. Includes simple sensors and UI elements to ease automation work.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

shf_electricity_price_now sensor getting price from one hour ahead

heijjan opened this issue · comments

Hi,

After the recent HA update and fixes to the yaml, I noticed that the shf_electricity_price_now sensor is getting it's value from one hour ahead.

state_attr("sensor.shf_electricity_price_now", "today_prices")[now().hour] gives the price for next hour instead of the current one. Modifying this with state_attr("sensor.shf_electricity_price_now", "today_prices")[now().hour-1] fixes the issue, but of course isn't the best practice.

I have checked that HA is set at the correct time and now().hour returns the number of current hour.

Looks like spot-hinta.fi changed their API yesterday
First hour on https://api.spot-hinta.fi/TodayAndDayForward?HomeAssistant=true is not 00:00 anymore but 01:00.
Also it doesn't include data for 2 days ("TodayAndDayForward") anymore, but only "DayForward".
Hopefully it was just glitch yesterday and not permanent change.

Reply from spot-hinta.fi

Joo eilen oli laajasti vikaa Nordpool tiedoissa ja rajapinnoissa. Mm. EntsoE ei jakanut eilistä dataa ollenkaan.

Onneksi osui nollahintapäiviin nämä bugit.

Eli siis ei muutosta, toivotaan että tänään tulee tiedot jo oikein.

Yes, this was EntsoE bug or rather Nordpool data distribution bug. I will study this to make API more robust to this kind of data source bug.

Hmm, I didn’t make any changes in the code and it still gets prices 1 hour ahead. Or is this working for someone like it should?

EntsoE seems not to release yesterday prices even today. So first hour from today is missing from data. And thar probably makes yaml hour calculation go wrong. This should get fixed tomorrow because data for today and tomorrow looks fine.

Unfortunately prices are still 1 hour ahead.

EDIT: Weird but HA restart corrected the issue.

Did the same thing this morning and now it seems to be working properly.

It seems that this was an error on the data distribution side. Anyway, I'm going to (hopefully not in the too distant future) refactor the code in order to take into account DST time so during that refactoring I try to make the code more robust against this too.

Closing the issue as this has happened only once due to a major problem due to EntsoE / Nordpool data distribution bug (reported by @Spot-hinta-fi ). Feel free to reopen, if this happens again / other changes are needed.