Push notifications via Nextcloud
Moderators: leecollings, remb0
Push notifications via Nextcloud
Hi,
I think that a lot of users has installed Nextcloud server along with Domoticz and would be nice to use a Nextcloud as push notification server for Domoticz. Unfortunately I don't have enough skills to write plug-in for that.
I think that a lot of users has installed Nextcloud server along with Domoticz and would be nice to use a Nextcloud as push notification server for Domoticz. Unfortunately I don't have enough skills to write plug-in for that.
Re: Push notifications via Nextcloud
Please can anyone help me how to configure domoticz.openURL function to act like this command?
At least I am trying to make DzVents script for notification...
Code: Select all
curl -H "OCS-APIREQUEST: true" -X POST https://ADMIN:TOKEN@URL/ocs/v2.php/apps/admin_notifications/api/v1/notifications/USER -d "shortMessage=test"
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Push notifications via Nextcloud
Something likem147 wrote: ↑Tuesday 19 January 2021 13:26 Please can anyone help me how to configure domoticz.openURL function to act like this command?Code: Select all
curl -H "OCS-APIREQUEST: true" -X POST https://ADMIN:TOKEN@URL/ocs/v2.php/apps/admin_notifications/api/v1/notifications/USER -d "shortMessage=test"
Code: Select all
domoticz.openURL({
url = 'https://ADMIN:TOKEN@URL/ocs/v2.php/apps/admin_notifications/api/v1/notifications/USER',
headers = { ['OCS-APIREQUEST'] = true },
postData = { ['shortMessage'] = 'test' },
method = 'POST',
callback = 'Could be any string or left out completely',
})
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Re: Push notifications via Nextcloud
The "-d" is missing in postData.waaren wrote: ↑Tuesday 19 January 2021 13:43Something likem147 wrote: ↑Tuesday 19 January 2021 13:26 Please can anyone help me how to configure domoticz.openURL function to act like this command?Code: Select all
curl -H "OCS-APIREQUEST: true" -X POST https://ADMIN:TOKEN@URL/ocs/v2.php/apps/admin_notifications/api/v1/notifications/USER -d "shortMessage=test"
Code: Select all
domoticz.openURL({ url = 'https://ADMIN:TOKEN@URL/ocs/v2.php/apps/admin_notifications/api/v1/notifications/USER', headers = { ['OCS-APIREQUEST'] = true }, postData = { ['shortMessage'] = 'test' }, method = 'POST', callback = 'Could be any string or left out completely', })
If i try to add it like this:
Code: Select all
postData = {"-d", ['shortMessage'] = 'test' },
Thank you for your help.2021-01-19 14:06:00.077 Status: dzVents: Debug: OpenURL: method = POST
2021-01-19 14:06:00.077 Status: dzVents: Debug: OpenURL: post data = {"shortMessage":"test","1":"-d"}
2021-01-19 14:06:00.077 Status: dzVents: Debug: OpenURL: headers = !#OCS-APIREQUEST: true
2021-01-19 14:06:00.077 Status: dzVents: Debug: OpenURL: callback = Could be any string or left out completely
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Push notifications via Nextcloud
The -d is no data but a control switch for curl.
Code: Select all
-d, --data <data> HTTP POST data
--data-ascii <data> HTTP POST ASCII data
--data-binary <data> HTTP POST binary data
--data-raw <data> HTTP POST data, '@' allowed
--data-urlencode <data> HTTP POST data url encoded
--delegation <LEVEL> GSS-API delegation permission
--digest Use HTTP Digest Authentication
If you use the callback option you will see the result of the call (including errors (if any))
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Re: Push notifications via Nextcloud
Of course you are right! Sorry.waaren wrote: ↑Tuesday 19 January 2021 14:18The -d is no data but a control switch for curl.
You don't use it with the openURL switch.Code: Select all
-d, --data <data> HTTP POST data --data-ascii <data> HTTP POST ASCII data --data-binary <data> HTTP POST binary data --data-raw <data> HTTP POST data, '@' allowed --data-urlencode <data> HTTP POST data url encoded --delegation <LEVEL> GSS-API delegation permission --digest Use HTTP Digest Authentication
If you use the callback option you will see the result of the call (including errors (if any))
But anyway the result is not same as posted curl command >> It doesn't work
2021-01-19 14:24:00.343 Status: dzVents: Debug: OpenURL: method = POST
2021-01-19 14:24:00.343 Status: dzVents: Debug: OpenURL: post data = {"shortMessage":"test"}
2021-01-19 14:24:00.343 Status: dzVents: Debug: OpenURL: headers = !#OCS-APIREQUEST: true
2021-01-19 14:24:00.343 Status: dzVents: Debug: OpenURL: callback = Could be any string or left out completely
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Push notifications via Nextcloud
What is you domoticz version?
The Header section does not look right.
Can you send me your script so I can help you adding a response section? It might help in identifying what happens.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Re: Push notifications via Nextcloud
Version: 2020.2 (build 12738)
Well the "script" is so far just openUrl function. I wanted to figure it out before I move forward.
Code: Select all
return {
on = {
-- devices = {},
timer = {'every minute'},
},
logging = {
level = domoticz.LOG_DEBUG,
},
execute = function(domoticz, triggeredItem)
domoticz.openURL({
url = 'https://admin:token@url/ocs/v2.php/apps/admin_notifications/api/v1/notifications/user',
headers = { ['OCS-APIREQUEST'] = 'true' },
postData = {['shortMessage'] = 'test' },
method = 'POST',
})
end
}
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Push notifications via Nextcloud
Below version should give some more info..
Code: Select all
local scriptVar = 'nextCloud'
return
{
on =
{
devices =
{
},
timer =
{
'every minute'
},
httpResponses =
{
scriptVar,
},
},
logging = {
level = domoticz.LOG_DEBUG,
marker = scriptVar,
},
execute = function(dz, item)
local function sendTo()
dz.openURL(
{
url = 'https://admin:token@url/ocs/v2.php/apps/admin_notifications/api/v1/notifications/user',
headers = { ['OCS-APIREQUEST'] = 'true' },
postData = {['shortMessage'] = 'test' },
method = 'POST',
callback = scriptVar,
})
end
if item.isTimer or item.isDevice then
sendTo()
else
dz.log(item,dz.LOG_DEBUG)
end
end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Re: Push notifications via Nextcloud
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Push notifications via Nextcloud
Could it be something with a string that needs url encoding?
Anyway can you test this one? ( After updating to a later version )
Code: Select all
-- Requires dzVents >= 3.1 (domoticz build >= 12771)
local scriptVar = 'nextCloud'
return
{
on =
{
devices =
{
},
timer =
{
'every minute',
},
shellCommandResponses =
{
scriptVar,
},
},
logging = {
level = domoticz.LOG_DEBUG,
marker = scriptVar,
},
execute = function(dz, item)
local function sendTo()
dz.executeShellCommand(
{
command = 'curl -H "OCS-APIREQUEST: true" -X POST https://ADMIN:TOKEN@URL/ocs/v2.php/apps/admin_notifications/api/v1/notifications/USER -d "shortMessage=test"',
timeout = 300,
callback = scriptVar,
})
end
if item.isTimer or item.isDevice then
sendTo()
else
dz.log(item,dz.LOG_DEBUG)
end
end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Re: Push notifications via Nextcloud
I don't really understand.Could it be something with a string that needs url encoding?
I am afraid I have to wait until the build issue will be solved.Anyway can you test this one? ( After updating to a later version )
https://github.com/domoticz/domoticz/issues/4546
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Push notifications via Nextcloud
Probably a long shot but the characters '!', '*', "'", "(", ")", ";", ":", "@", "&", "=", "+", "$", ",", "/", "?", "%", "#", "[", "]" in a string are not very well interpreted when sending in a url. To convert these chars to something that can be part of a url, the function dz.utils.urlEncode() is available. So if ADMIN:TOKEN does contain any of these chars you could try to urlEncode the string first.
OK. @gizmocuz is working that now so should not take much longerI am afraid I have to wait until the build issue will be solved.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Push notifications via Nextcloud
If you have a windows system in your network you could test this now.
Installing domoticz on windows can be done in a couple of minutes. Only other thing needed would then be curl
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Re: Push notifications via Nextcloud
Ok I have tried install last beta on windows and it works!
Token contains doesn't contain any of these characters. Only weird character there is "-" .Probably a long shot but the characters '!', '*', "'", "(", ")", ";", ":", "@", "&", "=", "+", "$", ",", "/", "?", "%", "#", "[", "]" in a string are not very well interpreted when sending in a url. To convert these chars to something that can be part of a url, the function dz.utils.urlEncode() is available. So if ADMIN:TOKEN does contain any of these chars you could try to urlEncode the string first.
Who is online
Users browsing this forum: No registered users and 1 guest