Custom http notification  [Solved]

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

Moderator: leecollings

User avatar
Varazir
Posts: 487
Joined: Friday 20 February 2015 22:23
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Contact:

Re: Custom http notification

Post by Varazir »

i'm getting
2020-10-01 13:14:21.710 Error: dzVents: Error: (3.0.12) An error occurred when calling event handler test
2020-10-01 13:14:21.710 Error: dzVents: Error: (3.0.12) ...moticz/scripts/dzVents/generated_scripts/global_data.lua:21: attempt to concatenate a table value (local 'cmd')

Code: Select all

return 
{
    logging =   { 
                level           = domoticz.LOG_DEBUG, 
                marker          = "Global" 
            },
	-- global helper functions
	helpers = {
		join = function(dz, command, title)
		    
		    local function logWrite(str,level)
                dz.log(tostring(str),level or dz.LOG_DEBUG)
            end
            
            local function osCommand(cmd)
            dz.log('Executing Command: ' .. cmd,dz.LOG_DEBUG)

            local fileHandle = assert(io.popen(cmd))
            local commandOutput = assert(fileHandle:read('*a'))
            local returnTable = {fileHandle:close()}

            dz.log('ReturnCode: ' .. returnTable[3] .. '\ncommandOutput:\n' .. commandOutput, dz.LOG_DEBUG)
            return commandOutput,returnTable[3] -- rc[3] contains returnCode
            end
        
		    logWrite("Command " .. command .. "Title" .. title)
		    
		    icon = "&icon=https://raw.githubusercontent.com/domoticz/domoticz/master/www/images/logo.png"
		    JoinPassword = dz.variables('JoinPassword').value
		    JoinEmail = dz.variables('JoinEmail').value
		    JoinKey = "apikey=" .. dz.variables('JoinKey').value
 		    JoinURL = "https://joinjoaomgcd.appspot.com/_ah/api/messaging/v1/sendPush?"
		    
		    if string.match(command, "=:=") then 
		            message = "&deviceId=group.android"
        		else
                    returnTitle, returnCode = osCommand(dz, 'perl /opt/join/joincli.pl \"' .. JoinPassword .. ';' .. JoinEmail .. ';' .. title .. '\"') 
                    message = "&title=" .. returnTitle .. icon .. "&deviceId=group.all"
            end
            
		    returnMessage, returnCode = osCommand(dz, 'perl /opt/join/joincli.pl \"' .. JoinPassword .. ';' .. JoinEmail .. ';' .. command .. '\"') 
		    if returnCode then
		        logWrite(returnCode)
		        return
		    end
		    
		    message = message .. "&text=" .. returnMessage
		    dz.openurl( JoinURL .. JoinKey .. message  )
    end
	}
}
Raspberry PI 4 with RaZberry Controller 2016 ZWave+ and CC2531(zigbee)
Several IKEA devices/z-wave devices
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Custom http notification

Post by waaren »

Varazir wrote: Thursday 01 October 2020 13:27 i'm getting
2020-10-01 13:14:21.710 Error: dzVents: Error: (3.0.12) An error occurred when calling event handler test
2020-10-01 13:14:21.710 Error: dzVents: Error: (3.0.12) ...moticz/scripts/dzVents/generated_scripts/global_data.lua:21: attempt to concatenate a table value (local 'cmd')
That is because you send two parms to the function osCommand (the domoticz object and the cmd) but this function only expect one; therefore the second one is ignored. The domoticz object (here dz) is a table so the Error message is appropriate.

Please change

Code: Select all

returnTitle, returnCode = osCommand(dz, 'perl /opt/join/joincli.pl \"' .. JoinPassword .. ';' .. JoinEmail .. ';' .. title .. '\"') 
to

Code: Select all

returnTitle, returnCode = osCommand('perl /opt/join/joincli.pl \"' .. JoinPassword .. ';' .. JoinEmail .. ';' .. title .. '\"') 
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
User avatar
Varazir
Posts: 487
Joined: Friday 20 February 2015 22:23
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Contact:

Re: Custom http notification

Post by Varazir »

waaren wrote: Thursday 01 October 2020 14:25
Varazir wrote: Thursday 01 October 2020 13:27 i'm getting
2020-10-01 13:14:21.710 Error: dzVents: Error: (3.0.12) An error occurred when calling event handler test
2020-10-01 13:14:21.710 Error: dzVents: Error: (3.0.12) ...moticz/scripts/dzVents/generated_scripts/global_data.lua:21: attempt to concatenate a table value (local 'cmd')
That is because you send two parms to the function osCommand (the domoticz object and the cmd) but this function only expect one; therefore the second one is ignored. The domoticz object (here dz) is a table so the Error message is appropriate.

