vividfog / nordpool-predict-fi

A Python app and ML model that predicts spot prices for the Nordpool FI market.
https://sahkovatkain.web.app/
MIT License
68 stars 8 forks source link

Possibility to get the predictions as a sensor like normal nordpool sensor in HA #15

Open Denna93 opened 7 months ago

Denna93 commented 7 months ago

Is there anyway to get these predictions into a sensor in HA like the normal nordpool sensor. Would be best to update it when new prices are coming and showing the confirmed prices + predictions. Looking to integrate the predictions to emhass in HA

vividfog commented 7 months ago

Similar to #9 which was a study for this.

Denna93 commented 7 months ago

I am not so good with code but I can try to implement this. In the manifest.json what parameters do you need to put in? Or could you help me fetching the predicitons into HA and make a sensor out of the parameters. I guess you just need to fetch currect pricing from the nordpool sensor + numbers from your prediction.json? What does those numbers standfor in the prediction.json eg: [1709676000000.0, 10.552465408316145], the later one is the predicted price in euro cents? but the first number what does that stand for?

vividfog commented 7 months ago

I am not so good with code but I can try to implement this. In the manifest.json what parameters do you need to put in? Or could you help me fetching the predicitons into HA and make a sensor out of the parameters. I guess you just need to fetch currect pricing from the nordpool sensor + numbers from your prediction.json? What does those numbers standfor in the prediction.json eg: [1709676000000.0, 10.552465408316145], the later one is the predicted price in euro cents? but the first number what does that stand for?

I haven't done a HA sensor myself, so we would start from the same level of ignorance here. The first number is milliseconds since epoch, something that eCharts and ApexCharts can read correctly by default. The second number is cents per kWh with VAT. An interim PR of this might be a .yaml file that could be placed in HA custom components. Or however that sensor is created. I have no need to push this to HACS, other than as a curiosity.

You're welcome to try to implement a sensor. This is a frequent request by many. I might pick it up as well, when there's time. No harm trying twice and combining the learnings. If it reveals a need for a better, HA-centric prediction.json, those are doable if given a spec.

from datetime import datetime

# Timestamp in milliseconds
timestamp_ms = 1709676000000.0

# Convert to seconds
timestamp_s = timestamp_ms / 1000

# Convert to datetime
date_time = datetime.utcfromtimestamp(timestamp_s)

date_time.strftime('%Y-%m-%d %H:%M:%S UTC')

# Result
# '2024-03-05 22:00:00 UTC'
masipila commented 7 months ago

Heya,

I'm the author of https://github.com/masipila/openhab-spot-price-optimizer/ which is built on openHAB. openHAB is another home automation system like HomeAssistant.

@vividfog Do I get things right that the architectural approach is that

EDIT:

Cheers, Markus

vividfog commented 7 months ago

Heya,

I'm the author of https://github.com/masipila/openhab-spot-price-optimizer/ which is built on openHAB. openHAB is another home automation system like HomeAssistant.

@vividfog Do I get things right that the architectural approach is that

  • Sähkövatkain will NOT offer an API where external solutions (which are built with HomeAssistant or openHAB) could fetch the forecasts?

  • Instead, the approach is that the end users can install your solution locally and then save the forecasts wherever they want (let that be HomeAssistant or openHAB)?

Cheers,

Markus

That looks like an interesting project too.

I would like to have an API for this, if a free tier indie/hobby friendly option for hosting the runtime components exists and it works with Python. I don't mind running all the compute in the cloud if there's an option.

The JSON files are basically a PoC to get the data available in some form to begin with. Not the endgame. I happen to use HA so it's getting some personal attention. My fridge door HA tablet was the first client app.

Firebase has Cloud Functions but I haven't had time to investigate that option yet. Other pointers welcome.

Others can run their own predictions if they wish, as long as their index.html makes it clear it's not me who hosts that page and they have their own disclaimers.

Given that the model is changing a lot, an API would likely make most sense for most, rather than some distributed everyone-for-themselves setup. People have that option but I don't intend it as an obligation.

Denna93 commented 7 months ago

I was also thinking if there would be a possibility to go beyond 5 days. For example Foreca gives 10days forecast. I would love to have an option where you can see the more accurate predicition of 5 days but also see a full 2 week predicition by the system also.

I tried yesterday implement it to HA with the help of chatgpt, but couldnt get it to understand the prediciton.json and get the numbers in to a sensor

vividfog commented 7 months ago

I was also thinking if there would be a possibility to go beyond 5 days. For example Foreca gives 10days forecast. I would love to have an option where you can see the more accurate predicition of 5 days but also see a full 2 week predicition by the system also.

I tried yesterday implement it to HA with the help of chatgpt, but couldnt get it to understand the prediciton.json and get the numbers in to a sensor

The weather data is available for 10 days, so ten days is doable. To do it in a maintainable manner, this would require a solid few hours to sit back and refactor the code to make this a variable to ensure the data frames passed back and forth during prediction remain clean and robust. The current implementation is a bit of "learn as I go", so I'd like to (at some point) refactor it in this regard. And if there's an API, then surely it should pass information up to however far the prediction runs, even if the standard web page is more conservative and sticks to +5 days. If you don't mind, pass this as a new issue/enhancement, as it's a bit unrelated to this one. As is the API topic itself BTW.

Pave87 commented 4 months ago

I took this up as a case to start with Python and Home Assistant coding. I created python script that loads "https://raw.githubusercontent.com/vividfog/nordpool-predict-fi/main/deploy/prediction.json". It also takes in nordpool sensor from Home Assistant instance its running on to get some sense how accurate late predictions where.

It then creates sensor that contains prediction data as attribute. https://github.com/Pave87/Nordpool-Prediction-Sensor My next step is to learn and create this into HACS integration but wanted to put this out as it might take a while.

@vividfog Thanks for data.