solar power prediction

Subforum for general discussions. Do not dump your questions/problems here, but try to find the subforum where it belongs!

Moderators: leecollings, remb0

Post Reply
JanJaap
Posts: 215
Joined: Thursday 12 October 2017 20:46
Target OS: Raspberry Pi / ODroid
Domoticz version: Dev
Location: the Netherlands
Contact:

solar power prediction

Post by JanJaap »

Hey,

Has anyone already built some integration to fetch predicted solar power? Would be interested in light of controlling home batteries. First step would be to compare prediction vs actuals..... Solarpanel.forecast for example seems like a potential target to pull form.
RPi 3, Domoticz dev version, Aeon ZWave stick (with a whole bunch of slaves), Zigbee using Zigbee2MQTT, Nest thermo, P1 smart meter on RPi Zero
User avatar
psubiaco
Posts: 222
Joined: Monday 20 August 2018 9:38
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Italy
Contact:

Re: solar power prediction

Post by psubiaco »

I don't remeber where I found this dzVents script, but it works. Try it!

Code: Select all

return {
  on = {
    timer = {
        'at *:50'
    },
    httpResponses = {
      'solarforecastEAST' -- must match with the callback passed to the openURL command
    }
  },
  logging = {
    level = domoticz.LOG_INFO,
    marker = 'get solar forecast',
  },
  execute = function(domoticz, item)
      
      local idxSolarForecastCounter=2481  	-- device with 24h forecast: type 'Managed counter', Energy generated
      local idxSolarForecast=2477  			-- device holding the forecast for the next hour: type 'Custom sensor', axis: 'Wh'


    if (item.isTimer) then
		print("EAST")
      domoticz.openURL({
        url = 'https://api.forecast.solar/estimate/watthours/period/45.8812/12.1833/15/-90/2.7',
        method = 'GET',
        callback = 'solarforecastEAST', -- see httpResponses above.
      })
    end

    if (item.isHTTPResponse) then

      if (item.ok) then
        --domoticz.log('item.data ' .. item.data .. '***************************', domoticz.LOG_INFO)
        
        if (item.isJSON) then
            domoticz.utils.dumpTable(item)
            
            local messagetype=item.json.message["type"]
            domoticz.log("message type" .. messagetype, domoticz.LOG_INFO) 
            
            if messagetype=="success" then
                local currentHR=os.date("%Y-%m-%d %H:00:00")
                local oneHRahead=os.date("%Y-%m-%d %H:00:00",os.time()+1*60*60)
                local twoHRahead=os.date("%Y-%m-%d %H:00:00",os.time()+2*60*60)
                local forecastCurrentHR=tonumber(item.json.result[currentHR])
                if forecastCurrentHR==nil then
                    forecastCurrentHR=0 
                end    
                local forecastOneHR=tonumber(item.json.result[oneHRahead])
                if forecastOneHR==nil then
                    forecastOneHR=0 
                end    
                local forecastTwoHR=tonumber(item.json.result[twoHRahead])    
                if forecastTwoHR==nil then
                    forecastTwoHR=0 
                end    
                domoticz.log("solar forecast for next three hours :" .. forecastCurrentHR .. "+" .. forecastOneHR .. " + " .. forecastTwoHR .. " WattHR", domoticz.LOG_INFO) 
                domoticz.devices(idxSolarForecast).updateCustomSensor(forecastOneHR)
                
                local updateHour=0
                for id = 1, 24 do
                    if id<10 then
                        updateHour="0"..tostring(id)
                    else 
                        updateHour=tostring(id)
                    end    
                    domoticz.devices(idxSolarForecastCounter).updateHistory(os.date("%Y-%m-%d ")..updateHour..":00:00","0;0")
                    domoticz.devices(idxSolarForecastCounter).updateHistory(os.date("%Y-%m-%d ",os.time()+24*60*60)..updateHour..":00:00","0;0")
                end    
                    
                local response=item.json.result
                for datehour,value in pairs(response) do
                    domoticz.log("solar forecast date "..domoticz.utils.stringSplit(datehour)[1].." hour "..domoticz.utils.stringSplit(domoticz.utils.stringSplit(datehour)[2],":")[1].." value "..value,domoticz.LOG_INFO)
                    local previousHour=domoticz.utils.stringSplit(domoticz.utils.stringSplit(datehour)[2],":")[1]-1
                    if previousHour<10 then 
                        previousHour="0"..tostring(previousHour)
                    else
                        previousHour=tostring(previousHour)
                    end    
                    domoticz.log("previousHour "..previousHour)    
                    if value>0 then
                        sensorDateHour=domoticz.utils.stringSplit(datehour)[1].." "..domoticz.utils.stringSplit(domoticz.utils.stringSplit(datehour)[2],":")[1]..":00:00"
                        sValueStr="0;"..value
                        domoticz.log("sensorDateHour "..sensorDateHour.." sValueStr "..sValueStr,domoticz.LOG_INFO)
                        domoticz.devices(idxSolarForecastCounter).updateHistory(sensorDateHour,sValueStr)
                        if sensorDateHour==currentHR then
                            domoticz.devices(idxSolarForecastCounter).updateCounter(value)
                        end    
                    end       
                end
            else
                domoticz.log("no successfull message", domoticz.LOG_INFO)
            end    
        else
            domoticz.log('is not json', domoticz.LOG_INFO) 
        end    
      else
        domoticz.log('There was a problem handling the request', domoticz.LOG_INFO)
        domoticz.log(item, domoticz.LOG_INFO)
      end

    end

  end
}

