Hi all
I’m attempting to use a platform: rest sensor (and doing testing using rest_command) to POST the 5-minute averages of my solar system’s output to solcast.com to tune it’s predictions of my production.
I’ve been using a platform: rest sensor successfully for a while now to GET predicted output from solcast.com, but no success with POST.
My yaml for the post_command is as follows (xxxx represents my the solcast rooftop ID, yyyy represents my API key):
The payload in sensor.solcast_post is a string generated through a template sensor to create the JSON-coded info needed for the API. It looks like this: {"measurement": {"period_end": "2019-10-19T03:35:00Z", "period": "PT5M","total_power": 1.19}}
I’ve tested the API POST using Postman (with the URL above, and strings straight from sensor.solcast_post and it works fine (i.e. no errors in Postman, and the measurement shows up on solcast.com).
However, whenever I can service rest_command.solcast_tune in Developer Tools I get a 400 error (per the solcast.com API, this indicates “The measurement does not pass validation (only for single measurement).”
Hey @dannerph… here you go… in stages, as its a bit complicated as I have it set up to attempt to limit API calls to my free 20 hits per day… (usually woks unless I restart HA a bunch of times).
REST sensor (runs once per year… i.e. basically never):
Really depends on your setup. Solcast doesn’t allow you to ‘set up’ a rooftop system with panels facing in different directions (e.g. I have both north and west facing panels)—so initially I set up two accounts, with two systems and aggregated the predictions (it was fairly good except for some early morning and mid afternoon shading effects). So if your panels face only one way and you don’t have any unusual local shading issues, its very good even without calibration. Otherwise, its must better with calibration—correlation on my (now single account, with tuning) is 98%.
Hi @Zarch… almost certainly possible… and something I was considered (or rather, the opposite… using a single API call for the previous days data, so I go the bull data set rather than hourly spots).
However, I kinda put it in the to-hard basket because of the difficulty in passing the full chunk of data with time conversions in the “history” of a sensor.
It should be feasible to write a small module for home assistant that pulls the data only once or twice a day and converts the data to the correct timezone. I will put it on my todo list!
For historical view that should not be a problem as this module will probably implement a senor that pushes the previously fetched data at the time of the forecast (use case of @AussieByrd). For a preview for the upcoming day, I do not know any home assistant internal data model that could be used here (use case of @Zarch). The most similar data model is the one of weather forecasts (only temperature, humidity nothing about energy). Home Assistant, for my understanding, is a real-time system that does not provide an option to insert predicted values in sensors.
I now have a basic module consuming only the api_key and the resource_id of the rooftop site:
solcast:
api_key: xxx
resource_id: xxx
It can already fetch forecasts and the estimated actuals (POST of measurements are prepared but WIP. My idea is to configure an entity_id in the config file from which the script fetches the data for automatically pushing it to solcast).
From the forecasts, it calculates the expected total energy of the next day as separate sensor in kWh (I have no idea how to store and show a timeseries, so I aggregated the energy as this provides a good starting point to see how the energy production for the next day will be).
From the estimated actuals values I could easily show the latest value, but then I need to update every 30 min to get the data in highest resolution which will overshoot the API limit. As far as I have seen, it is not possible to store historical values within Home Assistant, always only the current state. One option is to reduce the fetching rate in order not to overshoot the API limit, second option I need to dig deeper into Home Assistant Core. Any ideas?
Short update:
I now checked how state values are stored in the database (in the recorder module). The listening EVENT_STATE_CHANGED event, that triggers storing the data from an entity (sensor) to the database and hence for the history graph, is created in core.py:984. The important last_changed datetime, however, is set to the processing time.
As short conclusion: If the solcast component cannot push directly to the event bus, we cannot get historical data in the database (e.g. for only one request to the solcast API per day). According to the documentation it should be possible to fire directly on the eventbus. I will have a look on it the next days.
UPDATE: I got a small test code running that feeds in past data, so technically it is feasible! Future data however is not automatically shown in the history graph. I will probably use the aggregated energy per day as explained before.