REST API command/platform fails on POST to external URL (solcast)

I finally pushed a first version to GitHub:

Working:

  • Automatic collection of past values (estimated_actuals) while respecting the free API limits
  • Daily calculation of the forecasted energy producation for the next days (request every day at midnight)
  • Service call to push measured values with a script

TODO:

  • Automatic pushing of measurement values (not as simple as I hoped, I need to adopt some code from the statistics component, or maybe reuse it)
  • When everything is working fine, maybe add the custom component to HACS

Working… :smiley:
image

1 Like

Hi guys,

Wondering if any progress on this getting towards a HACS release so less skilled like ourselves can have a play? :slight_smile:

Many thanks.

@AussieByrd & @dannerph

Thanks for working on this. Discovered Solcast a couple of days ago, so saves me making a custom_componenet.

Will have a look at adding this to my setup when I get home from work.

Are you using this data to automate anything?
What I would like to do is use it to automate charging my battery system off the grid over night when prices are cheap, if there wont be enough solar to last through to the next day.

What a nice use case! Which battery system do you have? Is it controllable via HomeAssistant?

I am planning to optimize my EV charging in order to estimate, when it will be fully charged using PV power only in my green charging mode (some documentation is here: https://danner-web.de/2020/04/ev-green-charging/).

I still have a bug in the code of the solcast component when using a fast MySQL database as recorder: sometimes wrong values of the historical solcast model are stored at the time of the request. I will have a look to that soon.

I am using a SolaX Inverter and the a 4.5kWh Triple Power Battery.
I want to add a second battery hopefully at the end of the month.

I created the following to control the Battery and Read the Inverter states.

1 Like

It is still on the todo list, I want fix all remaining issues/bugs before. I am also still thinking of improving the forecast data storage in Home Assistant to be able to support more use cases, maybe hourly data instead/in addition to daily forecasts.

1 Like

Is the pushing of data to solcast automatic? Or do I need an automation to trigger the upload?

I am using the code posted by @AussieByrd on March 2nd

Just one small automation for me. I automatically switch on (at the wall) my (very dumb… which actually makes it easier) clothes dryer when my power export exceeds a given level (I think I have it set to 600W at the moment). That way clothes are left in the dryer ready to go the night before, it switches on at a point (avoiding high power use when solar is not yet avaailable).

Hi @wills106… my yaml posted on 3 March creates a sensor whose content you can use to POST your productions data to SolCast for tuning. But it doesn’t actually send the data—you’ll need an automated API call to SolCast for that. I’m on my work computer at the moment so don’t have access to my yaml. Will try to post it at lunchtime.

Ok thanks @AussieByrd
I take it when you log onto the SolCast website you will start to see your own data points being uploaded?

Yep. On the summary (front) page it’ll show “PV Tuning” and when it got the last data pushed through. Once you click in, you can select the “Accuracy” graph which compares your uploaded data with their estimated actuals and 1-hour forward looking forecast values. My correlation coefficient is around 0.98.

@wills106… here is my yaml for automating the data push…

###Automation for REST commands - SolCast
#Send current solar production to SolCast for tuning
rest_command:
  solcast_tune:
    url: https://api.solcast.com.au/rooftop_sites/your-id-here/measurements?api_key=your_API_key_here
    method: POST
    headers:
      Content-Type: application/json
    payload: "{{states('sensor.solcast_post')}}"

automation:
#Run data upload every 5 minutes
  - alias: solcast-upload
    trigger:
      platform: time_pattern
      minutes: "/5"
    condition:
      condition: and
      conditions:
        - condition: sun
          before: sunset
          before_offset: "+00:30:00"
        - condition: sun
          after: sunrise
          after_offset: "-00:30:00"
    action:
      service: rest_command.solcast_tune
1 Like

Apologies for my ignorance, but I’ve installed this manually in custom components and seems ok.

But is there anyway of changing the schedule for it to pull tomorrows forecast? to say 7pm instead of midnight?

it would be useful to know what solar is going to look like tomorrow so can plan if I need to charge PV battery overnight. :slight_smile:

Thanks for you tremendous work @dannerph

My solcast integration includes a service call to push values to solcast API. My plan is to include an automatic pushing of values in the solcast integration, however I still need to figure out the best way to get the average of a certain period …

push_measurement:
  desciption: >
    Pushes PV measurements to Solcast for model fine tuning.
  fields:
    total_power:
      desciption: >
        The total power of the PV system for the given period.
      example: 1.23456
    period:
      desciption: >
        The period of the total power (e.g. PT5M, PT15M, PT30M, ...)
      example: PT5M
    period_end:
      desciption: >
        The end period of the total power in UTC timezone
      example: 2018-02-02T03:30:00.0000000Z

Good point, at the moment it is hard coded but you can create an automation and use the service call to force pull the current forecast (be aware that the forecast for today will only contain the remaining energy until midnight, the forecast of tomorrow and the day after tomorrow will be for the whole day starting from midnight local timezone).

The json response for the forecast API call only contains future time so I decided to fetch the forecast at midnight to include the whole day (might be more accurate at sunrise actually). I might introduce a parameter for that at next release.

update_forecast:
  description: >
    Fetches the forecasts from Solcast.

1 Like

Hello!

First of all I wanted to thank you for your work and to give it to everybody :slight_smile: I just received my solar panels a few days ago and started using home assistant for it, so I’m relatively new to all this.

I’ve been able to run your script and I can get the history data and forecast. However, there is 2 small issues:

  • I had to change line 112 by adding ssl=False otherwise I wasn’t able to connect
  • I can’t really use the forecast since I’m using the data in Grafana to display everything I need. Is there any way to get the forecast 30 minutes by 30 minutes as with the history data?

Thanks in advance!

Matthieu

@dannerph Just got this installed, also trying to do what @wills106 was saying, set my Tesla Powerwall to charge overnight (2am) if the next day will be a bad day for solar. The powerwall does sort of do this for you, but it doesn’t seem very accurate and over fills quite often.

Do you have an example of a service call for:

solcast.push_measurement

Or your automation you use to do this?

Hi @ParalaX,
nice to see people using my code, so it was a good investment of time :wink:

I had to change line 112 by adding ssl=False otherwise I wasn’t able to connect

I would avoid ssl=False, as it neglects the SSL certificate check and thus renders transport encryption broken. It might be related to your systems certificate store, maybe the root CA (from Amazon) is missing?

I can’t really use the forecast since I’m using the data in Grafana to display everything I need. Is there any way to get the forecast 30 minutes by 30 minutes as with the history data?

I need to check if I can also publish future events on the event bus and what the integrated recorder component, which is compatible with multiple backends, is doing with them. But i remember something that it was no possible that’s why I created another solution. I will check again when I find some time.

Hi @james_hiscott,

actually, I have not yet setup the pushing of measurements by myself (had still to fix reading from the smart meter, which is working now). In addition, I still need to figure out how to aggregate the measurement values on the time dimension (my meter is pushing on 2-3 seconds resolution) before I can forward them to solcast.