PV output
Posted: Monday 18 September 2023 20:17
I install a kWH meter SDM120 for my solarpanels. During nigt time there is a small consumption on the meter a negative value.
The script I use has no solution for negative value. That means that uploading to PV output during night time is not accepted due negative value.
I trie to change the script but I didn't find a solution .
The changes I added are marked red.
Can someone give a solution.
local scriptVar = 'PVOutput'
return {
on = {
timer = { 'every 5 minutes'},
httpResponses = { scriptVar },
},
logging = {
level = domoticz.LOG_INFO,
marker = "pvOutput"
},
execute = function(dz, item)
local function post2PVOutput(PVSettings, postData)
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('Electriciteit')
--local Youless = dz.devices('Youless')
----------------------------------------------------------------------------------------------------------
-- Domoticz IDX of the needed devices)
----------------------------------------------------------------------------------------------------------
local Solar = dz.devices(258) -- IDX of Solar Panels
local Consumption = dz.devices(763) -- IDX of Consumption device (from consumption.lua script)
--local Gas = dz.devices(2) -- IDX of Smart Gas Meter
local temperature = dz.devices(896) -- change to your outside temp device
local voltage = dz.devices (310) -- change to a device with a voltage value
dz.log('-- Energy generation (v1) = ' .. Solar.WhTotal .. ' Wh ', dz.LOG_INFO)
if localSolar < 0 then
dz.log('(NEGATIVE-- Power generation (v2) = ' .. Solar.actualWatt .. ' W ', dz.LOG_INFO)
dz.log('Power generation set to 0', dz.LOG_INFO)
localSolar = 0
else
dz.log('-- Power generation (v2) = ' .. Solar.actualWatt .. ' W ', dz.LOG_INFO)
end
-- dz.log('-- Power generation (v2) = ' .. Solar.actualWatt .. ' W ', dz.LOG_INFO)
dz.log('-- Energy consumption (v3) = ' .. Consumption.WhTotal .. ' Wh ', dz.LOG_INFO)
dz.log('-- Power consumption (v4) = ' .. Consumption.actualWatt .. ' W ', dz.LOG_INFO)
local round = dz.utils.round
local postdDataAsString =
--[[
v1 - energy generation
v2 - power generationn
v3 - energy consumption
v4 - power consumption
v5 - temperature
v6 - voltage
]] --
'd=' .. os.date("%Y%m%d") ..
'&t=' .. os.date("%H:%M") ..
'&v1=' .. Solar.WhTotal ..
'&v2=' .. Solar.actualWatt ..
-- '&v2=' .. 0 ..
'&v3=' .. Consumption.WhTotal ..
'&v4=' .. Consumption.actualWatt ..
'&v5=' .. round(temperature.temperature,1) ..
'&v6=' .. dz.utils.round(voltage.voltage,1) ..
'&c1=1'
return postdDataAsString
end
if item.isHTTPResponse then
dz.log("Return from PVOutput \n" .. item.data,dz.LOG_DEBUG)
else
----------------------------------------------------------------------------------------------------------
-- Settings for pvoutput.org
----------------------------------------------------------------------------------------------------------
post2PVOutput(PVSettings, makepostData())
end
end
}
The script I use has no solution for negative value. That means that uploading to PV output during night time is not accepted due negative value.
I trie to change the script but I didn't find a solution .
The changes I added are marked red.
Can someone give a solution.
local scriptVar = 'PVOutput'
return {
on = {
timer = { 'every 5 minutes'},
httpResponses = { scriptVar },
},
logging = {
level = domoticz.LOG_INFO,
marker = "pvOutput"
},
execute = function(dz, item)
local function post2PVOutput(PVSettings, postData)
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('Electriciteit')
--local Youless = dz.devices('Youless')
----------------------------------------------------------------------------------------------------------
-- Domoticz IDX of the needed devices)
----------------------------------------------------------------------------------------------------------
local Solar = dz.devices(258) -- IDX of Solar Panels
local Consumption = dz.devices(763) -- IDX of Consumption device (from consumption.lua script)
--local Gas = dz.devices(2) -- IDX of Smart Gas Meter
local temperature = dz.devices(896) -- change to your outside temp device
local voltage = dz.devices (310) -- change to a device with a voltage value
dz.log('-- Energy generation (v1) = ' .. Solar.WhTotal .. ' Wh ', dz.LOG_INFO)
if localSolar < 0 then
dz.log('(NEGATIVE-- Power generation (v2) = ' .. Solar.actualWatt .. ' W ', dz.LOG_INFO)
dz.log('Power generation set to 0', dz.LOG_INFO)
localSolar = 0
else
dz.log('-- Power generation (v2) = ' .. Solar.actualWatt .. ' W ', dz.LOG_INFO)
end
-- dz.log('-- Power generation (v2) = ' .. Solar.actualWatt .. ' W ', dz.LOG_INFO)
dz.log('-- Energy consumption (v3) = ' .. Consumption.WhTotal .. ' Wh ', dz.LOG_INFO)
dz.log('-- Power consumption (v4) = ' .. Consumption.actualWatt .. ' W ', dz.LOG_INFO)
local round = dz.utils.round
local postdDataAsString =
--[[
v1 - energy generation
v2 - power generationn
v3 - energy consumption
v4 - power consumption
v5 - temperature
v6 - voltage
]] --
'd=' .. os.date("%Y%m%d") ..
'&t=' .. os.date("%H:%M") ..
'&v1=' .. Solar.WhTotal ..
'&v2=' .. Solar.actualWatt ..
-- '&v2=' .. 0 ..
'&v3=' .. Consumption.WhTotal ..
'&v4=' .. Consumption.actualWatt ..
'&v5=' .. round(temperature.temperature,1) ..
'&v6=' .. dz.utils.round(voltage.voltage,1) ..
'&c1=1'
return postdDataAsString
end
if item.isHTTPResponse then
dz.log("Return from PVOutput \n" .. item.data,dz.LOG_DEBUG)
else
----------------------------------------------------------------------------------------------------------
-- Settings for pvoutput.org
----------------------------------------------------------------------------------------------------------
post2PVOutput(PVSettings, makepostData())
end
end
}