Check PV production with sunpower (persistent data)  [Solved]

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Post Reply
riko
Posts: 90
Joined: Saturday 22 August 2020 13:36
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Check PV production with sunpower (persistent data)

Post by riko »

I'm trying to build a script to check whether my solar panels work properly. I found out that the 'Sun Power' device of Buienradar is a good predictor for the real production (real production is about 2,9 times higher than Sun power). The output is a level/color in the alert device that should be updated.

The first part of the script seems to work okay. From the moment I'm commenting the parts it is trial and error and returning error codes.

It is my first time to use persistent data with history and I think the error is caused because I'm storing a string instead of numeric values. The devices (Sun Power as well as Production) are both custom sensors. Though as you can see I've already changed the data tonumber() before adding to the database.

Does somebody know whether I'm filling the database properly and how I can retrieve these values?

Code: Select all

return 
{
    active = true,
    on = {
      devices = {
				    6, -- IDX van SunPower 
					24 -- IDX van Productie zonnepanelen in W
                  }
         },


    logging =    
    {   
        level = domoticz.LOG_DEBUG, -- change to LOG_ERROR when OK - was LOG_DEBUG
        marker = 'Zonnepanelen_defect'
    },
	
	data = 	{ solar = { history = true, maxHours = 25, maxItems = 1000 }},


    execute = function(dz, item)
    
	    local round = dz.utils.round
	
        local Solar_theoretical = dz.devices(6)   -- IDX van SunPower
        local Solar_production = dz.devices(24)   -- IDX van Productie zonnepanelen in W
        local Alert = dz.devices(46)    -- Alert device

		local lastTheoreticalWatt = round(tonumber(Solar_theoretical.state),1)
        local lastProductionWatt = round(tonumber(Solar_production.rawData[1]),1)
		
        dz.log('lastTheoreticalWatt: ' .. lastTheoreticalWatt .. ' W',dz.LOG_DEBUG)
        dz.log('lastProductionWatt: ' .. lastProductionWatt .. ' W',dz.LOG_DEBUG)
 
        dz.data.solar.add -- Store current values in persistent historical data
        (
            {
                ['theoretical'] = lastTheoreticalWatt, 
                ['production'] = lastProductionWatt
            }
        )


--        dz.log(dz.data.solar.get(2),dz.LOG_DEBUG)

		local sum_2hr = dz.data.solar.sumSince('00:01:00')
		dz.log('test ' .. sum_2hr .. ' test',dz.LOG_DEBUG)

--[[
		if (lastTheoreticalWatt <= 15 and lastProductionWatt == 0) then
		Alert.updateAlertSensor(ALERTLEVEL_GREY, 'Er is geen zon')
		dz.log('Sun power (' .. lastTheoreticalWatt .. ') < 15 W and production = 0',dz.LOG_DEBUG)
		
		elseif (theoretical.sumSince('02:00:00') > 0 and production.sumSince('02:00:00') == 0) then
		Alert.updateAlertSensor(ALERTLEVEL_RED, 'Zonnepanelen lijken niet meer te werken')		
		dz.log('Zonnepanelen lijken afgelopen 2 uur niet te werken (zonkracht was in totaal ' .. theoretical.sumSince('02:00:00') .. ', maar productie nog steeds 0)',dz.LOG_DEBUG)

		elseif (production.sumSince('24:00:00') / theoretical.sumSince('24:00:00')) > 2 then
		Alert.updateAlertSensor(ALERTLEVEL_GREEN, 'Zonnepanelen werken naar behoren')	
		dz.log('Productie per theroretisch is groter dan 2 (' .. (production.sumSince('02:00:00') / theoretical.sumSince('24:00:00')) .. ')',dz.LOG_DEBUG)

		elseif (production.sumSince('24:00:00') / theoretical.sumSince('24:00:00')) > 1 then
		Alert.updateAlertSensor(ALERTLEVEL_ORANGE, 'Zonnepanelen lijken slechter te werken')
		dz.log('Productie per theroretisch is tussen 1 en 2 (' .. (production.sumSince('02:00:00') / theoretical.sumSince('24:00:00')) .. ')',dz.LOG_DEBUG)

		elseif (production.sumSince('24:00:00') / theoretical.sumSince('24:00:00')) <= 1 then
		Alert.updateAlertSensor(ALERTLEVEL_RED, 'Zonnepanelen lijken niet meer te werken')
		dz.log('Productie per theroretisch is lager dan 1 (' .. (production.sumSince('02:00:00') / theoretical.sumSince('24:00:00')) .. ')',dz.LOG_DEBUG)
		
		end
]]--

   end
	
}
This is the error:

