DzVents and PushSafer - need help getting it to work  [Solved]

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

Moderator: leecollings

Post Reply
User avatar
erem
Posts: 230
Joined: Tuesday 27 March 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: 2021.1
Location: Amsterdam/netherlands
Contact:

DzVents and PushSafer - need help getting it to work

Post by erem »

Friends,

I am trying to get PushSafer to send a push message to my iPhone.
The http syntax i use is OK, as i can end that message from a browser from the RPi and the notification shows up at my phone.
trying to send that message from DzVents does not yied an error from DzVents, but the message never shows up at my phone

DzVents code i "wrote/cobbled together"

Code: Select all


-- Test event to see if pushsafer can be done from DzEvents
return {
   on = {
      timer = { 'every 5 minutes' },
      httpResponses = { 'MsgSent' }
   },
   execute = function(domoticz, device)
      if (device.isTimer) then
         domoticz.openURL(
            {
            url = 'https://www.pushsafer.com/api?k=####################&d=#####&i=173&v=3&pr=0&a=1&t=Message from DzEvents&m=Zet je fiets aan de lader',
            method = 'POST',
            callback = 'MsgSent'
            }
         )
      end
      if (device.isHTTPResponse) then
         if (device.ok) then
            domoticz.log('HTTP POST message TBC was sent', domoticz.LOG_INFO)
         else
            domoticz.log('device.ok was not on', domoticz.LOG_INFO)
         end
      end  
   end
}

The Domoticz log with DzVents at most verbose level yields

Code: Select all

2018-12-11 11:30:00.467 Status: dzVents: Info: ------ Start internal script: SndNotTest:, trigger: every 5 minutes
2018-12-11 11:30:00.469 Status: dzVents: Debug: OpenURL: url = https://www.pushsafer.com/api?k=####################&d=####&i=173&v=3&pr=0&a=1&t=Message from DzEvents&m=Zet je fiets aan de lader
2018-12-11 11:30:00.469 Status: dzVents: Debug: OpenURL: method = POST
2018-12-11 11:30:00.469 Status: dzVents: Debug: OpenURL: post data =
2018-12-11 11:30:00.469 Status: dzVents: Debug: OpenURL: headers = nil
2018-12-11 11:30:00.469 Status: dzVents: Debug: OpenURL: callback = MsgSent
2018-12-11 11:30:00.469 Status: dzVents: Info: ------ Finished SndNotTest
2018-12-11 11:30:00.469 Status: dzVents: Debug: Commands sent to Domoticz:
2018-12-11 11:30:00.470 Status: dzVents: Debug: - OpenURL = {["method"]="POST", ["URL"]="https://www.pushsafer.com/api?k=####################&d=####&i=173&v=3&pr=0&a=1&t=Message from DzEvents&m=Zet je fiets aan de lader", ["_trigger"]="MsgSent", ["postdata"]=""}
2018-12-11 11:30:00.470 Status: dzVents: Debug: =====================================================

I do not see any obvious errors, but since there is no notification received, something must be wrong.
I have tried sending the same http string from the RPi browser, and that yields a notification on my phone, so technically it works from the RPi.
I suspect the issue to be in my DzVents code, but as a LUA newbie i i am not to familiar with the syntax.

Did anybody try this already and got it to work? I am grateful for any advice that may help me get this working.

thanks for reading,

Rob
Regards,

Rob
elmortero
Posts: 247
Joined: Sunday 29 November 2015 20:46
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.9639
Location: Spain
Contact:

Re: DzVents and PushSafer - need help getting it to work  [Solved]

Post by elmortero »

I think you should use urlencode (info on the dzvents wiki page) to avoid the spaces in the URL.
You can easily check if that is the cause by replacing the spaces in your URL with %20
User avatar
erem
Posts: 230
Joined: Tuesday 27 March 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: 2021.1
Location: Amsterdam/netherlands
Contact:

Re: DzVents and PushSafer - need help getting it to work

Post by erem »

@elmotero, you hit the nail on the head. domoticz.urlEncode was the solution

But, urlencode also encoded the http:// to http%3A%2F%2F, and that did not work for me

so i ended up doing: PS_URL = PS_httpHeader .. domoticz.urlEncode(PS_Parms)
Regards,

Rob
Robby1969
Posts: 3
Joined: Tuesday 28 June 2016 13:37
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: DzVents and PushSafer - need help getting it to work

Post by Robby1969 »

Hello Rob,

Is it possible to place the final code in this subject. You wrote "so i ended up doing: PS_URL = PS_httpHeader .. domoticz.urlEncode(PS_Parms)"
But where in the code do I have to place this?

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

Re: DzVents and PushSafer - need help getting it to work

Post by waaren »

Robby1969 wrote: Thursday 24 January 2019 21:58 Is it possible to place the final code in this subject. You wrote "so i ended up doing: PS_URL = PS_httpHeader .. domoticz.urlEncode(PS_Parms)"
But where in the code do I have to place this?
There is no real need to use the http code for a pushsafer notification from dzVents. Pushsafer can be used with the notify command.

Code: Select all

domoticz.notify("Subject", "Message", domoticz.PRIORITY_NORMAL,,,domoticz.NSS_PUSHSAFER) 
If for one reason or another you still need to use the operURL approach the code would be something like