Please change

Code: Select all

returnTitle, returnCode = osCommand(dz, 'perl /opt/join/joincli.pl \"' .. JoinPassword .. ';' .. JoinEmail .. ';' .. title .. '\"') 
to

Code: Select all

returnTitle, returnCode = osCommand('perl /opt/join/joincli.pl \"' .. JoinPassword .. ';' .. JoinEmail .. ';' .. title .. '\"') 

Ops, I was playing with making osCommand helper and forgot to remove the dz
Raspberry PI 4 with RaZberry Controller 2016 ZWave+ and CC2531(zigbee)
Several IKEA devices/z-wave devices
User avatar
Varazir
Posts: 487
Joined: Friday 20 February 2015 22:23
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Contact:

Re: Custom http notification

Post by Varazir »

waaren wrote: Thursday 01 October 2020 14:25
Varazir wrote: Thursday 01 October 2020 13:27 i'm getting
2020-10-01 13:14:21.710 Error: dzVents: Error: (3.0.12) An error occurred when calling event handler test
2020-10-01 13:14:21.710 Error: dzVents: Error: (3.0.12) ...moticz/scripts/dzVents/generated_scripts/global_data.lua:21: attempt to concatenate a table value (local 'cmd')
That is because you send two parms to the function osCommand (the domoticz object and the cmd) but this function only expect one; therefore the second one is ignored. The domoticz object (here dz) is a table so the Error message is appropriate.

Please change

Code: Select all

returnTitle, returnCode = osCommand(dz, 'perl /opt/join/joincli.pl \"' .. JoinPassword .. ';' .. JoinEmail .. ';' .. title .. '\"') 
to

Code: Select all

returnTitle, returnCode = osCommand('perl /opt/join/joincli.pl \"' .. JoinPassword .. ';' .. JoinEmail .. ';' .. title .. '\"') 
I'm close but I'm getting.

I have added log out put and the url looks ok.
2020-10-01 16:34:19.262 Error: dzVents: Error: (3.0.12) ...moticz/scripts/dzVents/generated_scripts/global_data.lua:57: attempt to call a nil value (field 'openurl')
Raspberry PI 4 with RaZberry Controller 2016 ZWave+ and CC2531(zigbee)
Several IKEA devices/z-wave devices
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Custom http notification  [Solved]

Post by waaren »

Varazir wrote: Thursday 01 October 2020 16:43
2020-10-01 16:34:19.262 Error: dzVents: Error: (3.0.12) ...moticz/scripts/dzVents/generated_scripts/global_data.lua:57: attempt to call a nil value (field 'openurl')
Please check the dzVents wiki for spelling (pay extra attention to case) and syntax before asking here.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
User avatar
Varazir
Posts: 487
Joined: Friday 20 February 2015 22:23
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Contact:

Re: Custom http notification

Post by Varazir »

waaren wrote:
Varazir wrote: Thursday 01 October 2020 16:43
2020-10-01 16:34:19.262 Error: dzVents: Error: (3.0.12) ...moticz/scripts/dzVents/generated_scripts/global_data.lua:57: attempt to call a nil value (field 'openurl')
Please check the dzVents wiki for spelling (pay extra attention to case) and syntax before asking here.
Damit sorry, I just read this and didn't think of the upper case.

domoticz.openURL('http://domain/path/to/something?withparameters=1')

Skickat från min EML-L29 via Tapatalk

Raspberry PI 4 with RaZberry Controller 2016 ZWave+ and CC2531(zigbee)
Several IKEA devices/z-wave devices
User avatar
Varazir
Posts: 487
Joined: Friday 20 February 2015 22:23
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Contact:

Re: Custom http notification

Post by Varazir »

waaren wrote: Thursday 01 October 2020 17:11
Varazir wrote: Thursday 01 October 2020 16:43
2020-10-01 16:34:19.262 Error: dzVents: Error: (3.0.12) ...moticz/scripts/dzVents/generated_scripts/global_data.lua:57: attempt to call a nil value (field 'openurl')
Please check the dzVents wiki for spelling (pay extra attention to case) and syntax before asking here.
Thank you, now it's up and running
Raspberry PI 4 with RaZberry Controller 2016 ZWave+ and CC2531(zigbee)
Several IKEA devices/z-wave devices
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest