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

I’ve tweaked the code again to add three more sensors that give the predicted energy and peaks for the current day by storing the values at 15 minutes before dawn in new sensors…

I added:

  - trigger:
    - platform: sun
      event: sunrise
      offset: "-00:15:00"
    sensor:
    - name: "Solcast Forecast Energy Today Predicted"
      unique_id: solcast_forecast_energy_today_predicted
      state: "{{ states('sensor.solcast_forecast_energy_today_remaining') }}"
      unit_of_measurement: 'kWh'
      device_class: energy
    - name: "Solcast Forecast Peak Time Today Predicted"
      unique_id: solcast_forecast_peak_time_today_predicted
      icon: mdi:clock
      state: "{{ states('sensor.solcast_forecast_peak_time_today') }}"
    - name: "Solcast Forecast Peak Power Today Predicted"
      unique_id: solcast_forecast_peak_power_today_predicted
      unit_of_measurement: "kW"
      device_class: power
      state_class: measurement
      state: "{{ states('sensor.solcast_forecast_peak_power_today') }}"

and changed

sensor.solcast_forecast_energy_today

to

sensor.solcast_forecast_energy_today_remaining

I’ve updated the code above.

Nice! Thanks for sharing.

Is the code correct, because I see:

template:
  - sensor:
      - name: "Solcast Forecast Energy Today Remaining"
        unique_id: solcast_forecast_energy_today_remaining

but then

  - trigger:
    - platform: sun
      event: sunrise
      offset: "-00:15:00"
    sensor:
    - name: "Solcast Forecast Energy Today Predicted"
      unique_id: solcast_forecast_energy_today_predicted
      state: "{{ states('sensor.solcast_forecast_energy_remaining') }}"

Basically solcast_forecast_energy_today_remaining != solcast_forecast_energy_remaining

Is this a typo or did you modify some of your previous code too?

That said, many thanks for your example!

Forgive my ignorance - is the “trigger” code part of the “Template” section, or is it a separate automation?

Incidentally, there’s a small typo in the unique_id: solcast_forecast_enery_next_hour sensor. Missing the “g” in “energy”.

There were some typos. I’ll fix them above.

1 Like

An alternative to this is to use MQTT which will retain the predicted values when HA restarts.

First use an automation:

alias: Solcast Forecast to MQTT
description: Put Solcast predicted values in MQTT
trigger:
  - platform: sun
    event: sunrise
    offset: '-00:15:00'
condition: []
action:
  - service: mqtt.publish
    data:
      topic: home/solcast/energy_today_predicted
      payload_template: '{{ states(''sensor.solcast_forecast_energy_today_remaining'') }}'
      retain: true
  - service: mqtt.publish
    data:
      topic: home/solcast/peak_power_today_predicted
      payload_template: '{{ states(''sensor.solcast_forecast_peak_power_today'') }}'
      retain: true
  - service: mqtt.publish
    data:
      topic: home/solcast/peak_time_today_predicted
      payload_template: '{{ states(''sensor.solcast_forecast_peak_time_today'') }}'
      retain: true
mode: single

Then set up the three sensors in configuration.yaml:

sensor:
  - platform: mqtt
    name: "Solcast Forecast Energy Today Predicted"
    state_topic: "home/solcast/energy_today_predicted"
    unique_id: solcast_forecast_energy_today_predicted_mqtt
    unit_of_measurement: 'kWh'
    device_class: energy
  - platform: mqtt
    name: "Solcast Forecast Peak Time Today Predicted"
    state_topic: "home/solcast/peak_time_today_predicted"
    unique_id: solcast_forecast_peak_time_today_predicted_mqtt
    icon: mdi:clock
  - platform: mqtt
    name: "Solcast Forecast Peak Power Today Predicted"
    state_topic: "home/solcast/peak_power_today_predicted"
    unique_id: solcast_forecast_peak_power_today_predicted_mqtt
    unit_of_measurement: "kW"
    device_class: power
    state_class: measurement
1 Like

A great solution to a problem I didn’t even know I had! Thank you.

1 Like

@safepay Have you updated to 2022.4.1 yet? I’m getting all sorts of solcast template errors since I’ve done so,

EDIT: It’s possible Solcast was down. The sensors seem to be working now…

@Sddawson I’ve stopped using my config and just use the Solcast PV Solar in HACS.

@safepay Fair enough. I’ve thought about doing the same, but your config has so many more sensors (most of which, admittedly, I don’t use!). You mean GitHub - oziee/ha-solcast-solar: Solcast Integration for Home Assistant right? There does seem to be an outstanding issue with that and 2022.4 though…

Yep. I’m using that one. Haven’t noticed any problems yet, though.

I was looking at this issue Detected integration that accesses the database without the database executor · Issue #34 · oziee/ha-solcast-solar · GitHub.

Have you found a way to reproduce the nice forecast graph that uses the apexcharts-card? I find that really useful.

Sorry, but I’ve pretty much given up on forecasting solar at this point.

Oh, fair enough! Any reasons in particular?

yes the solcast integration seems to throw log errors… and im not sure if its still working with 2022.4 or not as I have not updated to that yet due to too many errors and integration problems I have with it. so for now im sticking with 2022.3

I have been looking into some changed with the way the integration works and logs data. Being that it is a “forecast” im going to put less effort into past data and more into current forecast data

I have been reading through here as to what and how ppl are waiting to use data, so also thinking of any other sensors etc to create or at least have the data there for ppl to make their own sensors from

@oziee Thanks for the update. I’d be keen to switch to the integration once we’re sure it works with the latest HA. There are certainly a lot of sensors that @safepay has made possible in this thread that could be useful. I’ll watch where the integration goes with interest.

new version seems to be working great

@oziee With which HA version?

@Sddawson I have not uploaded the new version of the integration just yet… still just bug testing it
new version will be v3.0.0
works with HA including new 2022.4

@oziee Thanks for all your efforts! Look forward to trying the new version when it’s available.