Page 1 of 1

Problems with Pushover suddenly

Posted: Saturday 11 January 2020 23:30
by Golleman
Hi,
My notifications scripts have been working fine until latest update (so I believe) to version 4.10717 (May 9th 2019). Testing pushover via settings gui works fine.

The following scripts failes with log entries

Code: Select all

2020-01-11 23:17:39.283 Status: LUA: ~~~~~~ (script_device_trigger) -- EventUpdated by TEST_BUTTON state:On idx:166 at 23.17.39
2020-01-11 23:17:45.048 Notification sent (pushover) => Failed
2020-01-11 23:17:45.048 Error: Pushover:
2020-01-11 23:17:46.087 Notification sent (email) => Success
Script triggered by dummy switch:

Code: Select all

commandArray = {}
if(devicechanged['TEST_BUTTON'])then
	commandArray[#commandArray + 1] = { SendNotification = 'subject#body#0###'}
end
return commandArray
However, if I remove the if clause, it works...

Code: Select all

commandArray = {}
commandArray[#commandArray + 1] = { SendNotification = 'subject#body#0###'}
return commandArray
and I recieve the push notification. Note that the scripts above is only an error tracking effort. I have several scripts that uses the 'SendNotification' in a similar way and they fail. Usually in a if statement I set notifications like

Code: Select all

...
if(globalvariables['Security']=='Armed Away')then
		commandArray['SendNotification']=Alarm ON' .. '#' .. 'Entire house#0'
		print('** alarm script: *Armed Away* -> ligth off')
	end
...
and it fails now. Any ideas why and how to solve?

Re: Problems with Pushover suddenly

Posted: Monday 13 January 2020 7:14
by Golleman
Created a new LUA script that contained a function that does the 'SendNotification' setter on the commandArray and that worked ONCE. Second and following executes failed. Something is not right with the request...

Temp solution was to create a bash script that curls the pushover api and call that from the function script. Not optimal, but will do for now.

Function script:

Code: Select all

function SendNotification(commandArray, subject, body, priority, sound)
	if(priority == nil or priority == '')then 
		priority = '0'
	end
	if(sound == nil or sound == '')then 
		sound = '0'
	end
	print('##---> SendNotification script (email + pushover) with subject:' .. subject)
	commandArray[#commandArray + 1] = { SendNotification = subject .. '#' .. body .. '#' .. priority .. '#' .. sound .. '##email'}
	--os.execute ('/home/pi/domoticz/scripts/pushover.sh "Test" "Test message" "-1"')
	os.execute ('/home/pi/domoticz/scripts/pushover.sh "' .. subject .. '" "' .. body .. '" "' .. priority .. '" "' .. sound .. '"')
end

Re: Problems with Pushover suddenly

Posted: Monday 13 January 2020 13:19
by bewo
Hi Golleman,

maybe there's a problem with the annotations or the hashtags, when they are empty...

I'll do a "normal" notification in this way - Which work's fine:

Code: Select all

if devicechanged['TEST-Schalter'] == 'On' then    
    commandArray['SendNotification'] = 'Titel#Hello, this is an test message!'    
end
If you want to send an message with higher priority just add an #1 or #2 at the end, just before the closing ' .


The format with commandArray-Table which i use without problem's is:

Code: Select all

if devicechanged['TEST-Schalter'] == 'On' then 
   commandArray[#commandArray+1] = { ['SendNotification'] = 'Titel#Hello, this is an test message!' }
end

And if you wan't to use a function, for example to send the message only at one of your devices, this is an possibility (found the base for this here in the forum):

Code: Select all

function Pushmessage(priority, title, message, device, sound)
   -- priority = -2,-1,0,1,2
   -- title = title of the message
   -- message = message you'll like to send
   -- device = The device which should receive the message. For example: All, Name1, Name2
   if device == 'All' or device == nil then device = ''
   elseif device == 'Name1' then device = 'Name-of-the-device1-at-the-Pushover-Account'
   elseif device == 'Name2' then device = 'Name-of-the-device2-at-the-Pushover-Account'
   end
   -- sound = The sound you would like to hear; Find here: https://pushover.net/api#sounds
   if sound == nil then sound = '' end
   -- Pushover-Account:
   UserKey = '1234-find-in-Pushover'
   ApiToken = '1234-find-in-Pushover'
   -- Send the message:
   os.execute('curl --data "token='..ApiToken..'&user='..UserKey..'&title='..encodeURI(title)..'&message='..encodeURI(message)..'&priority='..tostring(priority)..'&sound='..sound..'&device='..device..'" https://api.pushover.net/1/messages.json')
   print('Send an push-message to: '..device)
end
In the pushover-function i use another function for encode the message as an uri, to prevent problems with special characters:

Code: Select all

function encodeURI(str)
	if (str) then
		str = string.gsub (str, "\n", "\r\n")
		str = string.gsub (str, "([^%w ])",
			function (c) return string.format ("%%%02X", string.byte(c)) end)
		str = string.gsub (str, " ", "+")
    end
	return str
end
With the function sending a message is done as follows:

Code: Select all

if devicechanged['TEST-Schalter'] == 'On' then
	Pushmessage('0', 'Title', 'Hello, this is an test message!', 'All')
end
    --


Re: Problems with Pushover suddenly

Posted: Thursday 16 January 2020 8:40
by Golleman
Hi bewo,
Thanks for the feedback. I've tried different constructs of the annotation, unfortunately with the same outcome.
However, my function using curl is similar to yours and that works for me too.
I'll continue some testing and will use your suggestion with the uri encoding as well (thanks), but as the

Code: Select all

commandArray['SendNotification']
works once for a new script, then fails, I believe there is something else going on with my pi/domoticz setup. I will also try out the table construct and see if it behaves differently. Is there a way to get detailed logging for errors in the gui log?