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

POSTs are not counted towards the API limit (i.e. tuning POSTs are unlimited).

1 Like

Lamer newbie HA question… How do I get solcast: working my install please to test?

Says unknown when I try adding into my configuration.yaml

Thanks

My Solcast integration is not yet upstream in the home assistant release and will probably never be upstream in the home assistant release. I am currently testing everthing, should be finished end of this week, afterwards you can integrate solcast as a custom component (instructions will follow).

1 Like

Phew, not me being a bit dumb then! :slight_smile:

Thank you, will look forward to the initial release.

One question to @AussieByrd: In which interval do you push the measurements currently? As I collect the data directly from the smart meter, I have a 3 seconds resolution, which is of course a little bit overkill :smiley:

I am thinking of internally collecting the state of the specified sensor for a certain time and then pushing the average of the gathered value. Let’s say every 15 or 30 minutes. There is a function in the core (event.py) that might be useful for this:

def async_track_same_state(
    hass: HomeAssistant,
    period: timedelta,
    action: Callable[..., None],
    async_check_same_func: Callable[[str, State, State], bool],
    entity_ids: Union[str, Iterable[str]] = MATCH_ALL,
) -> CALLBACK_TYPE:
    """Track the state of entities for a period and run an action.

    If async_check_func is None it use the state of orig_value.
    Without entity_ids we track all state changes.
    """
1 Like

I send POST data every 5 minutes (I seem to recall this is the shortest interval for rooftop systems on Solcast, but that’d be worth checking). I actually send the average of the past 5 minutes readings from my inverter’s Fronius smart meter–I think it reads every 30 seconds or so).

This is what I use to for the data to POST:

###Solar production estimates from SolCast - live###

##5 minute average for production
  - platform: statistics
    entity_id: sensor.current_production
    name: pv_stats
    max_age:
      minutes: 5
##Template sensor for POST string
  - platform: template
    sensors:
      solcast_post:
        entity_id:
          - sensor.date_time_iso
          - sensor.pv_stats
        value_template: >
          {{ '{"measurement": {"period_end": "' ~ as_timestamp(states.sensor.date_time_iso.state)|timestamp_custom ('%Y-%m-%dT%H:%M:%SZ', false) ~ '", "period": "PT5M","total_power": ' ~ state_attr('sensor.pv_stats', 'mean') ~ '}}' }}
3 Likes

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