Page 1 of 1

What is wrong

Posted: Thursday 22 November 2018 15:11
by havnegata
Someone has an idea of why this is not working?

Code: Select all

     return {
        on = {
            devices = {
                ['Bad2etg'] = {'at 06:00-07:00 on mon,tue,wed,thu,fri'},
                ['Yttergang'] = {'at 06:00-07:00 on mon,tue,wed,thu,fri'}
            },   
        execute = function(domoticz, device)
            if ((device.name == 'Bad2etg' and device.active) or (device.name == 'Yttergang' and device.active)) then
                domoticz.notify('Noen har våknet', domoticz.NSS_PUSHOVER)
                
        end
        
    end
}
}

Re: What is wrong

Posted: Thursday 22 November 2018 21:30
by waaren
havnegata wrote: Thursday 22 November 2018 15:11 Someone has an idea of why this is not working?
Spoiler: show

Code: Select all

     return {
        on = {
            devices = {
                ['Bad2etg'] = {'at 06:00-07:00 on mon,tue,wed,thu,fri'},
                ['Yttergang'] = {'at 06:00-07:00 on mon,tue,wed,thu,fri'}
            },   
        execute = function(domoticz, device)
            if ((device.name == 'Bad2etg' and device.active) or (device.name == 'Yttergang' and device.active)) then
                domoticz.notify('Noen har våknet', domoticz.NSS_PUSHOVER)
                
        end
        
    end
}
}
You are quite close but misplaced one }
This one works on my system

Code: Select all

return {
                on =    { devices = {   ['Bad2etg']     = {'at 06:00-07:00 on mon,tue,wed,thu,fri'},
                                        ['Yttergang']   = {'at 06:00-07:00 on mon,tue,wed,thu,fri'}}
                        },   
            
    execute = function(domoticz, device)
        if (device.name == 'Bad2etg' and device.active) or (device.name == 'Yttergang' and device.active) then
            domoticz.notify('Noen har våknet', domoticz.NSS_PUSHOVER)
        end
    end
}

Re: What is wrong

Posted: Thursday 22 November 2018 23:06
by havnegata
Brilliant! Thanks a lot!

Re: What is wrong

Posted: Friday 23 November 2018 11:54
by havnegata
OK, so I was waken by hammering notifications today, so the script is working, but needs a little tuning ;) I figured a variable could fix this so that I only get one notification. I tried with adding a variable Vaken. The variable changes, but this is ignored the next time it runs.

Code: Select all

 return {
        on = {
            devices = {
                ['Bad2etg'] = {'at 06:00-11:00 on mon,tue,wed,thu,fri'},
                ['Yttergang'] = {'at 06:00-07:00 on mon,tue,wed,thu,fri'}}
            },   
        execute = function(domoticz, device)
            local Vaken = domoticz.variables('Vaken')
            if ((device.name == 'Bad2etg' and device.active) or (device.name == 'Yttergang' and device.active) and (Vaken.value == '0')) then
                domoticz.notify('Noen har våknet', domoticz.NSS_PUSHOVER)
                Vaken.set('1')
                
        end
        
    end
}

Re: What is wrong

Posted: Friday 23 November 2018 12:20
by waaren
havnegata wrote: Friday 23 November 2018 11:54 OK, so I was waken by hammering notifications today, so the script is working, but needs a little tuning ;) I figured a variable could fix this so that I only get one notification. I tried with adding a variable Vaken. The variable changes, but this is ignored the next time it runs.
Again it's in the brackets..

Code: Select all

 return {
        on = {
            devices = {
                ['Bad2etg'] = {'at 06:00-11:00 on mon,tue,wed,thu,fri'},
                ['Yttergang'] = {'at 06:00-07:00 on mon,tue,wed,thu,fri'}}
            },   
    execute = function(domoticz, device)
        local Vaken = domoticz.variables('Vaken')
		
        if ((device.name == 'Bad2etg' and device.active) or (device.name == 'Yttergang' and device.active) and (Vaken.value == '0')) then
            domoticz.notify('Noen har våknet', domoticz.NSS_PUSHOVER)
            Vaken.set('1')
	end
        domoticz.log("Current logic : (true or false and false)   ===>> " .. tostring(true or false and false) )
        domoticz.log("What you want : (true or false) and false   ===>> " .. tostring((true or false) and false) )
		
        
    end
}

Re: What is wrong

Posted: Tuesday 27 November 2018 17:45
by havnegata

Code: Select all

2018-11-27 17:33:08.228 Status: User: Admin initiated a switch command (16/Bad2etg/On)
2018-11-27 17:33:08.447 Status: EventSystem: Script event triggered: /home/pi/domoticz/dzVents/runtime/dzVents.lua
2018-11-27 17:33:08.461 Status: Notification: Noen har våknet
2018-11-27 17:33:08.464 Status: Set UserVariable Vaken = 1
The script is triggering on first switch "Bad2etg" and the uservariable is set and the notification is sent. So far so good 🙂 However it's not triggering on second switch "Yttergang" and the uservariable doesn't seem to have any effect because if first switch is triggered again the notification is sent again, which it was not supposed to do, at least according to my intentions :? Does this have anything to do with brackets?

Re: What is wrong

Posted: Tuesday 27 November 2018 18:15
by waaren
havnegata wrote: Tuesday 27 November 2018 17:45

Code: Select all

2018-11-27 17:33:08.228 Status: User: Admin initiated a switch command (16/Bad2etg/On)
2018-11-27 17:33:08.447 Status: EventSystem: Script event triggered: /home/pi/domoticz/dzVents/runtime/dzVents.lua
2018-11-27 17:33:08.461 Status: Notification: Noen har våknet
2018-11-27 17:33:08.464 Status: Set UserVariable Vaken = 1
The script is triggering on first switch "Bad2etg" and the uservariable is set and the notification is sent. So far so good 🙂 However it's not triggering on second switch "Yttergang" and the uservariable doesn't seem to have any effect because if first switch is triggered again the notification is sent again, which it was not supposed to do, at least according to my intentions :? Does this have anything to do with brackets?
What is the type of the uservariable ? integer / float / string ?

Re: What is wrong

Posted: Tuesday 27 November 2018 19:21
by havnegata
Integer

Re: What is wrong  [Solved]

Posted: Tuesday 27 November 2018 20:44
by waaren
havnegata wrote: Tuesday 27 November 2018 19:21Integer
OK then the script should look like the one below. Do you have another script to reset the uservariable ? Because based on this code the uservariable will be set once and after that the notification will never come again.

Code: Select all

 return {
        on = {
            devices = {
                ['Bad2etg'] = {'at 06:00-11:00 on mon,tue,wed,thu,fri'},
                ['Yttergang'] = {'at 06:00-07:00 on mon,tue,wed,thu,fri'}}
            },   

            execute = function(domoticz, device, info)

        local Vaken = domoticz.variables('Vaken')

        if ((device.name == 'Bad2etg' and device.active) or (device.name == 'Yttergang' and device.active)) and Vaken.value == 0 then
            domoticz.notify(info.scriptName,'Noen har våknet', domoticz.PRIORITY_NORMAL,nil,nil,domoticz.NSS_PUSHOVER)
            Vaken.set(1)
            domoticz.log("notification send and Vaken set")
        else  
            domoticz.log("device " .. device.name .. " active: " .. tostring(device.active) )
            domoticz.log("variable " .. Vaken.name .. " value: " .. Vaken.value )
        end
    end
}

Re: What is wrong

Posted: Tuesday 27 November 2018 22:18
by havnegata
Great! Thanks for the swift replies and your last solution is working perfect! It was the quotation marks around the uservariable values. It's supposed to be uservariable.set(1), not uservariable.set('1')

Re: What is wrong

Posted: Tuesday 27 November 2018 22:47
by waaren
havnegata wrote: Tuesday 27 November 2018 22:18 Great! Thanks for the swift replies and your last solution is working perfect! It was the quotation marks around the uservariable values. It's supposed to be uservariable.set(1), not uservariable.set('1')
Yes if the var is defined as integer then we do not need the ''