Page 1 of 1

Need some help to update text device

Posted: Saturday 02 March 2019 15:35
by Lebo2d9
Hi,

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
}
I always get the following error

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
Can someone help me with the "attempt to call field 'updateText'(a nil value)?

Kind regards

Koen

Re: Need some help to update text device

Posted: Saturday 02 March 2019 17:29
by waaren
Lebo2d9 wrote: Saturday 02 March 2019 15:35 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"
You mixed up the quotes. Change line

Code: Select all

  domoticz.devices(deaddevices).updateText('message2')
to

Code: Select all

  domoticz.devices('deaddevices').updateText(message2)

Re: Need some help to update text device

Posted: Saturday 02 March 2019 18:28
by Lebo2d9
Thx Waaren,

Now it is working.