I am busy with a Solar used energy script. Script is doing correctly its job but I am still struggling with updating a Virtual Sensor (Electric Instant and Counter)
Below is my script :
Code: Select all
return {
on = {
timer = {
'at 23:50'
}
},
logging = {
level = domoticz.LOG_INFO,
marker = 'CounterReader'
},
execute = function(domoticz, timer)
local P1 = domoticz.devices(1)
local GoodWe = domoticz.devices(50)
local dailyUsage = domoticz.devices(62)
if not P1 then
domoticz.log('Device with IDX 1 not found!', domoticz.LOG_ERROR)
return
elseif not GoodWe then
domoticz.log('Device with IDX 50 not found!', domoticz.LOG_ERROR)
return
elseif not dailyUsage then
domoticz.log('Dummy device IDX 62 not found!', domoticz.LOG_ERROR)
return
end
local deliveryToday = P1.counterDeliveredToday
local generatedToday = GoodWe.counterToday
local resultToday = math.max(0, generatedToday - deliveryToday)
dailyUsage.updateElectricity(0, resultToday * 1000)
domoticz.log('CounterDeliveredToday IDX 1: ' .. tostring(deliveryToday) .. ' kWh', domoticz.LOG_INFO)
domoticz.log('CounterToday IDX 50: ' .. tostring(generatedToday) .. ' kWh', domoticz.LOG_INFO)
domoticz.log('Result: ' .. tostring(resultToday) .. ' kWh', domoticz.LOG_INFO)
end
}
The first bar is from monday 9.946 kWh second graph from yesterday should be 7.711 kWh but it shows like a negative 2.235 kWh. Looks like it does 7.711 - 9.946 then you will get - 2.235.
If I look at the counter at the top of the graphs I see the the total of yesterday :

What am I doing wrong?