Code: Select all
return {
active = true,
on = {
devices = { 'Water', 'Garden' }
},
logging = {
level = domoticz.LOG_DEBUG,
marker = "Water Counter Script"
},
execute = function(domoticz, device)
local count1 = domoticz.devices('Water').counter
local count2 = domoticz.devices('Garden').counter
local resultCounter = domoticz.devices('test')
local dailyCount1 = domoticz.devices('Water').counterToday
local dailyCount2 = domoticz.devices('Garden').counterToday
domoticz.log('Water: ' .. tostring(count1), domoticz.LOG_DEBUG)
domoticz.log('Garden: ' .. tostring(count2), domoticz.LOG_DEBUG)
domoticz.log('Daily Water: ' .. tostring(dailyCount1), domoticz.LOG_DEBUG)
domoticz.log('Daily Garden: ' .. tostring(dailyCount2), domoticz.LOG_DEBUG)
if count1 ~= nil and count2 ~= nil then
local totalDifference = count1 - count2
local dailyDifference = dailyCount1 - dailyCount2
domoticz.log('Total difference: ' .. tostring(totalDifference), domoticz.LOG_DEBUG)
domoticz.log('Daily difference: ' .. tostring(dailyDifference), domoticz.LOG_DEBUG)
resultCounter.updateCounter(totalDifference)
else
domoticz.log('One device has nil value', domoticz.LOG_ERROR)
end
end
}