Page 1 of 1

afterMin() problem

Posted: Saturday 30 March 2019 22:59
by pgielen
I'm having problems using the afterMin function in dzvents. For some reason, the following does not work:

dz.notify('Washingmachine', 'The laundry is done', PRIORITY_LOW, dz.NSS_PUSHOVER).afterMin(15)

The notification is sent immediately and the log file says: 'attempt to index a nil value'. What could be the problem?

Re: afterMin() problem

Posted: Sunday 31 March 2019 0:35
by felix63
According to the DzVents documentation notify doesn't support the afterMin option.
Spoiler: show
notify(subject, message, priority, sound, extra, subsystem): Function. Send a notification (like Prowl). Priority can be like domoticz.PRIORITY_LOW, PRIORITY_MODERATE, PRIORITY_NORMAL, PRIORITY_HIGH, PRIORITY_EMERGENCY. For sound see the SOUND constants below. subsystem can be a table containing one or more notification subsystems. See domoticz.NSS_xxx types.

Re: afterMin() problem

Posted: Sunday 31 March 2019 19:26
by waaren
pgielen wrote: Saturday 30 March 2019 22:59 I'm having problems using the afterMin function in dzvents. For some reason, the following does not work:

dz.notify('Washingmachine', 'The laundry is done', PRIORITY_LOW, dz.NSS_PUSHOVER).afterMin(15)

The notification is sent immediately and the log file says: 'attempt to index a nil value'. What could be the problem?
domoticz does not natively support delayed notifications. Please see attached for a workaround.

Code: Select all

--
-- Is the laundry ready?
--
 local webResponse = 'delayedNotificationForWashingMachineReady'
 
 return  {   on =    {  
                        devices    = { 'Floodsensor trillingen' },
                        httpResponses = { webResponse },
                    },

    data = { vibrationStateUpdates = { history = true, maxMinutes = 5 } },

    execute = function(dz, item)
    
        local function delayedNotification(delay)
            url = dz.settings['Domoticz url'] .. '/json.htm?type=command&param=addlogmessage&message=' .. webResponse
            dz.openURL({
                                url = url,
                                method = 'GET',
                                callback = webResponse
                        }).afterMin(delay)
        end
        
        if item.isHTTPResponse then 
            dz.notify('Washingmachine', 'The laundry is done', PRIORITY_LOW,nil,nil, dz.NSS_PUSHOVER) -- syntax is notify(subject, message, priority, sound, extra, subsystem)
        else
            dz.data.vibrationStateUpdates.add(item.state)
            local vibcnt = dz.data.vibrationStateUpdates.size
            print('Status changes in the last 5 minutes: '.. vibcnt)
            if (vibcnt > 15) then
                print('Spin drying') 
                delayedNotification(15)
                dz.data.vibrationStateUpdates.reset() -- remove entries in persistent history
            end
        end
   end
}

Re: afterMin() problem

Posted: Wednesday 03 April 2019 10:28
by pgielen
Thanks, I'll try this.