Page 2 of 3

Re: PLEX status (dzVents)

Posted: Friday 08 May 2020 18:33
by OedzesG
Alles geïnstalleerd en werkt redelijk goed!
Thnx for feedback! enjoy!

Re: PLEX status (dzVents)

Posted: Tuesday 26 May 2020 14:50
by Number8
Hello,
I'm trying to get Webhooks on Tautilli side correctly setup. This is not a direct dzVents question. I know how to manage this part.
Is there a way to send dynamic data to Domoticz without having to setup a callback to Tatutilli?
Domoticz url has a data section: &data={some JSON data}. How do we make this data dynamic. For instance: when playback start is triggered, I'd like to send data specific to this event. There is indeed provision in the corresponding JSON data section of Playback start event.

Side question: Tautulli features quite a lot of internal variable, for instance {title}. What is the syntax that is expected in the data section of the above event?

So far in the test tab, there is a section with JSON data. I had no success so far get data delivered to Domoticz.

Thank you

Re: PLEX status (dzVents)

Posted: Tuesday 26 May 2020 15:12
by waaren
Number8 wrote: Tuesday 26 May 2020 14:50 So far in the test tab, there is a section with JSON data. I had no success so far get data delivered to Domoticz.
Did you already have a look at the customEvents section ?

Re: PLEX status (dzVents)

Posted: Tuesday 26 May 2020 16:10
by Number8
Thanks waaren, yes indeed, and I have several scripts using customEvents with great satisafaction. The problem is not on dzVents side, but on Tautilli side where I missed some info on how to set up the wekhook. Maybe the OP has the answer

Re: PLEX status (dzVents)

Posted: Saturday 30 May 2020 11:46
by Number8
Following a discussion I had with Tautulli dev https://www.reddit.com/r/Tautulli/comme ... emote_app/, this app send data using POST exclusively and not GET. Is there any chance that at some point Domoticz supports receiving DATA from a POST?

Re: PLEX status (dzVents)

Posted: Saturday 30 May 2020 12:16
by waaren
Number8 wrote: Saturday 30 May 2020 11:46 Following a discussion I had with Tautulli dev https://www.reddit.com/r/Tautulli/comme ... emote_app/, this app send data using POST exclusively and not GET. Is there any chance that at some point Domoticz supports receiving DATA from a POST?
If the data is part of the url, it is already possible.

Code: Select all

curl -d '' "http://127.0.0.1:8084/json.htm?type=command&param=customevent&event=myCustomEvent&data={test}"

Re: PLEX status (dzVents)

Posted: Saturday 30 May 2020 21:19
by Number8
No this is the issue, data is part of the request body

Re: PLEX status (dzVents)

Posted: Tuesday 02 June 2020 8:19
by Number8
So rephrase the request: is there any chance that customEvent API will be improved in order to accept a POST in order for a remote app to send data in the request body (instead of passing parameters directly in the URL).
Is it the right place to suggest improvements or is there a better place to post suggestions? Thank you

Re: PLEX status (dzVents)

Posted: Tuesday 02 June 2020 13:10
by waaren
Number8 wrote: Tuesday 02 June 2020 8:19 So rephrase the request: is there any chance that customEvent API will be improved in order to accept a POST in order for a remote app to send data in the request body (instead of passing parameters directly in the URL).
Yes but no guarantee or even a timeline. No idea yet how much effort is involved and if there would be any security issues to consider.
Is it the right place to suggest improvements or is there a better place to post suggestions? Thank you
The right place for suggestions is this subforum

Re: PLEX status (dzVents)

Posted: Thursday 04 June 2020 22:40
by waaren
Number8 wrote: Tuesday 02 June 2020 8:19 Is there any chance that customEvent API will be improved in order to accept a POST
I have created a Pull request JSON allow use of HTTP POST with postdata for dzvent's customEvents for this. Will be merged in a future beta if/when reviewers are OK with it.

