Page 2 of 3

Re: Lua version problem domoticz

Posted: Monday 30 March 2020 10:19
by sjoemie1985
I think i have finally a working script to upload my data to pvoutput.org
i only can't see the energy used and power used on pvoutput

i have this sctipt in use:
any one who knows how to get these 2 data also in pvoutput.org?

Code: Select all

return {
    active = true,
    logging = {
        --level = domoticz.LOG_DEBUG, -- Uncomment to override the dzVents global logging setting and use debug
        marker = 'PVOutput'
    },
   on = {
      timer = {
         'every 5 minutes'   -- The number of minutes between posts to PVoutput (normal is 5 but when in donation mode it's max 1)
      },
      httpResponses = { 'triggerPVoutput' }
   },
   execute = function(domoticz,item)
       
        ----------------------------------------------------------------------------------------------------------
        -- PVoutput parameters
        ----------------------------------------------------------------------------------------------------------
        local PVoutputApi = 'c550e7568ba649922fd015828f37667bf4xxxxxx8'      -- Your PVoutput api key
        local PVoutputSystemID = 'xxxxx'                                    -- Your PVoutput System ID
        local PVoutputURL = 'http://pvoutput.org/service/r2/addstatus.jsp'  -- The URL to the PVoutput Service
        ----------------------------------------------------------------------------------------------------------
        -- Domoticz Sensor parameters
        ----------------------------------------------------------------------------------------------------------
        local tempSensor = 'THB'
        local ConsumptionSensor = 'ConsumptionDevice'

        domoticz.log('PVOutput script running', domoticz.LOG_DEBUG)

        if (item.isTimer) then
            local temperature = domoticz.devices(tempSensor).temperature
            local Temperature = domoticz.round(temperature,2)
            local EnergyConsumption  = domoticz.devices(ConsumptionSensor).counterToday*1000 -- v3 in Watt hours
            local PowerConsumption  = domoticz.devices(ConsumptionSensor).usage              -- v4 in Watts
            domoticz.log('Temperature is :'..Temperature..' graden', domoticz.LOG_DEBUG)
            domoticz.log('EnergyConsumption is :'..EnergyConsumption..' Wh', domoticz.LOG_DEBUG)
            domoticz.log('PowerConsumption is :'..PowerConsumption..' watt', domoticz.LOG_DEBUG)


            domoticz.log('Call PVOutput url with callback', domoticz.LOG_DEBUG)
            -- ASYNC openUrl
            domoticz.openURL({
                                url = PVoutputURL..'?d='..os.date("%Y%m%d")..'&t='..os.date("%H:%M")..'&v3='..EnergyConsumption..'&v4='..PowerConsumption,
                                method = 'GET',
                                callback = 'triggerPVoutput',
                                headers = { ['X-Pvoutput-Apikey'] = PVoutputApi, 
                                            ['X-Pvoutput-SystemId'] = PVoutputSystemID
                                          }
            })
        
        
        end

        if (item.isHTTPResponse) then 
            domoticz.log('Callback from url requested. Statuscode:'..item.statusCode, domoticz.LOG_DEBUG)

            if (item.ok) then
                local valid = string.find(item.data, "OK 200: Added Status")  
                if (valid ~= nil) then
                    domoticz.log('Response received from PVOutput: '..item.data, domoticz.LOG_DEBUG)
        
                    domoticz.log('Current status successfully uploaded to PVoutput.', domoticz.LOG_INFO)
                else
                    domoticz.log('Current status NOT successfully uploaded to PVoutput -> '..item.data, domoticz.LOG_ERROR)
                end
            else
                domoticz.log('Current status NOT successfully uploaded to PVoutput. Statuscode:'..item.statusCode, domoticz.LOG_ERROR)
            end        
        end
    end

}

Re: Lua version problem domoticz

Posted: Monday 30 March 2020 10:33
by waaren
sjoemie1985 wrote: Monday 30 March 2020 10:19 I think i have finally a working script to upload my data to pvoutput.org
i only can't see the energy used and power used on pvoutput
Some questions
  • What do you see in the domoticz log
  • What type of device (type / subtype) is 'ConsumptionDevice'
You can also find another dzVents pvoutput script here

Re: Lua version problem domoticz

Posted: Monday 30 March 2020 11:33
by sjoemie1985
waaren wrote: Monday 30 March 2020 10:33
sjoemie1985 wrote: Monday 30 March 2020 10:19 I think i have finally a working script to upload my data to pvoutput.org
i only can't see the energy used and power used on pvoutput
Some questions
  • What do you see in the domoticz log
  • What type of device (type / subtype) is 'ConsumptionDevice'
You can also find another dzVents pvoutput script here
i see this
and many more, but it goes pretty fast, the logging.
the consumptiondevice is made with an dummy from domoticz

Image

Re: Lua version problem domoticz

Posted: Monday 30 March 2020 13:47
by sjoemie1985
I tried that new script, it seems to be uploading, but i get still the following error :(

Code: Select all

2020-03-30 13:40:00.270 Error: dzVents: Error: (3.0.1) pvOutput: An error occurred when calling event handler script_Time_Upload_to_PVoutput
2020-03-30 13:40:00.270 Error: dzVents: Error: (3.0.1) pvOutput: /home/pi/domoticz/dzVents/runtime/Utils.lua:121: attempt to perform arithmetic on a string value (local 'x')

Re: Lua version problem domoticz

Posted: Monday 30 March 2020 13:59
by waaren
sjoemie1985 wrote: Monday 30 March 2020 13:47 I tried that new script, it seems to be uploading, but i get still the following error :(

Code: Select all

2020-03-30 13:40:00.270 Error: dzVents: Error: (3.0.1) pvOutput: An error occurred when calling event handler script_Time_Upload_to_PVoutput
2020-03-30 13:40:00.270 Error: dzVents: Error: (3.0.1) pvOutput: /home/pi/domoticz/dzVents/runtime/Utils.lua:121: attempt to perform arithmetic on a string value (local 'x')
can you change the lines

Code: Select all

            '&v5=' .. round(temperature.temperature,1) .. 
            '&v6=' .. round(voltage.sValue,1) ..
to

Code: Select all

            '&v5=' .. round(tonumber(temperature.temperature),1) .. 
            '&v6=' .. round(tonumber(voltage.sValue),1) ..
and try again ?

Re: Lua version problem domoticz

Posted: Monday 30 March 2020 14:07
by sjoemie1985
waaren wrote: Monday 30 March 2020 13:59
sjoemie1985 wrote: Monday 30 March 2020 13:47 I tried that new script, it seems to be uploading, but i get still the following error :(

Code: Select all

2020-03-30 13:40:00.270 Error: dzVents: Error: (3.0.1) pvOutput: An error occurred when calling event handler script_Time_Upload_to_PVoutput
2020-03-30 13:40:00.270 Error: dzVents: Error: (3.0.1) pvOutput: /home/pi/domoticz/dzVents/runtime/Utils.lua:121: attempt to perform arithmetic on a string value (local 'x')
can you change the lines

Code: Select all

            '&v5=' .. round(temperature.temperature,1) .. 
            '&v6=' .. round(voltage.sValue,1) ..
to

Code: Select all

            '&v5=' .. round(tonumber(temperature.temperature),1) .. 
            '&v6=' .. round(tonumber(voltage.sValue),1) ..
and try again ?
done that but still the same error.

Re: Lua version problem domoticz

Posted: Monday 30 March 2020 14:49
by waaren
sjoemie1985 wrote: Monday 30 March 2020 14:07 done that but still the same error.
OK. Can you show the script as you have it now and show the device types and subtypes of the devices you use to get the data from in the script.

Re: Lua version problem domoticz

Posted: Monday 30 March 2020 14:51
by sjoemie1985
waaren wrote: Monday 30 March 2020 14:49
sjoemie1985 wrote: Monday 30 March 2020 14:07 done that but still the same error.
OK. Can you show the script as you have it now and show the device types and subtypes of the devices you use to get the data from in the script.
offcourse here it is.

Code: Select all

--[[
        dzVents version of pvOutput script.
        api-key and id stored in domoticz uservariables type string
]]

local scriptVar = 'PVOutput'

return {
            on =    { 
                        timer = { 'every 5 minutes'},
                        httpResponses = { scriptVar },
                    },
 
       logging =    {   
                        level   =   domoticz.LOG_DEBUG, -- change to error when OK
                        marker  =   "pvOutput" 
                    },    

    execute = function(dz, item)
            
        local function post2PVOutput(PVSettings, postData)
            -- dz.utils.dumpTable(PVSettings, 'PVSettings > ')
            -- dz.log('postData: ' .. postData,dz.LOG_FORCE)
            dz.openURL({
                url = PVSettings.url,
                method = 'POST',
                headers = {
                    ['X-Pvoutput-Apikey'] = PVSettings.api,
                    ['X-Pvoutput-SystemId'] = PVSettings.id
                },
                callback = scriptVar,
                postData = postData
            })
        end
        
        local function makepostData()
            local P1 = dz.devices('Power') 
            local temperature = dz.devices('THB')
            local voltage = dz.devices('VoltageOutput')
            local round = dz.utils.round
            
            local postdDataAsString = 
            'd=' .. os.date("%Y%m%d") ..
            '&t=' .. os.date("%H:%M") .. 
            '&v1=' .. P1.return1 + P1.return2 ..
            '&v2=' .. P1.usageDelivered ..
            '&v3=' .. P1.usage1 + P1.usage2 ..
            '&v4=' .. P1.usage ..
            '&v5=' .. round(tonumber(temperature.temperature),1) .. 
            '&v6=' .. round(tonumber(voltage.sValue),1) ..
            
            '&c1=1'
            
            --[[ 
                v1 - energy generation
                v2 - power generation            W from 
                v3 - energy consumption
                v4 - power consumption
                v5 - temperature
                v6 - voltage
            '&c1= ..  c1
            '&n= .. n
                                            Donation mode only parms
            '&delay=' .. Delay
            '&v7=' .. WaterConsumption
            '&v8=' .. InverterFrequency
            '&v11=' .. InverterTemp
            '&v12=' .. GasConsumption
            ]] -- 
           
            return postdDataAsString
        end

        if item.isHTTPResponse then
            dz.log("Return from PVOutput ==>> " .. item.data,dz.LOG_FORCE)
        else
            
            PVSettings = 
            {
            url = 'HTTPS://pvoutput.org/service/r2/addstatus.jsp',
            api = dz.variables('PVoutput_API').value,
            id  = dz.variables('PVoutput_ID').value,
            }
            
            post2PVOutput(PVSettings, makepostData())
        end
    end
}
    

Re: Lua version problem domoticz

Posted: Monday 30 March 2020 15:12
by waaren
sjoemie1985 wrote: Monday 30 March 2020 14:51
waaren wrote: Monday 30 March 2020 14:49
OK. Can you show the script as you have it now and show the device types and subtypes of the devices you use to get the data from in the script.
offcourse here it is.
I also asked for the types and subtypes of the devices you use. I need that information to help you !!

Added some extra log statements

Code: Select all

--[[
        dzVents version of pvOutput script.
        api-key and id stored in domoticz uservariables type string
]]

local scriptVar = 'PVOutput'

return {
            on =    { 
                        timer = { 'every 5 minutes'},
                        httpResponses = { scriptVar },
                    },
 
       logging =    {   
                        level   =   domoticz.LOG_DEBUG, -- change to error when OK
                        marker  =   "pvOutput" 
                    },    

    execute = function(dz, item)
            
        local function post2PVOutput(PVSettings, postData)
            -- dz.utils.dumpTable(PVSettings, 'PVSettings > ')
            -- dz.log('postData: ' .. postData,dz.LOG_FORCE)
            dz.openURL({
                url = PVSettings.url,
                method = 'POST',
                headers = {
                    ['X-Pvoutput-Apikey'] = PVSettings.api,
                    ['X-Pvoutput-SystemId'] = PVSettings.id
                },
                callback = scriptVar,
                postData = postData
            })
        end
        
        local function makepostData()
            local P1 = dz.devices('Power') 
            local temperature = dz.devices('THB')
            local voltage = dz.devices('VoltageOutput')
            local round = dz.utils.round
            
            
            dz.log('P1         : ' .. P1.sValue,dz.LOG_DEBUG)
            dz.log('Temperature: ' .. temperature.temperature,dz.LOG_DEBUG)
            dz.log('voltage: ' .. voltage.sValue,dz.LOG_DEBUG)
            
            local postdDataAsString = 
            'd=' .. os.date("%Y%m%d") ..
            '&t=' .. os.date("%H:%M") .. 
            '&v1=' .. P1.return1 + P1.return2 ..
            '&v2=' .. P1.usageDelivered ..
            '&v3=' .. P1.usage1 + P1.usage2 ..
            '&v4=' .. P1.usage ..
            '&v5=' .. round(tonumber(temperature.temperature),1) .. 
            '&v6=' .. round(tonumber(voltage.sValue),1) ..
            
            '&c1=1'
            
            --[[ 
                v1 - energy generation
                v2 - power generation            W from 
                v3 - energy consumption
                v4 - power consumption
                v5 - temperature
                v6 - voltage
            '&c1= ..  c1
            '&n= .. n
                                            Donation mode only parms
            '&delay=' .. Delay
            '&v7=' .. WaterConsumption
            '&v8=' .. InverterFrequency
            '&v11=' .. InverterTemp
            '&v12=' .. GasConsumption
            ]] -- 
           
            return postdDataAsString
        end

        if item.isHTTPResponse then
            dz.log("Return from PVOutput ==>> " .. item.data,dz.LOG_FORCE)
        else
            
            PVSettings = 
            {
            url = 'HTTPS://pvoutput.org/service/r2/addstatus.jsp',
            api = dz.variables('PVoutput_API').value,
            id  = dz.variables('PVoutput_ID').value,
            }
            
            post2PVOutput(PVSettings, makepostData())
        end
    end
}
    

Re: Lua version problem domoticz

Posted: Monday 30 March 2020 15:18
by sjoemie1985
waaren wrote: Monday 30 March 2020 15:12
sjoemie1985 wrote: Monday 30 March 2020 14:51
waaren wrote: Monday 30 March 2020 14:49
OK. Can you show the script as you have it now and show the device types and subtypes of the devices you use to get the data from in the script.
offcourse here it is.
I also asked for the types and subtypes of the devices you use. I need that information to help you !!

Added some extra log statements

Code: Select all

--[[
        dzVents version of pvOutput script.
        api-key and id stored in domoticz uservariables type string
]]

local scriptVar = 'PVOutput'

return {
            on =    { 
                        timer = { 'every 5 minutes'},
                        httpResponses = { scriptVar },
                    },
 
       logging =    {   
                        level   =   domoticz.LOG_DEBUG, -- change to error when OK
                        marker  =   "pvOutput" 
                    },    

    execute = function(dz, item)
            
        local function post2PVOutput(PVSettings, postData)
            -- dz.utils.dumpTable(PVSettings, 'PVSettings > ')
            -- dz.log('postData: ' .. postData,dz.LOG_FORCE)
            dz.openURL({
                url = PVSettings.url,
                method = 'POST',
                headers = {
                    ['X-Pvoutput-Apikey'] = PVSettings.api,
                    ['X-Pvoutput-SystemId'] = PVSettings.id
                },
                callback = scriptVar,
                postData = postData
            })
        end
        
        local function makepostData()
            local P1 = dz.devices('Power') 
            local temperature = dz.devices('THB')
            local voltage = dz.devices('VoltageOutput')
            local round = dz.utils.round
            
            
            dz.log('P1         : ' .. P1.sValue,dz.LOG_DEBUG)
            dz.log('Temperature: ' .. temperature.temperature,dz.LOG_DEBUG)
            dz.log('voltage: ' .. voltage.sValue,dz.LOG_DEBUG)
            
            local postdDataAsString = 
            'd=' .. os.date("%Y%m%d") ..
            '&t=' .. os.date("%H:%M") .. 
            '&v1=' .. P1.return1 + P1.return2 ..
            '&v2=' .. P1.usageDelivered ..
            '&v3=' .. P1.usage1 + P1.usage2 ..
            '&v4=' .. P1.usage ..
            '&v5=' .. round(tonumber(temperature.temperature),1) .. 
            '&v6=' .. round(tonumber(voltage.sValue),1) ..
            
            '&c1=1'
            
            --[[ 
                v1 - energy generation
                v2 - power generation            W from 
                v3 - energy consumption
                v4 - power consumption
                v5 - temperature
                v6 - voltage
            '&c1= ..  c1
            '&n= .. n
                                            Donation mode only parms
            '&delay=' .. Delay
            '&v7=' .. WaterConsumption
            '&v8=' .. InverterFrequency
            '&v11=' .. InverterTemp
            '&v12=' .. GasConsumption
            ]] -- 
           
            return postdDataAsString
        end

        if item.isHTTPResponse then
            dz.log("Return from PVOutput ==>> " .. item.data,dz.LOG_FORCE)
        else
            
            PVSettings = 
            {
            url = 'HTTPS://pvoutput.org/service/r2/addstatus.jsp',
            api = dz.variables('PVoutput_API').value,
            id  = dz.variables('PVoutput_ID').value,
            }
            
            post2PVOutput(PVSettings, makepostData())
        end
    end
}
    
see images is hope this is enough info :)
Image
Image

Code: Select all

2020-03-30 15:17:22.931 Status: LUA: ----- EnergyConsumption = 731646.0 Wh
2020-03-30 15:17:23.763 (P1 Slimme meter) P1 Smart Meter (Power)
2020-03-30 15:17:23.768 (P1 Slimme meter) General/Voltage (Voltage L1)
2020-03-30 15:17:23.772 (P1 Slimme meter) Usage (Usage L1)
2020-03-30 15:17:23.777 (P1 Slimme meter) Usage (Delivery L1)
2020-03-30 15:17:24.763 (P1 Slimme meter) P1 Smart Meter (Power)
2020-03-30 15:17:24.769 (P1 Slimme meter) General/Voltage (Voltage L1)
2020-03-30 15:17:24.774 (P1 Slimme meter) Usage (Usage L1)
2020-03-30 15:17:24.780 (P1 Slimme meter) Usage (Delivery L1)
2020-03-30 15:17:25.765 (P1 Slimme meter) P1 Smart Meter (Power)
2020-03-30 15:17:25.770 (P1 Slimme meter) General/Voltage (Voltage L1)
2020-03-30 15:17:25.775 (P1 Slimme meter) Usage (Usage L1)
2020-03-30 15:17:25.779 (P1 Slimme meter) Usage (Delivery L1)
2020-03-30 15:17:25.793 (Semsportal) Pushing 'onHeartbeatCallback' on to queue
2020-03-30 15:17:25.836 (Semsportal) Processing 'onHeartbeatCallback' message
2020-03-30 15:17:25.836 (Semsportal) Calling message handler 'onHeartbeat'.
2020-03-30 15:17:25.837 (Semsportal) onHeartbeat called, run again in 1 heartbeats.
2020-03-30 15:17:26.764 (P1 Slimme meter) P1 Smart Meter (Power)
2020-03-30 15:17:26.769 (P1 Slimme meter) General/Voltage (Voltage L1)
2020-03-30 15:17:26.784 (P1 Slimme meter) Usage (Usage L1)
2020-03-30 15:17:26.789 (P1 Slimme meter) Usage (Delivery L1)
2020-03-30 15:17:26.882 Status: dzVents: Debug: - Device: Delivery L1
2020-03-30 15:17:26.917 Status: LUA: ----- PowerGeneration = 468229 W
2020-03-30 15:17:26.917 Status: LUA: ----- EnergyGeneration = 301617 Wh
2020-03-30 15:17:26.917 Status: LUA: ----- PowerImport = 113 W
2020-03-30 15:17:26.917 Status: LUA: ----- EnergyImportLow = 468229 Wh
2020-03-30 15:17:26.917 Status: LUA: ----- EnergyImportHigh = 301617 Wh
2020-03-30 15:17:26.917 Status: LUA: ----- EnergyImport = 769846.0 Wh
2020-03-30 15:17:26.917 Status: LUA: ----- PowerExport = 0 W
2020-03-30 15:17:26.917 Status: LUA: ----- Ener

Re: Lua version problem domoticz

Posted: Monday 30 March 2020 15:39
by waaren
sjoemie1985 wrote: Monday 30 March 2020 15:18 see images is hope this is enough info :)
Sorry but I don't see the debug loglines from the dzVents script.
The device info is OK.
Is there a specific reason why the P1 meter is updated every second ? If not, it's probably best to change rate limit (on the hardware tab) to 10 seconds.
The current settings does cause all Lua device scripts to be started every second.

Re: Lua version problem domoticz

Posted: Monday 30 March 2020 16:07
by sjoemie1985
waaren wrote: Monday 30 March 2020 15:39
sjoemie1985 wrote: Monday 30 March 2020 15:18 see images is hope this is enough info :)
Sorry but I don't see the debug loglines from the dzVents script.
The device info is OK.
Is there a specific reason why the P1 meter is updated every second ? If not, it's probably best to change rate limit (on the hardware tab) to 10 seconds.
The current settings does cause all Lua device scripts to be started every second.
i changed the setting to 10 seconds.
i have now this in my logging

Code: Select all

2020-03-30 16:06:00.130 (Semsportal) Pushing 'onHeartbeatCallback' on to queue
2020-03-30 16:06:00.170 (Semsportal) Processing 'onHeartbeatCallback' message
2020-03-30 16:06:00.170 (Semsportal) Calling message handler 'onHeartbeat'.
2020-03-30 16:06:00.170 (Semsportal) onHeartbeat called, run again in 10 heartbeats.
2020-03-30 16:06:00.733 (P1 Slimme meter) P1 Smart Meter (Power)
2020-03-30 16:06:00.739 (P1 Slimme meter) General/Voltage (Voltage L1)
2020-03-30 16:06:00.743 (P1 Slimme meter) Usage (Usage L1)
2020-03-30 16:06:00.747 (P1 Slimme meter) Usage (Delivery L1)
2020-03-30 16:06:00.184 Status: dzVents: Debug: Dumping domoticz data to /home/pi/domoticz/scripts/dzVents/domoticzData.lua
2020-03-30 16:06:00.190 Status: dzVents: Debug: Event triggers:
2020-03-30 16:06:00.190 Status: dzVents: Debug: - Timer
2020-03-30 16:06:00.756 Status: dzVents: Debug: Dumping domoticz data to /home/pi/domoticz/scripts/dzVents/domoticzData.lua
2020-03-30 16:06:00.772 Status: dzVents: Debug: Processing device-adapter for Power: P1 smart meter energy device adapter
2020-03-30 16:06:00.772 Status: dzVents: Debug: dzVents version: 3.0.1
2020-03-30 16:06:00.772 Status: dzVents: Debug: Event triggers:
2020-03-30 16:06:00.772 Status: dzVents: Debug: - Device: Power
2020-03-30 16:06:00.808 Status: LUA: ----- PowerGeneration = 468229 W
2020-03-30 16:06:00.808 Status: LUA: ----- EnergyGeneration = 301636 Wh
2020-03-30 16:06:00.808 Status: LUA: ----- PowerImport = 0 W
2020-03-30 16:06:00.808 Status: LUA: ----- EnergyImportLow = 468229 Wh
2020-03-30 16:06:00.808 Status: LUA: ----- EnergyImportHigh = 301636 Wh
2020-03-30 16:06:00.808 Status: LUA: ----- EnergyImport = 769865.0 Wh
2020-03-30 16:06:00.808 Status: LUA: ----- PowerExport = 422 W
2020-03-30 16:06:00.808 Status: LUA: ----- EnergyExportLow = 95006 Wh
2020-03-30 16:06:00.808 Status: LUA: ----- EnergyExportHigh = 244904 Wh
2020-03-30 16:06:00.808 Status: LUA: ----- EnergyExport = 339910.0 Wh
2020-03-30 16:06:00.808 Status: LUA: ----- PowerConsumption = 467807.0 W
2020-03-30 16:06:00.808 Status: LUA: ----- EnergyConsumption = 731591.0 Wh
2020-03-30 16:06:00.814 Status: EventSystem: Script event triggered: /home/pi/domoticz/scripts/lua/script_device_calculate_consumption.lua
2020-03-30 16:06:00.835 Status: dzVents: Debug: Dumping domoticz data to /home/pi/domoticz/scripts/dzVents/domoticzData.lua
2020-03-30 16:06:00.852 Status: dzVents: Debug: Processing device-adapter for Voltage L1: Voltage device adapter
2020-03-30 16:06:00.852 Status: dzVents: Debug: Processing device-adapter for Usage L1: Electric usage device adapter
2020-03-30 16:06:00.853 Status: dzVents: Debug: Processing device-adapter for Delivery L1: Electric usage device adapter
2020-03-30 16:06:00.853 Status: dzVents: Debug: dzVents version: 3.0.1
2020-03-30 16:06:00.853 Status: dzVents: Debug: Event triggers:
2020-03-30 16:06:00.853 Status: dzVents: Debug: - Device: Voltage L1
2020-03-30 16:06:00.853 Status: dzVents: Debug: - Device: Usage L1
2020-03-30 16:06:00.853 Status: dzVents: Debug: - Device: Delivery L1
2020-03-30 16:06:00.889 Status: LUA: ----- PowerGeneration = 468229 W
2020-03-30 16:06:00.889 Status: LUA: ----- EnergyGeneration = 301636 Wh
2020-03-30 16:06:00.889 Status: LUA: ----- PowerImport = 0 W
2020-03-30 16:06:00.889 Status: LUA: ----- EnergyImportLow = 468229 Wh
2020-03-30 16:06:00.889 Status: LUA: ----- EnergyImportHigh = 301636 Wh
2020-03-30 16:06:00.889 Status: LUA: ----- EnergyImport = 769865.0 Wh
2020-03-30 16:06:00.889 Status: LUA: ----- PowerExport = 422 W
2020-03-30 16:06:00.889 Status: LUA: ----- EnergyExportLow = 95006 Wh
2020-03-30 16:06:00.889 Status: LUA: ----- EnergyExportHigh = 244904 Wh
2020-03-30 16:06:00.889 Status: LUA: ----- EnergyExport = 339910.0 Wh
2020-03-30 16:06:00.889 Status: LUA: ----- PowerConsumption = 467807.0 W
2020-03-30 16:06:00.889 Status: LUA: ----- EnergyConsumption = 731591.0 Wh
2020-03-30 16:06:00.892 Status: LUA: ----- PowerGeneration = 468229 W
2020-03-30 16:06:00.892 Status: LUA: ----- EnergyGeneration = 301636 Wh
2020-03-30 16:06:00.892 Status: LUA: ----- PowerImport = 0 W
2020-03-30 16:06:00.892 Status: LUA: ----- EnergyImportLow = 468229 Wh
2020-03-30 16:06:00.892 Status: LUA: ----- EnergyImportHigh = 301636 Wh
2020-03-30 16:06:00.892 Status: LUA: ----- EnergyImport = 769865.0 Wh

Re: Lua version problem domoticz

Posted: Monday 30 March 2020 17:58
by waaren
sjoemie1985 wrote: Monday 30 March 2020 16:07 i have now this in my logging
Don't know how you activated the script I posted but this log does not contain the lines from that script. It looks like you have some other scripts (Lua and dzVents) active

Re: Lua version problem domoticz

Posted: Monday 30 March 2020 21:27
by sjoemie1985
waaren wrote: Monday 30 March 2020 17:58
sjoemie1985 wrote: Monday 30 March 2020 16:07 i have now this in my logging
Don't know how you activated the script I posted but this log does not contain the lines from that script. It looks like you have some other scripts (Lua and dzVents) active
that could be possible i have also this lua script in de lua folder of my pi.

Code: Select all

-- /home/pi/domoticz/scripts/lua/script_device_calculate_consumption.lua
-- This script collects the values below from Domoticz
--   * The Power and energy values (import and export) from a smartmeter 
--   * The Power and energy values from a Solar power inverter
-- It then calculates the consumed power and energy from the values above with the formula's
--   * EnergyConsumption = EnergyGeneration + EnergyImport - EnergyExport
--   * PowerConsumption = PowerGeneration + PowerImport - PowerExport
-- It then updates a virtual device which displays the consumed power and energy in Domoticz

----------------------------------------------------------------------------------------------------------
-- Domoticz IDX and names of the needed devices
----------------------------------------------------------------------------------------------------------
local GenerationDeviceName = "Power" 		-- Device name of the Generated energy
local EnergyDeviceName = "Power" 		-- Name of the energy device that shows imported and exported energy
local ConsumptionIDX = 61  			-- IDX of the energy device that shows calculated Consumption
local ConsumptionDeviceName = "ConsumptionDevice" 		-- Name of the energy device that shows calculated Consumption

----------------------------------------------------------------------------------------------------------
-- Require parameters
----------------------------------------------------------------------------------------------------------

--package.cpath ="/usr/lib/x86_64-linux-gnu/lua/5.2/?.so;" .. package.cpath
--package.path = "/usr/share/lua/5.3/socket/?.lua;" .. package.path
--local http = require("socket.http")

----------------------------------------------------------------------------------------------------------
-- Script parameters
----------------------------------------------------------------------------------------------------------
if (EnergyImportLow==nil) then
EnergyImportLow = 0	-- in Watt hours
EnergyImportHigh = 0	-- in Watt hours
EnergyExportLow = 0	-- in Watt hours
EnergyExportHigh = 0	-- in Watt hours
EnergyGeneration = 0 	-- in Watt hours
PowerGeneration = 0 	-- in Watts
EnergyImport = 0	-- in Watt hours
PowerImport = 0		-- in Watts
EnergyConsumption = 0 	-- in Watt hours
PowerConsumption = 0 	-- in Watts
Debug = "YES" 		-- Turn debugging on ("YES") or off ("NO")

end
----------------------------------------------------------------------------------------------------------
-- Lua Functions
----------------------------------------------------------------------------------------------------------
function update(device, id, power, energy, index)
	commandArray[index] = {['UpdateDevice'] = id .. "|0|" .. power .. ";" .. energy}
end 

----------------------------------------------------------------------------------------------------------
-- CommandArray
----------------------------------------------------------------------------------------------------------
commandArray = {}
	-- Generated
	PowerGeneration, EnergyGeneration = otherdevices_svalues[GenerationDeviceName]:match("([^;]+);([^;]+)")
	if Debug=="YES" then
		print("  ----- PowerGeneration = " .. PowerGeneration .. " W");
		print("  ----- EnergyGeneration = " .. EnergyGeneration .. " Wh");
	end

	EnergyImportLow, EnergyImportHigh, EnergyExportLow, EnergyExportHigh, PowerImport, PowerExport = otherdevices_svalues[EnergyDeviceName]:match("([^;]+);([^;]+);([^;]+);([^;]+);([^;]+);([^;]+)")
	EnergyImport = EnergyImportLow + EnergyImportHigh
	EnergyExport = EnergyExportLow + EnergyExportHigh
	if Debug=="YES" then
		print("  ----- PowerImport = " .. PowerImport .. " W");
		print("  ----- EnergyImportLow = " .. EnergyImportLow .. " Wh");
		print("  ----- EnergyImportHigh = " .. EnergyImportHigh .. " Wh");
		print("  ----- EnergyImport = " .. EnergyImport .. " Wh");
		print("  ----- PowerExport = " .. PowerExport .. " W");
		print("  ----- EnergyExportLow = " .. EnergyExportLow .. " Wh");
		print("  ----- EnergyExportHigh = " .. EnergyExportHigh .. " Wh");
		print("  ----- EnergyExport = " .. EnergyExport .. " Wh");
	end

	-- Calculate consumption
	PowerConsumption = PowerGeneration + PowerImport - PowerExport
	if Debug=="YES" then
		print("  ----- PowerConsumption = " .. PowerConsumption .. " W");
	end
	EnergyConsumption = EnergyGeneration + EnergyImport - EnergyExport
	if Debug=="YES" then
		print("  ----- EnergyConsumption = " .. EnergyConsumption .. " Wh");
	end

	-- Update comsumption device in Domoticz
	if devicechanged[EnergyDeviceName] then
		update(ConsumptionDeviceName, ConsumptionIDX, PowerConsumption, EnergyConsumption, 1)
	end
	
return commandArray

Re: Lua version problem domoticz

Posted: Monday 30 March 2020 22:09
by waaren
sjoemie1985 wrote: Monday 30 March 2020 21:27 That could be possible i have also this lua script in de lua folder of my pi.
To prevent confusion and potential mixup, it would be best if you deactivate these scripts during the test of this dzVents pvOutput script.
That will give you a much cleaner log and simplify collecting the necessary information.

Re: Lua version problem domoticz

Posted: Tuesday 31 March 2020 9:26
by sjoemie1985
waaren wrote: Monday 30 March 2020 22:09
sjoemie1985 wrote: Monday 30 March 2020 21:27 That could be possible i have also this lua script in de lua folder of my pi.
To prevent confusion and potential mixup, it would be best if you deactivate these scripts during the test of this dzVents pvOutput script.
That will give you a much cleaner log and simplify collecting the necessary information.
this is all dzvents log i see.

Code: Select all

2020-03-31 09:25:00.153 Status: dzVents: Debug: Dumping domoticz data to /home/pi/domoticz/scripts/dzVents/domoticzData.lua
2020-03-31 09:25:00.170 Status: dzVents: Debug: Processing device-adapter for Power: P1 smart meter energy device adapter
2020-03-31 09:25:00.170 Status: dzVents: Debug: dzVents version: 3.0.1
2020-03-31 09:25:00.170 Status: dzVents: Debug: Event triggers:
2020-03-31 09:25:00.170 Status: dzVents: Debug: - Device: Power
2020-03-31 09:25:00.225 Status: dzVents: Debug: Dumping domoticz data to /home/pi/domoticz/scripts/dzVents/domoticzData.lua
2020-03-31 09:25:00.242 Status: dzVents: Debug: Processing device-adapter for Voltage L1: Voltage device adapter
2020-03-31 09:25:00.243 Status: dzVents: Debug: Processing device-adapter for Usage L1: Electric usage device adapter
2020-03-31 09:25:00.243 Status: dzVents: Debug: Processing device-adapter for Delivery L1: Electric usage device adapter
2020-03-31 09:25:00.244 Status: dzVents: Debug: Processing device-adapter for Gas: Gas device adapter
2020-03-31 09:25:00.244 Status: dzVents: Debug: dzVents version: 3.0.1
2020-03-31 09:25:00.244 Status: dzVents: Debug: Event triggers:
2020-03-31 09:25:00.244 Status: dzVents: Debug: - Device: Voltage L1
2020-03-31 09:25:00.244 Status: dzVents: Debug: - Device: Usage L1
2020-03-31 09:25:00.244 Status: dzVents: Debug: - Device: Delivery L1
2020-03-31 09:25:00.244 Status: dzVents: Debug: - Device: Gas
2020-03-31 09:25:00.515 Status: dzVents: Debug: Dumping domoticz data to /home/pi/domoticz/scripts/dzVents/domoticzData.lua
2020-03-31 09:25:00.521 Status: dzVents: Debug: Event triggers:
2020-03-31 09:25:00.522 Status: dzVents: Debug: - Timer
2020-03-31 09:25:00.552 Status: dzVents: Info: pvOutput: ------ Start external script: script_Time_Upload_to_PVoutput.lua:, trigger: "every 5 minutes"
2020-03-31 09:25:00.563 Status: dzVents: Debug: pvOutput: Processing device-adapter for Power: P1 smart meter energy device adapter
2020-03-31 09:25:00.564 Status: dzVents: Debug: pvOutput: Processing device-adapter for THB: Temperature+humidity+barometer device adapter
2020-03-31 09:25:00.564 Status: dzVents: Debug: pvOutput: Processing device-adapter for VoltageOutput: Voltage device adapter
2020-03-31 09:25:00.564 Status: dzVents: Debug: pvOutput: P1 : 469572;303283;95006;245153;0;216
2020-03-31 09:25:00.564 Status: dzVents: Debug: pvOutput: Temperature: 0.89999997615814
2020-03-31 09:25:00.564 Status: dzVents: Debug: pvOutput: voltage: 241.8V
2020-03-31 09:25:00.565 Status: dzVents: Info: pvOutput: ------ Finished script_Time_Upload_to_PVoutput.lua
2020-03-31 09:25:10.154 Status: dzVents: Debug: Dumping domoticz data to /home/pi/domoticz/scripts/dzVents/domoticzData.lua
2020-03-31 09:25:10.170 Status: dzVents: Debug: Processing device-adapter for Power: P1 smart meter energy device adapter
2020-03-31 09:25:10.171 Status: dzVents: Debug: dzVents version: 3.0.1
2020-03-31 09:25:10.171 Status: dzVents: Debug: Event triggers:
2020-03-31 09:25:10.171 Status: dzVents: Debug: - Device: Power
2020-03-31 09:25:10.225 Status: dzVents: Debug: Dumping domoticz data to /home/pi/domoticz/scripts/dzVents/domoticzData.lua
2020-03-31 09:25:10.241 Status: dzVents: Debug: Processing device-adapter for Voltage L1: Voltage device adapter
2020-03-31 09:25:10.242 Status: dzVents: Debug: Processing device-adapter for Usage L1: Electric usage device adapter
2020-03-31 09:25:10.242 Status: dzVents: Debug: Processing device-adapter for Delivery L1: Electric usage device adapter
2020-03-31 09:25:10.242 Status: dzVents: Debug: dzVents version: 3.0.1
2020-03-31 09:25:10.243 Status: dzVents: Debug: Event triggers:
2020-03-31 09:25:10.243 Status: dzVents: Debug: - Device: Voltage L1
2020-03-31 09:25:10.243 Status: dzVents: Debug: - Device: Usage L1
2020-03-31 09:25:10.243 Status: dzVents: Debug: - Device: Delivery L1
2020-03-31 09:25:20.153 Status: dzVents: Debug: Dumping domoticz data to /home/pi/domoticz/scripts/dzVents/domoticzData.lua
2020-03-31 09:25:20.169 Status: dzVents: Debug: Processing device-adapter for Power: P1 smart meter energy device adapter
2020-03-31 09:25:20.169 Status: dzVents: Debug: dzVents version: 3.0.1
2020-03-31 09:25:20.169 Status: dzVents: Debug: Event triggers:
2020-03-31 09:25:20.169 Status: dzVents: Debug: - Device: Power
2020-03-31 09:25:20.224 Status: dzVents: Debug: Dumping domoticz data to /home/pi/domoticz/scripts/dzVents/domoticzData.lua
2020-03-31 09:25:20.241 Status: dzVents: Debug: Processing device-adapter for Voltage L1: Voltage device adapter
2020-03-31 09:25:20.242 Status: dzVents: Debug: Processing device-adapter for Usage L1: Electric usage device adapter
2020-03-31 09:25:20.242 Status: dzVents: Debug: Processing device-adapter for Delivery L1: Electric usage device adapter
2020-03-31 09:25:20.242 Status: dzVents: Debug: dzVents version: 3.0.1
2020-03-31 09:25:20.242 Status: dzVents: Debug: Event triggers:
2020-03-31 09:25:20.243 Status: dzVents: Debug: - Device: Voltage L1
2020-03-31 09:25:20.243 Status: dzVents: Debug: - Device: Usage L1
2020-03-31 09:25:20.243 Status: dzVents: Debug: - Device: Delivery L1
2020-03-31 09:25:30.156 Status: dzVents: Debug: Dumping domoticz data to /home/pi/domoticz/scripts/dzVents/domoticzData.lua
2020-03-31 09:25:30.172 Status: dzVents: Debug: Processing device-adapter for Power: P1 smart meter energy device adapter
2020-03-31 09:25:30.172 Status: dzVents: Debug: dzVents version: 3.0.1
2020-03-31 09:25:30.172 Status: dzVents: Debug: Event triggers:
2020-03-31 09:25:30.172 Status: dzVents: Debug: - Device: Power
2020-03-31 09:25:30.229 Status: dzVents: Debug: Dumping domoticz data to /home/pi/domoticz/scripts/dzVents/domoticzData.lua
2020-03-31 09:25:30.245 Status: dzVents: Debug: Processing device-adapter for Voltage L1: Voltage device adapter
2020-03-31 09:25:30.246 Status: dzVents: Debug: Processing device-adapter for Usage L1: Electric usage device adapter
2020-03-31 09:25:30.247 Status: dzVents: Debug: Processing device-adapter for Delivery L1: Electric usage device adapter
2020-03-31 09:25:30.247 Status: dzVents: Debug: dzVents version: 3.0.1
2020-03-31 09:25:30.247 Status: dzVents: Debug: Event triggers:
2020-03-31 09:25:30.247 Status: dzVents: Debug: - Device: Voltage L1
2020-03-31 09:25:30.247 Status: dzVents: Debug: - Device: Usage L1
2020-03-31 09:25:30.247 Status: dzVents: Debug: - Device: Delivery L1
2020-03-31 09:25:40.154 Status: dzVents: Debug: Dumping domoticz data to /home/pi/domoticz/scripts/dzVents/domoticzData.lua
2020-03-31 09:25:40.170 Status: dzVents: Debug: Processing device-adapter for Power: P1 smart meter energy device adapter
2020-03-31 09:25:40.170 Status: dzVents: Debug: dzVents version: 3.0.1
2020-03-31 09:25:40.170 Status: dzVents: Debug: Event triggers:
2020-03-31 09:25:40.170 Status: dzVents: Debug: - Device: Power
2020-03-31 09:25:40.226 Status: dzVents: Debug: Dumping domoticz data to /home/pi/domoticz/scripts/dzVents/domoticzData.lua
2020-03-31 09:25:40.243 Status: dzVents: Debug: Processing device-adapter for Voltage L1: Voltage device adapter
2020-03-31 09:25:40.244 Status: dzVents: Debug: Processing device-adapter for Usage L1: Electric usage device adapter
2020-03-31 09:25:40.245 Status: dzVents: Debug: Processing device-adapter for Delivery L1: Electric usage device adapter
2020-03-31 09:25:40.245 Status: dzVents: Debug: dzVents version: 3.0.1
2020-03-31 09:25:40.245 Status: dzVents: Debug: Event triggers:
2020-03-31 09:25:40.245 Status: dzVents: Debug: - Device: Voltage L1
2020-03-31 09:25:40.245 Status: dzVents: Debug: - Device: Usage L1
2020-03-31 09:25:40.245 Status: dzVents: Debug: - Device: Delivery L1
2020-03-31 09:25:50.154 Status: dzVents: Debug: Dumping domoticz data to /home/pi/domoticz/scripts/dzVents/domoticzData.lua
2020-03-31 09:25:50.171 Status: dzVents: Debug: Processing device-adapter for Power: P1 smart meter energy device adapter
2020-03-31 09:25:50.171 Status: dzVents: Debug: dzVents version: 3.0.1
2020-03-31 09:25:50.171 Status: dzVents: Debug: Event triggers:
2020-03-31 09:25:50.171 Status: dzVents: Debug: - Device: Power
2020-03-31 09:25:50.226 Status: dzVents: Debug: Dumping domoticz data to /home/pi/domoticz/scripts/dzVents/domoticzData.lua
2020-03-31 09:25:50.243 Status: dzVents: Debug: Processing device-adapter for Voltage L1: Voltage device adapter
2020-03-31 09:25:50.244 Status: dzVents: Debug: Processing device-adapter for Usage L1: Electric usage device adapter
2020-03-31 09:25:50.244 Status: dzVents: Debug: Processing device-adapter for Delivery L1: Electric usage device adapter
2020-03-31 09:25:50.244 Status: dzVents: Debug: dzVents version: 3.0.1
2020-03-31 09:25:50.244 Status: dzVents: Debug: Event triggers:
2020-03-31 09:25:50.244 Status: dzVents: Debug: - Device: Voltage L1
2020-03-31 09:25:50.244 Status: dzVents: Debug: - Device: Usage L1
2020-03-31 09:25:50.244 Status: dzVents: Debug: - Device: Delivery 

Re: Lua version problem domoticz

Posted: Tuesday 31 March 2020 10:11
by waaren
sjoemie1985 wrote: Tuesday 31 March 2020 9:26 this is all dzvents log i see.

Code: Select all

2020-03-31 09:25:00.552 Status: dzVents: Info: pvOutput: ------ Start external script: script_Time_Upload_to_PVoutput.lua:, trigger: "every 5 minutes"
2020-03-31 09:25:00.564 Status: dzVents: Debug: pvOutput: P1 : 469572;303283;95006;245153;0;216
2020-03-31 09:25:00.564 Status: dzVents: Debug: pvOutput: Temperature: 0.89999997615814
2020-03-31 09:25:00.564 Status: dzVents: Debug: pvOutput: voltage: 241.8V
2020-03-31 09:25:00.565 Status: dzVents: Info: pvOutput: ------ Finished script_Time_Upload_to_PVoutput.lua
I was indeed looking for this output. What I see is that the Voltage value shows 241.8V and dzVents and pvOutput expect only numbers.

Below script should take care of that.

Code: Select all

--[[
        dzVents version of pvOutput script.
        api-key and id stored in domoticz uservariables type string
]]

local scriptVar = 'PVOutput'

return {
            on =    { 
                        timer = { 'every 5 minutes'},
                        httpResponses = { scriptVar },
                    },
 
       logging =    {   
                        level   =   domoticz.LOG_DEBUG, -- change to error when OK
                        marker  =   "pvOutput" 
                    },    

    execute = function(dz, item)
            
        local function post2PVOutput(PVSettings, postData)
            -- dz.utils.dumpTable(PVSettings, 'PVSettings > ')
            -- dz.log('postData: ' .. postData,dz.LOG_FORCE)
            dz.openURL({
                url = PVSettings.url,
                method = 'POST',
                headers = {
                    ['X-Pvoutput-Apikey'] = PVSettings.api,
                    ['X-Pvoutput-SystemId'] = PVSettings.id
                },
                callback = scriptVar,
                postData = postData
            })
        end
        
        local function makepostData()
            local P1 = dz.devices('Power') 
            local temperature = dz.devices('THB')
            local voltageString = dz.devices('VoltageOutput').sValue
            local round = dz.utils.round
            
            dz.log('P1         : ' .. P1.sValue,dz.LOG_DEBUG)
            dz.log('Temperature: ' .. temperature.temperature,dz.LOG_DEBUG)
            dz.log('voltage: ' .. voltage.sValue,dz.LOG_DEBUG)
            
            local voltage = round(tonumber(voltageString:match('%d*%.*%d*')))
            
            local postdDataAsString = 
            'd=' .. os.date("%Y%m%d") ..
            '&t=' .. os.date("%H:%M") .. 
            '&v1=' .. P1.return1 + P1.return2 ..
            '&v2=' .. P1.usageDelivered ..
            '&v3=' .. P1.usage1 + P1.usage2 ..
            '&v4=' .. P1.usage ..
            '&v5=' .. round(tonumber(temperature.temperature),1) .. 
            '&v6=' .. voltage ..
            
            '&c1=1'
            
            --[[ 
                v1 - energy generation
                v2 - power generation            W from 
                v3 - energy consumption
                v4 - power consumption
                v5 - temperature
                v6 - voltage
            '&c1= ..  c1
            '&n= .. n
                                            Donation mode only parms
            '&delay=' .. Delay
            '&v7=' .. WaterConsumption
            '&v8=' .. InverterFrequency
            '&v11=' .. InverterTemp
            '&v12=' .. GasConsumption
            ]] -- 
           
            return postdDataAsString
        end

        if item.isHTTPResponse then
            dz.log("Return from PVOutput ==>> " .. item.data,dz.LOG_FORCE)
        else
            
            PVSettings = 
            {
            url = 'HTTPS://pvoutput.org/service/r2/addstatus.jsp',
            api = dz.variables('PVoutput_API').value,
            id  = dz.variables('PVoutput_ID').value,
            }
            
            post2PVOutput(PVSettings, makepostData())
        end
    end
}
    

Re: Lua version problem domoticz

Posted: Tuesday 31 March 2020 10:36
by sjoemie1985
waaren wrote: Tuesday 31 March 2020 10:11
sjoemie1985 wrote: Tuesday 31 March 2020 9:26 this is all dzvents log i see.

Code: Select all

2020-03-31 09:25:00.552 Status: dzVents: Info: pvOutput: ------ Start external script: script_Time_Upload_to_PVoutput.lua:, trigger: "every 5 minutes"
2020-03-31 09:25:00.564 Status: dzVents: Debug: pvOutput: P1 : 469572;303283;95006;245153;0;216
2020-03-31 09:25:00.564 Status: dzVents: Debug: pvOutput: Temperature: 0.89999997615814
2020-03-31 09:25:00.564 Status: dzVents: Debug: pvOutput: voltage: 241.8V
2020-03-31 09:25:00.565 Status: dzVents: Info: pvOutput: ------ Finished script_Time_Upload_to_PVoutput.lua
I was indeed looking for this output. What I see is that the Voltage value shows 241.8V and dzVents and pvOutput expect only numbers.

Below script should take care of that.

Code: Select all

--[[
        dzVents version of pvOutput script.
        api-key and id stored in domoticz uservariables type string
]]

local scriptVar = 'PVOutput'

return {
            on =    { 
                        timer = { 'every 5 minutes'},
                        httpResponses = { scriptVar },
                    },
 
       logging =    {   
                        level   =   domoticz.LOG_DEBUG, -- change to error when OK
                        marker  =   "pvOutput" 
                    },    

    execute = function(dz, item)
            
        local function post2PVOutput(PVSettings, postData)
            -- dz.utils.dumpTable(PVSettings, 'PVSettings > ')
            -- dz.log('postData: ' .. postData,dz.LOG_FORCE)
            dz.openURL({
                url = PVSettings.url,
                method = 'POST',
                headers = {
                    ['X-Pvoutput-Apikey'] = PVSettings.api,
                    ['X-Pvoutput-SystemId'] = PVSettings.id
                },
                callback = scriptVar,
                postData = postData
            })
        end
        
        local function makepostData()
            local P1 = dz.devices('Power') 
            local temperature = dz.devices('THB')
            local voltageString = dz.devices('VoltageOutput').sValue
            local round = dz.utils.round
            
            dz.log('P1         : ' .. P1.sValue,dz.LOG_DEBUG)
            dz.log('Temperature: ' .. temperature.temperature,dz.LOG_DEBUG)
            dz.log('voltage: ' .. voltage.sValue,dz.LOG_DEBUG)
            
            local voltage = round(tonumber(voltageString:match('%d*%.*%d*')))
            
            local postdDataAsString = 
            'd=' .. os.date("%Y%m%d") ..
            '&t=' .. os.date("%H:%M") .. 
            '&v1=' .. P1.return1 + P1.return2 ..
            '&v2=' .. P1.usageDelivered ..
            '&v3=' .. P1.usage1 + P1.usage2 ..
            '&v4=' .. P1.usage ..
            '&v5=' .. round(tonumber(temperature.temperature),1) .. 
            '&v6=' .. voltage ..
            
            '&c1=1'
            
            --[[ 
                v1 - energy generation
                v2 - power generation            W from 
                v3 - energy consumption
                v4 - power consumption
                v5 - temperature
                v6 - voltage
            '&c1= ..  c1
            '&n= .. n
                                            Donation mode only parms
            '&delay=' .. Delay
            '&v7=' .. WaterConsumption
            '&v8=' .. InverterFrequency
            '&v11=' .. InverterTemp
            '&v12=' .. GasConsumption
            ]] -- 
           
            return postdDataAsString
        end

        if item.isHTTPResponse then
            dz.log("Return from PVOutput ==>> " .. item.data,dz.LOG_FORCE)
        else
            
            PVSettings = 
            {
            url = 'HTTPS://pvoutput.org/service/r2/addstatus.jsp',
            api = dz.variables('PVoutput_API').value,
            id  = dz.variables('PVoutput_ID').value,
            }
            
            post2PVOutput(PVSettings, makepostData())
        end
    end
}
    
now i got this error on domoticz.
other question does this script also upload the energy used and power used to pvoutput.org?

Code: Select all

2020-03-31 10:34:00.221 Error: dzVents: Error: (3.0.1) pvOutput: An error occurred when calling event handler script_Time_Upload_to_PVoutput
2020-03-31 10:34:00.221 Error: dzVents: Error: (3.0.1) pvOutput: ...ripts/dzVents/scripts/script_Time_Upload_to_PVoutput.lua:44: attempt to index a nil value (global 'VoltageOutput')
also some logging:

Code: Select all

2020-03-31 11:20:00.077 Status: dzVents: Debug: pvOutput: Processing device-adapter for Power: P1 smart meter energy device adapter
2020-03-31 11:20:00.078 Status: dzVents: Debug: pvOutput: Processing device-adapter for THB: Temperature+humidity+barometer device adapter
2020-03-31 11:20:00.078 Status: dzVents: Debug: pvOutput: Processing device-adapter for VoltageOutput: Voltage device adapter
2020-03-31 11:20:00.078 Status: dzVents: Debug: pvOutput: P1 : 469572;303283;95006;246175;0;870
2020-03-31 11:20:00.078 Status: dzVents: Debug: pvOutput: Temperature: 5.3000001907349
2020-03-31 11:20:00.079 Status: dzVents: Info: pvOutput: ------ Finished script_Time_Upload_to_PVoutput.lua
2020-03-31 11:20:00.103 Status: dzVents: Debug: Dumping domoticz data to /home/pi/domoticz/scripts/dzVents/domoticzData.lua
2020-03-31 11:20:00.120 Status: dzVents: Debug: Processing device-adapter for Power: P1 smart meter energy device adapter
2020-03-31 11:20:00.120 Status: dzVents: Debug: Processing device-adapter for Voltage L1: Voltage device adapter
2020-03-31 11:20:00.121 Status: dzVents: Debug: Processing device-adapter for Usage L1: Electric usage device adapter
2020-03-31 11:20:00.121 Status: dzVents: Debug: Processing device-adapter for Delivery L1: Electric usage device adapter
2020-03-31 11:20:00.122 Status: dzVents: Debug: Processing device-adapter for Gas: Gas device adapter
2020-03-31 11:20:00.122 Status: dzVents: Debug: dzVents version: 3.0.1
2020-03-31 11:20:00.122 Status: dzVents: Debug: Event triggers:
2020-03-31 11:20:00.122 Status: dzVents: Debug: - Device: Power
2020-03-31 11:20:00.122 Status: dzVents: Debug: - Device: Voltage L1
2020-03-31 11:20:00.122 Status: dzVents: Debug: - Device: Usage L1
2020-03-31 11:20:00.122 Status: dzVents: Debug: - Device: Delivery L1
2020-03-31 11:20:00.122 Status: dzVents: Debug: - Device: Gas
2020-03-31 11:20:00.079 Error: dzVents: Error: (3.0.1) pvOutput: An error occurred when calling event handler script_Time_Upload_to_PVoutput
2020-03-31 11:20:00.079 Error: dzVents: Error: (3.0.1) pvOutput: ...ripts/dzVents/scripts/script_Time_Upload_to_PVoutput.lua:44: attempt to index a nil value (global 'Voltage')

Re: Lua version problem domoticz

Posted: Tuesday 31 March 2020 14:28
by waaren
sjoemie1985 wrote: Tuesday 31 March 2020 10:36 now i got this error on domoticz.

Code: Select all

2020-03-31 10:34:00.221 Error: dzVents: Error: (3.0.1) pvOutput: An error occurred when calling event handler script_Time_Upload_to_PVoutput
2020-03-31 10:34:00.221 Error: dzVents: Error: (3.0.1) pvOutput: ...ripts/dzVents/scripts/script_Time_Upload_to_PVoutput.lua:44: attempt to index a nil value (global 'VoltageOutput')
Just remove line 44. It was there for debugging which is no longer needed.
other question does this script also upload the energy used and power used to pvoutput.org?
Yes. That is the whole idea of the script. Please read the comments (line 60 - 75)

Re: Lua version problem domoticz

Posted: Tuesday 31 March 2020 15:43
by sjoemie1985
waaren wrote: Tuesday 31 March 2020 14:28
sjoemie1985 wrote: Tuesday 31 March 2020 10:36 now i got this error on domoticz.

Code: Select all

2020-03-31 10:34:00.221 Error: dzVents: Error: (3.0.1) pvOutput: An error occurred when calling event handler script_Time_Upload_to_PVoutput
2020-03-31 10:34:00.221 Error: dzVents: Error: (3.0.1) pvOutput: ...ripts/dzVents/scripts/script_Time_Upload_to_PVoutput.lua:44: attempt to index a nil value (global 'VoltageOutput')
Just remove line 44. It was there for debugging which is no longer needed.
other question does this script also upload the energy used and power used to pvoutput.org?
Yes. That is the whole idea of the script. Please read the comments (line 60 - 75)
after removing/ locking out that row the script started working the right way i now see the data on the pvoutput page.

many many thanks :) 8-) :D