Paolo
--
I use DomBus modules to charge EV car, get a full alarm system, control heat pump, fire alarm detection, lights and much more. Video
Facebook page - Youtube channel
JanJaap
Posts: 215
Joined: Thursday 12 October 2017 20:46
Target OS: Raspberry Pi / ODroid
Domoticz version: Dev
Location: the Netherlands
Contact:

Re: solar power prediction

Post by JanJaap »

Tnx! Looks simple enough, might convert it to plugin.
RPi 3, Domoticz dev version, Aeon ZWave stick (with a whole bunch of slaves), Zigbee using Zigbee2MQTT, Nest thermo, P1 smart meter on RPi Zero
User avatar
psubiaco
Posts: 222
Joined: Monday 20 August 2018 9:38
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Italy
Contact:

Re: solar power prediction

Post by psubiaco »

JanJaap wrote: Saturday 01 February 2025 20:02 Tnx! Looks simple enough, might convert it to plugin.
Wow... keep us informed if you'll write a plugin doing that! Thanks a lot
Paolo
--
I use DomBus modules to charge EV car, get a full alarm system, control heat pump, fire alarm detection, lights and much more. Video
Facebook page - Youtube channel
willemd
Posts: 642
Joined: Saturday 21 September 2019 17:55
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.1
Location: The Netherlands
Contact:

Re: solar power prediction

Post by willemd »

here is my dzVents script to load solar forecast for my location (I replaced my location with XXXX an YYYY) and my panel specs (angles and capacity)
Please check the API specification for the other parameters in the call.

Code: Select all