Re: PLEX status (dzVents)

Posted: Friday 05 June 2020 2:35
by Number8
Thanks a lot waaren. I think that until customevents existed it was ok to send commands directly in the URL. With customevents one can potentially send a fair amount of data, and sending it into the URL is not the best approach. Having the possibility to use either get or post would be a must.

Re: PLEX status (dzVents)

Posted: Friday 05 June 2020 13:29
by Number8
I read that gizmocuz approved the idea. Good news! Wait and see now.

Re: PLEX status (dzVents)

Posted: Friday 05 June 2020 17:47
by waaren
Number8 wrote: Friday 05 June 2020 13:29 I read that gizmocuz approved the idea. Good news! Wait and see now.
Open for testing in build 12126

Re: PLEX status (dzVents)

Posted: Friday 05 June 2020 21:15
by Number8
Great! If I can I'll do some testing tomorrow. I guess JSON data is put in a table as for the GET?

Re: PLEX status (dzVents)

Posted: Friday 05 June 2020 22:24
by Number8
I did a very quick test. It works as expected (I used for that Tautulli application). Kudos!
I will do some more tomorrow.
Thanks for your great support in this matter

Re: PLEX status (dzVents)

Posted: Friday 05 June 2020 23:08
by waaren
Number8 wrote: Friday 05 June 2020 21:15 Great! If I can I'll do some testing tomorrow. I guess JSON data is put in a table as for the GET?
Yes on the receiving side (the script triggered by the customEvent) nothing changed.

Re: PLEX status (dzVents)

Posted: Saturday 06 June 2020 7:18
by Number8
I have done several tests as a matter of fact using Tautulli. Nothing to report except that it works very well. It opens a lot of new possibilities. Simple question though: item.headers reports nil. Is it what one should expect, or am I doing something wrong?

Re: PLEX status (dzVents)

Posted: Saturday 06 June 2020 8:44
by waaren
Number8 wrote: Saturday 06 June 2020 7:18 I have done several tests as a matter of fact using Tautulli. Nothing to report except that it works very well. It opens a lot of new possibilities. Simple question though: item.headers reports nil. Is it what one should expect, or am I doing something wrong?
That is what's expected.
dzVents does not know what the origin of your customEvent is. It can be send via an emitEvent, MQTT, HTTP Get or HTTP Post but for the receiving script it does not matter. It only gets the name and the data from the domoticz Webserver process.

So if you need information about the originator of the customEvent is has to be included in the data or being part of the name of the customEvent.

Re: PLEX status (dzVents)

Posted: Saturday 06 June 2020 9:20
by Number8
One little issue with the processing of single quote.
Here below full dz.item log

Code: Select all

2020-06-06 09:15:00.476 Status: dzVents: Info: batch job script: ------ Start external script: batchjobs-v1.lua:, trigger: "at 9:15" 
2020-06-06 09:15:00.476 Status: dzVents: Info: batch job script: starting daily backup 
2020-06-06 09:15:00.479 Status: dzVents: Info: batch job script: ------ Finished batchjobs-v1.lua 
2020-06-06 09:15:02.504 Status: Incoming connection from: 192.168.21.249 
2020-06-06 09:15:11.481 (rasp-PetiteMaison) Temp + Humidity (Mobile) 
2020-06-06 09:15:14.377 Status: dzVents: Info: plex script: ------ Start external script: plex.lua: Custom event: "plex" 
2020-06-06 09:15:14.377 Status: dzVents: customEvent> isJSON: false 
2020-06-06 09:15:14.377 Status: dzVents: customEvent> data: {"action": "resume", "titre": "L'Arnaque"} 
2020-06-06 09:15:14.377 Status: dzVents: customEvent> isGroup: false 
2020-06-06 09:15:14.377 Status: dzVents: customEvent> isTimer: false 
2020-06-06 09:15:14.377 Status: dzVents: customEvent> isSecurity: false 
2020-06-06 09:15:14.377 Status: dzVents: customEvent> trigger: plex 
2020-06-06 09:15:14.377 Status: dzVents: customEvent> isScene: false 
2020-06-06 09:15:14.377 Status: dzVents: customEvent> isHTTPResponse: false 
2020-06-06 09:15:14.377 Status: dzVents: customEvent> type: customEvent 
2020-06-06 09:15:14.377 Status: dzVents: customEvent> isDevice: false 
2020-06-06 09:15:14.377 Status: dzVents: customEvent> isSystem: false 
2020-06-06 09:15:14.377 Status: dzVents: customEvent> customEvent: plex 
2020-06-06 09:15:14.377 Status: dzVents: customEvent> isCustomEvent: true 
2020-06-06 09:15:14.377 Status: dzVents: customEvent> isHardware: false 
2020-06-06 09:15:14.377 Status: dzVents: customEvent> dump() 
2020-06-06 09:15:14.377 Status: dzVents: customEvent> status: info 
2020-06-06 09:15:14.377 Status: dzVents: customEvent> isVariable: false 
2020-06-06 09:15:14.377 Status: dzVents: customEvent> message: 
2020-06-06 09:15:14.377 Status: dzVents: customEvent> isXML: false 
2020-06-06 09:15:14.377 Status: dzVents: Info: plex script: {["isJSON"]=false, ["data"]="{"action": "resume", "titre": "L'Arnaque"}", ["isGroup"]=false, ["isTimer"]=false, ["isSecurity"]=false, ["trigger"]="plex", ["isScene"]=false, ["isHTTPResponse"]=false, ["type"]="customEvent", ["isDevice"]=false, ["isSystem"]=false, ["customEvent"]="plex", ["isCustomEvent"]=true, ["isHardware"]=false, ["dump"]=nil, ["status"]="info", ["isVariable"]=false, ["message"]="", ["isXML"]=false} 
2020-06-06 09:15:14.377 Status: dzVents: Info: plex script: ------ Finished plex.lua 
2020-06-06 09:15:14.377 Error: dzVents: Error: (3.0.9) plex script: Error parsing json to LUA table: /home/pi/domoticz/scripts/dzVents/../lua/JSON.lua:1234: /home/pi/domoticz/scripts/dzVents/../lua/JSON.lua:808: expected comma or '}' at byte 34 of: {"action": "resume", "titre": "L"Arnaque"} 
As you see, the data section reports correctly the value " L'Arnaque " . However the JSON decoder tranforms the single quote in a double quote which makes it failing to recognize it is a regular json stream

Re: PLEX status (dzVents)

Posted: Saturday 06 June 2020 10:59
by waaren
Number8 wrote: Saturday 06 June 2020 9:20 One little issue with the processing of single quote.

2020-06-06 09:15:14.377 Status: dzVents: Info: plex script: ------ Finished plex.lua
2020-06-06 09:15:14.377 Error: dzVents: Error: (3.0.9) plex script: Error parsing json to LUA table: /home/pi/domoticz/scripts/dzVents/../lua/JSON.lua:1234: /home/pi/domoticz/scripts/dzVents/../lua/JSON.lua:808: expected comma or '}' at byte 34 of: {"action": "resume", "titre": "L"Arnaque"} [/code]
As you see, the data section reports correctly the value " L'Arnaque " . However the JSON decoder tranforms the single quote in a double quote which makes it failing to recognize it is a regular json stream
According to the RFC, JSON strings cannot contain single quotes; hence the Lua JSON decoder does not allow them and throw an error.

Two possible workarounds:

1. Send your data as {"action": "resume", "titre": "L\u0027Arnaque"}
2. Use this code snippet in your script

Code: Select all

if not(item.json) then 
  item.json = dz.utils.fromJSON(item.data:gsub("'","\\u0027"))
end
[EDIT] replaced @ with single quote in code snippet was a left over from test.