Code: Select all

-- Test event to see if pushsafer can be done from DzEvents
return {
   on = {
      timer = { 'every 5 minutes' },
      httpResponses = { 'MsgSent' }
   },
   execute = function(domoticz, device)
      if (device.isTimer) then
         PS_httpHeader  = 'https://www.pushsafer.com/api?k='
         PS_Parms       = '####################&d=#####&i=173&v=3&pr=0&a=1&t=Message from DzEvents&m=Zet je fiets aan de lader'
         PS_URL         = PS_httpHeader .. domoticz.urlEncode(PS_Parms)
         domoticz.openURL(
            {
            url = PS_URL,
            method = 'POST',
            callback = 'MsgSent'
            }
         )
      end
      if (device.isHTTPResponse) then
         if (device.ok) then
            domoticz.log('HTTP POST message TBC was sent', domoticz.LOG_INFO)
         else
            domoticz.log('device.ok was not on', domoticz.LOG_INFO)
         end
      end  
   end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Robby1969
Posts: 3
Joined: Tuesday 28 June 2016 13:37
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: DzVents and PushSafer - need help getting it to work

Post by Robby1969 »

In the log I get the message : HTTP POST message TBC was sent, but I do not get the message on my phone.
If I paste the URL in the browser I do get the message on my phone.
With domoticz.notify I also get a message on my phone.
I have Domoticz version 4.9700

What could be the problem?
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: DzVents and PushSafer - need help getting it to work

Post by waaren »

Robby1969 wrote: Monday 28 January 2019 14:07 In the log I get the message : HTTP POST message TBC was sent, but I do not get the message on my phone.
If I paste the URL in the browser I do get the message on my phone.
With domoticz.notify I also get a message on my phone.
I have Domoticz version 4.9700

What could be the problem?
A problem could be that the api key and device are also urlEncoded.
Can you try this ? It works on my system.
[EDIT] removed logWrite and changed domoticz.urlEncode domoticz.utils.urleEncode (thanks Robby1969)

Code: Select all

-- Test event to see if pushsafer can be done from DzEvents
return {
   on = {
      timer = { 'every 5 minutes' },
      httpResponses = { 'MsgSent' }
   },
   execute = function(domoticz, device)
      if (device.isTimer) then
         PS_httpHeader  = 'https://www.pushsafer.com/api?k='
         local subject = 'Message from DzEvents'
               subject = domoticz.utils.urlEncode(subject)
         local message = 'Zet je fiets aan de lader nu'
               message = domoticz.utils.urlEncode(message)
         PS_Parms       = 'XXXXXXXX&d=XXXX&i=173&v=3&pr=0&a=1&t'.. subject .. '&m=' .. message
         PS_URL         = PS_httpHeader .. PS_Parms
         domoticz.openURL(
            {
            url = PS_URL,
            method = 'POST',
            callback = 'MsgSentX'
            }
         )
          
      end
      if (device.isHTTPResponse) then
         if (device.ok) then
            domoticz.log('HTTP POST message TBC was sent', domoticz.LOG_INFO)
         else
            domoticz.log('device.ok was not on', domoticz.LOG_INFO)
         end
      end  
   end
}
Last edited by waaren on Monday 28 January 2019 23:07, edited 3 times in total.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Robby1969
Posts: 3
Joined: Tuesday 28 June 2016 13:37
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: DzVents and PushSafer - need help getting it to work

Post by Robby1969 »

Thanks! now it works. A few minor changes where necessary:
Log: Info: domoticz.urlEncode deprecated. Please use domoticz.utils.urlEncode.
--domoticz.urlEncode needed to be domoticz.utils.urlEncode
and
Log: Error (2.4.6): ...oticz/scripts/dzVents/generated_scripts/testmessage3.lua:21: attempt to call global 'logWrite' (a nil value)
--logWrite(PS_URL) needed to be domoticz.log(PS_URL)

So the final code is:

Code: Select all

return {
   on = {
      timer = { 'every 2 minutes' },
      httpResponses = { 'MsgSent' }
   },
   execute = function(domoticz, device)
      if (device.isTimer) then
         PS_httpHeader  = 'https://www.pushsafer.com/api?k='
         local subject = 'Message from DzEvents'
               subject = domoticz.utils.urlEncode(subject)
         local message = 'Zet je motorfiets aan de lader nu'
               message = domoticz.utils.urlEncode(message)
         PS_Parms       = XXXXXXXXXXXXXXXX'&d=XXXXXXX&i=50&s=20&v=3&pr=0&a=1&t'.. subject .. '&m=' .. message
         PS_URL         = PS_httpHeader .. PS_Parms
         --logWrite(PS_URL)
         domoticz.log(PS_URL)
         
         domoticz.openURL(
            {
            url = PS_URL,
            method = 'POST',
            callback = 'MsgSentX'
            }
         )
          
      end
      if (device.isHTTPResponse) then
         if (device.ok) then
            domoticz.log('HTTP POST message TBC was sent', domoticz.LOG_INFO)
         else
            domoticz.log('device.ok was not on', domoticz.LOG_INFO)
         end
      end  
   end
}

Post Reply

Who is online

Users browsing this forum: Google [Bot] and 1 guest