return {
	on = {
		timer = {
		    'every hour'
		},
		httpResponses = {
			'solarforecast' -- must match with the callback passed to the openURL command
		}
	},
	logging = {
		level = domoticz.LOG_INFO,
		marker = 'get solar forecast',
	},
	execute = function(domoticz, item)
	    
	    local idxSolarForecast=106  -- device holding the forecast for the next hour
	    local idxSolarForecastCounter=186

		if (item.isTimer) then
			domoticz.openURL({
				url = 'https://api.forecast.solar/estimate/watthours/period/XXXX/YYYY/55/58/2.75',
				method = 'GET',
				callback = 'solarforecast', -- see httpResponses above.
			})
		end

		if (item.isHTTPResponse) then

			if (item.ok) then
				--domoticz.log('item.data ' .. item.data .. '***************************', domoticz.LOG_INFO)
				
				if (item.isJSON) then
				    domoticz.utils.dumpTable(item)
				    
				    local messagetype=item.json.message["type"]
				    domoticz.log("message type" .. messagetype, domoticz.LOG_INFO) 
				    
				    if messagetype=="success" then
				        local currentHR=os.date("%Y-%m-%d %H:00:00")
				        local oneHRahead=os.date("%Y-%m-%d %H:00:00",os.time()+1*60*60)
    				    local twoHRahead=os.date("%Y-%m-%d %H:00:00",os.time()+2*60*60)
    				    local forecastCurrentHR=tonumber(item.json.result[currentHR])
    				    if forecastCurrentHR==nil then
    				        forecastCurrentHR=0 
    				    end    
    				    local forecastOneHR=tonumber(item.json.result[oneHRahead])
    				    if forecastOneHR==nil then
    				        forecastOneHR=0 
    				    end    
    				    local forecastTwoHR=tonumber(item.json.result[twoHRahead])    
    				    if forecastTwoHR==nil then
    				        forecastTwoHR=0 
    				    end    
    				    domoticz.log("solar forecast for next three hours :" .. forecastCurrentHR .. "+" .. forecastOneHR .. " + " .. forecastTwoHR .. " WattHR", domoticz.LOG_INFO) 
    				    domoticz.devices(idxSolarForecast).updateCustomSensor(forecastOneHR)
    				    
    				    -- set previous forecast to zero on managed counter
    				    local updateHour=0
    				    for id = 1, 24 do
    				        if id<10 then
    				            updateHour="0"..tostring(id)
    				        else 
    				            updateHour=tostring(id)
    				        end    
    				        domoticz.devices(idxSolarForecastCounter).updateHistory(os.date("%Y-%m-%d ")..updateHour..":00:00","0;0")
    				        domoticz.devices(idxSolarForecastCounter).updateHistory(os.date("%Y-%m-%d ",os.time()+24*60*60)..updateHour..":00:00","0;0")
    				    end    
    				    
    				    -- load new forecast onto managed counter    
    				    local response=item.json.result
				        for datehour,value in pairs(response) do
				            domoticz.log("solar forecast date "..domoticz.utils.stringSplit(datehour)[1].." hour "..domoticz.utils.stringSplit(domoticz.utils.stringSplit(datehour)[2],":")[1].." value "..value,domoticz.LOG_INFO)
				            local previousHour=domoticz.utils.stringSplit(domoticz.utils.stringSplit(datehour)[2],":")[1]-1
				            if previousHour<10 then 
				                previousHour="0"..tostring(previousHour)
				            else
				                previousHour=tostring(previousHour)
				            end    
				            domoticz.log("previousHour "..previousHour)    
				            if value>0 then
				                sensorDateHour=domoticz.utils.stringSplit(datehour)[1].." "..domoticz.utils.stringSplit(domoticz.utils.stringSplit(datehour)[2],":")[1]..":00:00"
				                sValueStr="0;"..value
				                domoticz.log("sensorDateHour "..sensorDateHour.." sValueStr "..sValueStr,domoticz.LOG_INFO)
				                domoticz.devices(idxSolarForecastCounter).updateHistory(sensorDateHour,sValueStr)
				                if sensorDateHour==currentHR then
				                    domoticz.devices(idxSolarForecastCounter).updateCounter(value)
				                end    
				            end    
				        end
    				else
    				    domoticz.log("no successfull message", domoticz.LOG_INFO)
    				end    
				else
				    domoticz.log('is not json', domoticz.LOG_INFO) 
				end    
			else
				domoticz.log('There was a problem handling the request', domoticz.LOG_INFO)
				domoticz.log(item, domoticz.LOG_INFO)
			end

		end

	end
}

JanJaap
Posts: 215
Joined: Thursday 12 October 2017 20:46
Target OS: Raspberry Pi / ODroid
Domoticz version: Dev
Location: the Netherlands
Contact:

Re: solar power prediction

Post by JanJaap »

ok I can fetch data, so far so good. As I never use the dzEvents I'm a bit puzzled to how the sensor update works. Is the 24 hr forecast counter updated per hour? So only one hour form now? Or is it always giving 24 hrs ahead but all hours being updated as time passes?

See first part: JanJaapKo/SolarForecast
RPi 3, Domoticz dev version, Aeon ZWave stick (with a whole bunch of slaves), Zigbee using Zigbee2MQTT, Nest thermo, P1 smart meter on RPi Zero
erwindob
Posts: 5
Joined: Saturday 20 January 2024 12:03
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: solar power prediction

Post by erwindob »

@JanJaap
Looks promising,
I see the values in my log, but not yet in the devices. Keeping an eye on updates.
Toulon7559
Posts: 858
Joined: Sunday 23 February 2014 17:56
Target OS: Raspberry Pi / ODroid
Domoticz version: mixed
Location: Hengelo(Ov)/NL
Contact:

Re: solar power prediction

Post by Toulon7559 »

Try this weblink as introduction & explanation for the scripts earlier in this thread.
Set1 = RPI-Zero+RFXCom433+S0PCM+Shield for BMP180/DS18B20/RS485+DDS238-1ZNs
Set2 = RPI-3A++RFLinkGTW+ESP8266s+PWS_WS7000
Common = KAKUs+3*PVLogger+PWS_TFA_Nexus
plus series of 'satellites' for dedicated interfacing, monitoring & control.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest