I started to pull this together again just yesterday, so you are in luck!
For anyone else interested… @ffm777 , @Beny_44_44, @Makkie1969 et al
I had a very long revisit of my Node-RED code, completely updated it and set it up for testing last May. Every time I thought it was good to go, another ‘critical update’ or small problem came along, and I had to wait to see if it all still worked, hence the rather long wait.
I have moved on to other things, but this is my latest code for calling the Forecast Solar API directly. This is now entirely in JSONata, which has improved the ability to handle 1 to n planes, added more analysis output data for both today and tomorrow, and fixed a couple of bugs I found.
Disclaimer: this is working for me, but it may not work for you and you will have to deal with setting up Node-RED and all the various sensors and settings yourself.
If you are updating from my earlier version my suggestion is to disable all the old trigger, sensors, and configuration nodes, to redeploy and restart NR (so as to clear the sensor entities from HA), import the new code, and then update the parameter settings and HA server in the sensor configuration nodes.
All the context data should also be deleted so as to force the code to regenerate a fresh copy.
The sensors should reappear, but check that they are correctly named and not ‘_2’ copies: a full disable, deploy, restart HA and HR may be required to clear the old sensor (HA entities) in such cases.
Requirements: as before, this needs up to date Node-RED. It also requires the Cron-plus node (node-red-contrib-cron-plus) if you want to schedule the exact time in the hour for API call update, and it requires the time-date integration so as to be able to read the current local and ISO time.
- cronplus node is the one I prefer to use to trigger the hourly update, but this can be swapped for the standard inject node with a repeat set to every 60 minutes
- the time-date https://www.home-assistant.io/integrations/time_date/ integration should be added to configuration YAML file, the date_time_iso value is the one used by the code
- the half-hour solar actual sensor is explained above in previous posts
Here I am now using the forecast solar API returned UTC and local times to work out the time zone setting, and also using an entity state node to get the date_time_iso so as to obtain time zone settings. This all works, but I may modify the JSONata again to do the UTC to local time another way and avoid using the date-time platform… I am still experimenting with JSONata code to obtain the local time (UTC time is easy - just use $now()).
NOTE that Forecast Solar decides the local time zone / DST given the location settings used for the planes in the API call. As usual, this will all only work correctly where the HA machine local settings match the plane location settings. (I have tested my code for my location in the UK, Frankfurt in Europe, and had a stab at Pacific Daylight Time in LA, but it is challenging to fully test time zone code)
Code:
- All NR code has been scrubbed. You will need to add back in your own HA server to each of the sensor (entity) configuration nodes.
- Location settings for the planes have been invented. You will need to add back in your own settings for your plane(s). I have experimented with the ‘horizon’ setting to see if it improved the accuracy of the forecast. It appears to have no effect whatsoever, so I don’t think this is working, but I am leaving it in as an example - my horizon is very restricted so do remove or adjust this!
- The context variables save & read actions have been moved to change node entries. This makes them visible and much easier to select the context store (memory / file) if you have more than one. I use persistent file storage for the forecast table.
- key nodes have been disabled so as to make importing the code less disruptive. Enable configuration, sensor and display nodes as required.
When imported and configured it should look something like this:
The context data values have been extended to include much more data, particularly for the analysis (power level) table.
Today was not a good solar day. Forecast Solar, at the end of the day, is giving 3.4 kWh forecast (backcast), however my analysis uses the historic record values to give 4.1 kWh, which exactly matches the 4.1 kWh actually obtained.
For myself I use this in HA as a visual display only. I am now looking at the UK Octopus Energy ‘Flux’ tariff, and need to get an accurate forecast for ‘tomorrow’ to decide if I need/can charge my solar battery from the grid during the night, still allowing for space to capture excess solar.
Problems? Requests? Comments? Can’t get it to work?
Please note that I am retired (which means I am very busy). I am doing this just for fun (which means that, although I like to ensure my code is tested and it works, there is no warranty). I can answer questions, however most answers are already out there.
Many thanks to those who are using my code for your positive feedback. Good luck to you all with your solar (forecast) projects.