Code: Select all

2020-09-10 20:51:51.999 Error: dzVents: Error: (3.0.2) Zonnepanelen_defect: Item data is not a number type. Type is nil
2020-09-10 20:51:51.999 Error: dzVents: Error: (3.0.2) Zonnepanelen_defect: An error occurred when calling event handler zonnepanelen_defect_dev
2020-09-10 20:51:51.999 Error: dzVents: Error: (3.0.2) Zonnepanelen_defect: ...ticz/scripts/dzVents/scripts/zonnepanelen_defect_dev.lua:52: attempt to concatenate a nil value (local 'sum_2hr')
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Check PV production with sunpower (persistent data)

Post by waaren »

riko wrote: Thursday 10 September 2020 20:56 Does somebody know whether I'm filling the database properly and how I can retrieve these values?
You store a set in persistent historical data. This is possible but if you do that you cannot use the statistical functions like sum and avg without a helper function. Explained here .

You will make your code easier if you just store numbers (like below)

Also; Please note that having 1000 entries in persistent historical storage will have significant impact on performance.

Code: Select all

return 
{
    active = true,
    on = {
      devices = {
                    6, -- IDX van SunPower 
                    24 -- IDX van Productie zonnepanelen in W
                  }
         },


    logging =    
    {   
        level = domoticz.LOG_DEBUG, -- change to LOG_ERROR when OK - was LOG_DEBUG
        marker = 'Zonnepanelen_defect'
    },
    
    data =     
    { 
        solarTheoretical = 
        { 
            history = true,
            maxHours = 25,
            maxItems = 1000,
        },
        solarProduction = 
        { 
            history = true, 
            maxHours = 25, 
            maxItems = 1000,
    },
    

    execute = function(dz, item)
    
        local round = dz.utils.round
    
        local Solar_theoretical = dz.devices(6)   -- IDX van SunPower
        local Solar_production = dz.devices(24)   -- IDX van Productie zonnepanelen in W
        local Alert = dz.devices(46)    -- Alert device

        local lastTheoreticalWatt = round(tonumber(Solar_theoretical.state),1)
        local lastProductionWatt = round(tonumber(Solar_production.rawData[1]),1)
        
        dz.log('lastTheoreticalWatt: ' .. lastTheoreticalWatt .. ' W',dz.LOG_DEBUG)
        dz.log('lastProductionWatt: ' .. lastProductionWatt .. ' W',dz.LOG_DEBUG)
 
        dz.data.solarTheoretical.add(lastTheoreticalWatt) 
        dz.data.solarProduction.add(lastProductionWatt) 


--[[
        if (lastTheoreticalWatt <= 15 and lastProductionWatt == 0) then
        Alert.updateAlertSensor(ALERTLEVEL_GREY, 'Er is geen zon')
        dz.log('Sun power (' .. lastTheoreticalWatt .. ') < 15 W and production = 0',dz.LOG_DEBUG)
        
        elseif (theoretical.sumSince('02:00:00') > 0 and production.sumSince('02:00:00') == 0) then
        Alert.updateAlertSensor(ALERTLEVEL_RED, 'Zonnepanelen lijken niet meer te werken')        
        dz.log('Zonnepanelen lijken afgelopen 2 uur niet te werken (zonkracht was in totaal ' .. theoretical.sumSince('02:00:00') .. ', maar productie nog steeds 0)',dz.LOG_DEBUG)

        elseif (production.sumSince('24:00:00') / theoretical.sumSince('24:00:00')) > 2 then
        Alert.updateAlertSensor(ALERTLEVEL_GREEN, 'Zonnepanelen werken naar behoren')    
        dz.log('Productie per theroretisch is groter dan 2 (' .. (production.sumSince('02:00:00') / theoretical.sumSince('24:00:00')) .. ')',dz.LOG_DEBUG)

        elseif (production.sumSince('24:00:00') / theoretical.sumSince('24:00:00')) > 1 then
        Alert.updateAlertSensor(ALERTLEVEL_ORANGE, 'Zonnepanelen lijken slechter te werken')
        dz.log('Productie per theroretisch is tussen 1 en 2 (' .. (production.sumSince('02:00:00') / theoretical.sumSince('24:00:00')) .. ')',dz.LOG_DEBUG)

        elseif (production.sumSince('24:00:00') / theoretical.sumSince('24:00:00')) <= 1 then
        Alert.updateAlertSensor(ALERTLEVEL_RED, 'Zonnepanelen lijken niet meer te werken')
        dz.log('Productie per theroretisch is lager dan 1 (' .. (production.sumSince('02:00:00') / theoretical.sumSince('24:00:00')) .. ')',dz.LOG_DEBUG)
        
        end
]]--

   end
    
}
 
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
riko
Posts: 90
Joined: Saturday 22 August 2020 13:36
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Check PV production with sunpower (persistent data)

Post by riko »

Thanks waaren, impressed by your skills and speed! It's working. I've read the concept of the helper function, but didn't get it :( Luckily I don't need it this way.

I'm now working on the alert sensor update criteria and will share the final results of the script for reuse.
riko
Posts: 90
Joined: Saturday 22 August 2020 13:36
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Check PV production with sunpower (persistent data)

Post by riko »

This is the result. Using the status to update the alert device (IDX 46). I have to check the performance due to the big numbers in the database. The devices are updated every 30 seconds, meaning that 24 hours of data equals 24*60*2 = 2880 records

Code: Select all

return 
{
    active = true,
    on = {
      devices = {
                    6, -- IDX van SunPower 
                    24 -- IDX van Productie zonnepanelen in W
                  }
         },


    logging =    
    {   
        level = domoticz.LOG_DEBUG, -- change to LOG_ERROR when OK - was LOG_DEBUG
        marker = 'Zonnepanelen_defect'
    },
    
    data =     
    { 
        solarTheoretical = 
        { 
            history = true,
            maxHours = 25,
            maxItems = 5000,
        },
        solarProduction = 
        { 
            history = true, 
            maxHours = 25,
            maxItems = 5000,
    }},
    

    execute = function(dz, item)
    
        local round = dz.utils.round
    
        local Solar_theoretical = dz.devices(6)   -- IDX van SunPower
        local Solar_production = dz.devices(24)   -- IDX van Productie zonnepanelen in W
        local Alert = dz.devices(46)    -- Alert device

        local lastTheoreticalWatt = round(tonumber(Solar_theoretical.state),0)
        local lastProductionWatt = round(tonumber(Solar_production.rawData[1]),0)
        
        dz.log('lastTheoreticalWatt: ' .. lastTheoreticalWatt .. ' W',dz.LOG_DEBUG)
        dz.log('lastProductionWatt: ' .. lastProductionWatt .. ' W',dz.LOG_DEBUG)
 
        dz.data.solarTheoretical.add(lastTheoreticalWatt) 
        dz.data.solarProduction.add(lastProductionWatt) 
		
		-- Calculate total production of 2 hours and 24 hours
		local th_sum_2hr = dz.data.solarTheoretical.sumSince('02:00:00')
		local pr_sum_2hr = dz.data.solarProduction.sumSince('02:00:00')
		local th_sum_24hr = dz.data.solarTheoretical.sumSince('24:00:00')
		local pr_sum_24hr = dz.data.solarProduction.sumSince('24:00:00')

		dz.log('Theoretical sum 2hr ' .. th_sum_2hr .. ' W',dz.LOG_DEBUG)
		dz.log('Production sum 2hr ' .. pr_sum_2hr .. ' W',dz.LOG_DEBUG)
		dz.log('Theoretical sum 24hr ' .. th_sum_24hr .. ' W',dz.LOG_DEBUG)
		dz.log('Production sum 24hr ' .. pr_sum_24hr .. ' W',dz.LOG_DEBUG)

        if (lastTheoreticalWatt <= 15 and lastProductionWatt == 0) then
        Alert.updateAlertSensor(dz.ALERTLEVEL_GREY, 'Er is geen zon')
        dz.log('Sun power (' .. lastTheoreticalWatt .. ') < 15 W and production = 0',dz.LOG_DEBUG)
       
        elseif (th_sum_2hr > 0 and pr_sum_2hr == 0) then
        Alert.updateAlertSensor(dz.ALERTLEVEL_RED, 'Zonnepanelen lijken niet meer te werken')        
        dz.log('Zonnepanelen lijken afgelopen 2 uur niet te werken (zonkracht was in totaal ' .. th_sum_2hr .. 'W, maar productie nog steeds ' .. pr_sum_2hr .. 'W)',dz.LOG_DEBUG)
		dz.notify('Zonnepanelen check','Zonnepanelen lijken afgelopen 2 uur niet te werken (zonkracht was in totaal ' .. th_sum_2hr .. 'W, maar productie nog steeds ' .. pr_sum_2hr .. 'W)', dz.PRIORITY_NORMAL,dz.SOUND_DEFAULT, "" , dz.NSS_TELEGRAM)
		
        elseif (pr_sum_24hr / th_sum_24hr) > 2 then
        Alert.updateAlertSensor(dz.ALERTLEVEL_GREEN, 'Zonnepanelen werken naar behoren')    
        dz.log('Productie per theroretisch is groter dan 2 (' .. (pr_sum_24hr / th_sum_24hr) .. ')',dz.LOG_DEBUG)
--  		dz.notify('Zonnepanelen check','Productie/theoretisch ratio is <1 (' .. (pr_sum_24hr / th_sum_24hr) .. ')', dz.PRIORITY_NORMAL,dz.SOUND_DEFAULT, "" , dz.NSS_TELEGRAM)

        elseif (pr_sum_24hr / th_sum_24hr) > 1 then
        Alert.updateAlertSensor(dz.ALERTLEVEL_ORANGE, 'Zonnepanelen lijken slechter te werken')
        dz.log('Productie/theoretisch ratio is tussen 1 en 2 (' .. (pr_sum_24hr / th_sum_24hr) .. ')',dz.LOG_DEBUG)
		dz.notify('Zonnepanelen check','Zonnepanelen check','Productie/theoretisch ratio is tussen 1 en 2 (' .. (pr_sum_24hr / th_sum_24hr) .. ')', dz.PRIORITY_NORMAL,dz.SOUND_DEFAULT, "" , dz.NSS_TELEGRAM)

        elseif (pr_sum_24hr / th_sum_24hr) <= 1 then
        Alert.updateAlertSensor(dz.ALERTLEVEL_RED, 'Zonnepanelen lijken niet meer te werken')
        dz.log('Productie/theoretisch ratio is <1 (' .. (pr_sum_24hr / th_sum_24hr) .. ')',dz.LOG_DEBUG)
  		dz.notify('Zonnepanelen check','Productie/theoretisch ratio is <1 (' .. (pr_sum_24hr / th_sum_24hr) .. ')', dz.PRIORITY_NORMAL,dz.SOUND_DEFAULT, "" , dz.NSS_TELEGRAM)

        end


	end
    
}
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Check PV production with sunpower (persistent data)

Post by waaren »

riko wrote: Friday 11 September 2020 19:20 This is the result. Using the status to update the alert device (IDX 46). I have to check the performance due to the big numbers in the database. The devices are updated every 30 seconds, meaning that 24 hours of data equals 24*60*2 = 2880 records
In fact it is even more as the script is triggered by both devices and you update the persistent data regardless of what triggered the script.
So 2 * 2 * 24 * 60
I would be very surprised if this is going to work (performance wise) as the script will eventually have to read and interpret 10000 rows from persistent data 4 times a minute.
Probably you will need to aggregate the data in some way
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Check PV production with sunpower (persistent data)

Post by waaren »

waaren wrote: Friday 11 September 2020 21:03 Probably you will need to aggregate the data in some way
Using below script the data is aggregated on a per hour basis. Can you try and report back?

Code: Select all

return
{
    active = true,

    on =
    {
        devices =
        {
             6, -- IDX van SunPower
            24, -- IDX van Productie zonnepanelen in W
        },
    },

    logging =
    {
        level = domoticz.LOG_DEBUG, -- change to LOG_ERROR when OK - was LOG_DEBUG
        marker = 'Zonnepanelen_defect'
    },

    data =
    {
        solar =
        {
            initial = {},
        }
    },


    execute = function(dz, item)

        local round = dz.utils.round

        local Solar_theoretical = dz.devices(6)   -- IDX van SunPower
        local Solar_production = dz.devices(24)   -- IDX van Productie zonnepanelen in W
        local Alert = dz.devices(46)    -- Alert device

        local function initPersistentData()
            dz.data.solar.theoretical = {}
            dz.data.solar.production = {}

            for hour = 0,23 do
                dz.data.solar.theoretical[hour] = { ['time'] = 0, ['sum'] = 0 }
                dz.data.solar.production[hour] = { ['time'] = 0, ['sum'] = 0 }
            end

        end

        local function updatePersistentData(calculated, real )
            if dz.data.solar.theoretical[dz.time.hour].time < ( os.time() - 3600 ) then
                dz.data.solar.theoretical[dz.time.hour].sum = calculated
            else
                dz.data.solar.theoretical[dz.time.hour].sum = dz.data.solar.theoretical[dz.time.hour].sum + calculated
            end
            dz.data.solar.theoretical[dz.time.hour].time = os.time()

            if dz.data.solar.production[dz.time.hour].time < ( os.time() - 3600 ) then
                dz.data.solar.production[dz.time.hour].sum = real
            else
                dz.data.solar.production[dz.time.hour].sum = dz.data.solar.production[dz.time.hour].sum + real
            end
            dz.data.solar.production[dz.time.hour].time = os.time()
        end

        local function getPersistent(data, period)
            if period == 1 then
                return dz.data.solar[data][dz.time.hour].sum
            elseif period == 2 then
                return (
                            dz.data.solar[data][( dz.time.hour + 23 ) % 24 ].sum + -- hour minus 1
                            dz.data.solar[data][( dz.time.hour + 22 ) % 24 ].sum + -- hour minus 2
                            dz.data.solar[data][dz.time.hour].sum
                        )
            elseif period == 24 then
                local total = 0
                for hour = 0, 23 do
                    total = total + dz.data.solar[data][hour].sum
                end
                return total
            end
        end

        if dz.data.solar.theoretical == nil then
            initPersistentData()
        end

        local lastTheoreticalWatt = round(tonumber(Solar_theoretical.state))
        local lastProductionWatt = round(tonumber(Solar_production.rawData[1]))

        dz.log('lastTheoreticalWatt: ' .. lastTheoreticalWatt .. ' W',dz.LOG_DEBUG)
        dz.log('lastProductionWatt: ' .. lastProductionWatt .. ' W',dz.LOG_DEBUG)

        updatePersistentData(lastTheoreticalWatt, lastProductionWatt )

        -- Calculate total production of 2 hours and 24 hours
        local th_sum_2hr = getPersistent('theoretical',2)
        local pr_sum_2hr = getPersistent('production',2)
        local th_sum_24hr = getPersistent('theoretical',24)
        local pr_sum_24hr = getPersistent('production',24)

        dz.log('Theoretical sum 2hr ' .. th_sum_2hr .. ' W',dz.LOG_DEBUG)
        dz.log('Production sum 2hr ' .. pr_sum_2hr .. ' W',dz.LOG_DEBUG)
        dz.log('Theoretical sum 24hr ' .. th_sum_24hr .. ' W',dz.LOG_DEBUG)
        dz.log('Production sum 24hr ' .. pr_sum_24hr .. ' W',dz.LOG_DEBUG)

        if (lastTheoreticalWatt <= 15 and lastProductionWatt == 0) then
        Alert.updateAlertSensor(dz.ALERTLEVEL_GREY, 'Er is geen zon')
        dz.log('Sun power (' .. lastTheoreticalWatt .. ') < 15 W and production = 0',dz.LOG_DEBUG)

        elseif (th_sum_2hr > 0 and pr_sum_2hr == 0) then
        Alert.updateAlertSensor(dz.ALERTLEVEL_RED, 'Zonnepanelen lijken niet meer te werken')
        dz.log('Zonnepanelen lijken afgelopen 2 uur niet te werken (zonkracht was in totaal ' .. th_sum_2hr .. 'W, maar productie nog steeds ' .. pr_sum_2hr .. 'W)',dz.LOG_DEBUG)
        dz.notify('Zonnepanelen check','Zonnepanelen lijken afgelopen 2 uur niet te werken (zonkracht was in totaal ' .. th_sum_2hr .. 'W, maar productie nog steeds ' .. pr_sum_2hr .. 'W)', dz.PRIORITY_NORMAL,dz.SOUND_DEFAULT, "" , dz.NSS_TELEGRAM)

        elseif (pr_sum_24hr / th_sum_24hr) > 2 then
        Alert.updateAlertSensor(dz.ALERTLEVEL_GREEN, 'Zonnepanelen werken naar behoren')
        dz.log('Productie per theroretisch is groter dan 2 (' .. (pr_sum_24hr / th_sum_24hr) .. ')',dz.LOG_DEBUG)
--          dz.notify('Zonnepanelen check','Productie/theoretisch ratio is <1 (' .. (pr_sum_24hr / th_sum_24hr) .. ')', dz.PRIORITY_NORMAL,dz.SOUND_DEFAULT, "" , dz.NSS_TELEGRAM)

        elseif (pr_sum_24hr / th_sum_24hr) > 1 then
        Alert.updateAlertSensor(dz.ALERTLEVEL_ORANGE, 'Zonnepanelen lijken slechter te werken')
        dz.log('Productie/theoretisch ratio is tussen 1 en 2 (' .. (pr_sum_24hr / th_sum_24hr) .. ')',dz.LOG_DEBUG)
        dz.notify('Zonnepanelen check','Zonnepanelen check','Productie/theoretisch ratio is tussen 1 en 2 (' .. (pr_sum_24hr / th_sum_24hr) .. ')', dz.PRIORITY_NORMAL,dz.SOUND_DEFAULT, "" , dz.NSS_TELEGRAM)

        elseif (pr_sum_24hr / th_sum_24hr) <= 1 then
        Alert.updateAlertSensor(dz.ALERTLEVEL_RED, 'Zonnepanelen lijken niet meer te werken')
        dz.log('Productie/theoretisch ratio is <1 (' .. (pr_sum_24hr / th_sum_24hr) .. ')',dz.LOG_DEBUG)
        dz.notify('Zonnepanelen check','Productie/theoretisch ratio is <1 (' .. (pr_sum_24hr / th_sum_24hr) .. ')', dz.PRIORITY_NORMAL,dz.SOUND_DEFAULT, "" , dz.NSS_TELEGRAM)

        end

    end

}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
riko
Posts: 90
Joined: Saturday 22 August 2020 13:36
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Check PV production with sunpower (persistent data)

Post by riko »

waaren wrote: Friday 11 September 2020 22:57
waaren wrote: Friday 11 September 2020 21:03 Probably you will need to aggregate the data in some way
Using below script the data is aggregated on a per hour basis. Can you try and report back?
Wow I've missed this update, sorry! Great work again.

The script is running for a few days now without the aggegration and no issues yet. What kind of problems do you expect? CPU? Memory? I would like to try your aggegrating script later on. But I've made quite some adjustments in the meantime so it takes some time to integrate it.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Check PV production with sunpower (persistent data)

Post by waaren »

riko wrote: Wednesday 16 September 2020 20:01 The script is running for a few days now without the aggegration and no issues yet. What kind of problems do you expect? CPU? Memory?
Probably IO will be the first exhausted resource. How much time is there now between start and finish of the script? And what do you see when you look in <domoticz dir>/scripts/dzVents/data/
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
riko
Posts: 90
Joined: Saturday 22 August 2020 13:36
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Check PV production with sunpower (persistent data)

Post by riko »

waaren wrote: Wednesday 16 September 2020 20:16
riko wrote: Wednesday 16 September 2020 20:01 The script is running for a few days now without the aggegration and no issues yet. What kind of problems do you expect? CPU? Memory?
Probably IO will be the first exhausted resource. How much time is there now between start and finish of the script? And what do you see when you look in <domoticz dir>/scripts/dzVents/data/

Only 1 second:

Code: Select all

2020-09-19 21:09:11.745 Status: dzVents: Info: Zonnepanelen_defect: ------ Start external script: zonnepanelen_check_2.lua: Device: "Sun Power (BR) (Buienradar)", Index: 6
2020-09-19 21:09:12.511 Status: dzVents: Info: Zonnepanelen_defect: ------ Finished zonnepanelen_check_2.lua
The data file is data folder is 260kb.

Not bad at all I think? The script is at least running every 30 sec at daytime (that is the frequency my solar panels are updating the data). Not sure how often the Buienradar data is updated (which is also triggering the script)
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Check PV production with sunpower (persistent data)

Post by waaren »

riko wrote: Saturday 19 September 2020 21:13 Not bad at all I think? The script is at least running every 30 sec at daytime (that is the frequency my solar panels are updating the data). Not sure how often the Buienradar data is updated (which is also triggering the script)
Indeed much better then expected. But please be aware that during the time a Lua, dzVents or Blockly script is active no other event-scripts can start and writing 240K every 30 seconds might also wear your sd-card prematurely.
For comparing you might want to check how long a dzVents script without a data section runs before finishing.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
riko
Posts: 90
Joined: Saturday 22 August 2020 13:36
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Check PV production with sunpower (persistent data)

Post by riko »

waaren wrote: Monday 21 September 2020 12:54
riko wrote: Saturday 19 September 2020 21:13 Not bad at all I think? The script is at least running every 30 sec at daytime (that is the frequency my solar panels are updating the data). Not sure how often the Buienradar data is updated (which is also triggering the script)
Indeed much better then expected. But please be aware that during the time a Lua, dzVents or Blockly script is active no other event-scripts can start and writing 240K every 30 seconds might also wear your sd-card prematurely.
For comparing you might want to check how long a dzVents script without a data section runs before finishing.
Thanks for the tips. I've put your aggegrated version of the script on my backlog. But will take some time to experiment with.

In this context: i have a lot of scripts running for instance every 5 minutes. Starting at 00:05, 00:10, etc. Is there an option to run a script every five minutes (or every hour etc) but then a bit shifted? For instance 00:06, 00:11, ...
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Check PV production with sunpower (persistent data)

Post by waaren »

riko wrote: Monday 21 September 2020 19:37 In this context: i have a lot of scripts running for instance every 5 minutes. Starting at 00:05, 00:10, etc. Is there an option to run a script every five minutes (or every hour etc) but then a bit shifted? For instance 00:06, 00:11, ...
Sure:

Code: Select all

return 
{
        on =
        {
            timer =
            {
                --'every 5 minutes shifted',
                'at *:01', 'at *:06','at *:11','at *:16','at *:21','at *:26','at *:31','at *:36','at *:41','at *:46','at *:51',,'at *:56',
            },
        },
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
riko
Posts: 90
Joined: Saturday 22 August 2020 13:36
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Check PV production with sunpower (persistent data)  [Solved]

Post by riko »

waaren wrote: Monday 21 September 2020 21:50
riko wrote: Monday 21 September 2020 19:37 In this context: i have a lot of scripts running for instance every 5 minutes. Starting at 00:05, 00:10, etc. Is there an option to run a script every five minutes (or every hour etc) but then a bit shifted? For instance 00:06, 00:11, ...
Sure:

Code: Select all

return 
{
        on =
        {
            timer =
            {
                --'every 5 minutes shifted',
                'at *:01', 'at *:06','at *:11','at *:16','at *:21','at *:26','at *:31','at *:36','at *:41','at *:46','at *:51',,'at *:56',
            },
        },
Of course.... Nice! :)
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest