What is wrong  [Solved]

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

Moderator: leecollings

Post Reply
User avatar
havnegata
Posts: 114
Joined: Wednesday 10 September 2014 11:05
Target OS: Raspberry Pi / ODroid
Domoticz version: V4.10162
Location: Norway
Contact:

What is wrong

Post 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
}
}
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: What is wrong

Post 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
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
User avatar
havnegata
Posts: 114
Joined: Wednesday 10 September 2014 11:05
Target OS: Raspberry Pi / ODroid
Domoticz version: V4.10162
Location: Norway
Contact:

Re: What is wrong

Post by havnegata »

Brilliant! Thanks a lot!
User avatar
havnegata
Posts: 114
Joined: Wednesday 10 September 2014 11:05
Target OS: Raspberry Pi / ODroid
Domoticz version: V4.10162
Location: Norway
Contact:

Re: What is wrong

Post 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
}
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: What is wrong

Post 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
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
User avatar
havnegata
Posts: 114
Joined: Wednesday 10 September 2014 11:05
Target OS: Raspberry Pi / ODroid
Domoticz version: V4.10162
Location: Norway
Contact:

Re: What is wrong

Post 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?
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: What is wrong

Post 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 ?
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
User avatar
havnegata
Posts: 114
Joined: Wednesday 10 September 2014 11:05
Target OS: Raspberry Pi / ODroid
Domoticz version: V4.10162
Location: Norway
Contact:

Re: What is wrong

Post by havnegata »

Integer
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: What is wrong  [Solved]

Post 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
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
User avatar
havnegata
Posts: 114
Joined: Wednesday 10 September 2014 11:05
Target OS: Raspberry Pi / ODroid
Domoticz version: V4.10162
Location: Norway
Contact:

Re: What is wrong

Post 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')
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: What is wrong

Post 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 ''
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest