I have a script running to check for dead devices.
Now i have created a dummy text device and I want to update the value of the text device to all me dead devices
The text device is called "deaddevices"
This is the code I have
Code: Select all
return {
active = true,
on = {
timer = {
'every 2 minutes'
--'at 22:00'
}
},
execute = function(domoticz, _)
local message=""
local message2=""
domoticz.devices().forEach(function(device)
if (device.description ~= nil) then
_, _, threshold = string.find(device.description,"CDA:(%d+)")
if (threshold ~= nil) then
local name = device.name
local minutes = domoticz.devices(name).lastUpdate.minutesAgo
local hours= minutes/60
local days= hours/24
local rounded= (string.format("%2.1f", days))
if ( minutes > tonumber(threshold)) then
message = message .. 'Device ' ..
name .. ' blijkt niet meer te reageren. Geen heartbeat gezien sinds ' ..
rounded .. ' dagen.\r'
message2 = message2 ..
name .. '\r'
end
end
end
end)
if (message ~= "") then
--domoticz.notify('Dead devices', message, domoticz.PRIORITY_HIGH)
domoticz.log('Dead devices found: ' .. message, domoticz.LOG_ERROR)
domoticz.devices(deaddevices).updateText('message2')
--domoticz.notify('Dead devices', message2, domoticz.PRIORITY_HIGH)
end
end
}
Code: Select all
2019-03-02 15:32:00.544 Status: dzVents: Info: ------ Start internal script: check dead device timer:, trigger: every 2 minutes
2019-03-02 15:32:00.853 Status: dzVents: Error (2.4.6): Dead devices found: Device $Badkamer raam contact blijkt niet meer te reageren. Geen heartbeat gezien sinds 30.9 dagen.
Device $Mama groot contact blijkt niet meer te reageren. Geen heartbeat gezien sinds 31.7 dagen.
2019-03-02 15:32:00.853 Status: dzVents: Error (2.4.6): An error occured when calling event handler check dead device timer
2019-03-02 15:32:00.853 Status: dzVents: Error (2.4.6): ...ts/dzVents/generated_scripts/check dead device timer.lua:38: attempt to call field 'updateText' (a nil value)
2019-03-02 15:32:00.853 Status: dzVents: Info: ------ Finished check dead device timer
Kind regards
Koen