Need some help to update text device

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Post Reply
Lebo2d9
Posts: 139
Joined: Tuesday 06 September 2016 20:39
Target OS: Raspberry Pi / ODroid
Domoticz version: L stab
Location: Belgium
Contact:

Need some help to update text device

Post 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
Domoicz on RPI3 (wifi) directly connected 3x ds18b20 for CV temp, Evohome (9 zone), 1 remote 220V switch based on ESP-12. RFXtrx433E, 16x AMST-606, 5 Somfy RTS motors
Domoticz on RPI3(wifi) as slave for terraruim control
More to come
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Need some help to update text device

Post 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)
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Lebo2d9
Posts: 139
Joined: Tuesday 06 September 2016 20:39
Target OS: Raspberry Pi / ODroid
Domoticz version: L stab
Location: Belgium
Contact:

Re: Need some help to update text device

Post by Lebo2d9 »

Thx Waaren,

Now it is working.
Domoicz on RPI3 (wifi) directly connected 3x ds18b20 for CV temp, Evohome (9 zone), 1 remote 220V switch based on ESP-12. RFXtrx433E, 16x AMST-606, 5 Somfy RTS motors
Domoticz on RPI3(wifi) as slave for terraruim control
More to come
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 1 guest