Supereg / homebridge-http-switch

Powerful http switch for Homebridge: https://github.com/homebridge/homebridge
ISC License
219 stars 36 forks source link

Is it possible to send XML Post Request #63

Closed samma0815 closed 4 years ago

samma0815 commented 4 years ago

Hi, I use this plugin to send HTTP GET and POST requests in JSON Format to a Yamaha RX-A880 AV Receiver. However some commands require to send an XML request as post, like this one:

None 80 Hz

Is it possible to send that XML request via this plugin? If yes, how would the config look like since I already tried escaping the quotes or use single quotes. However it didn't work me.

Supereg commented 4 years ago

Well you can just put it in as a string in the body property. double quotes MUST be escaped using back slash (as double quotes are used in json to mark a string). Additionally line breaks are not supported by json. Instead you need to replace them by \n

So something like the following should work:

{
  "body": "<YAMAHA_AV rsp=\"GET\" RC=\"0\">\n\n<Speaker_Preout>\n<Pattern_1>\n\n<Front_Presence>\nNone\n<Cross_Over>80 Hz</Cross_Over>\n</Front_Presence>\n\n</Pattern_1>\n</Speaker_Preout>\n\n</YAMAHA_AV>"
}
samma0815 commented 4 years ago

Sorry for my late response and thanks so much for your help. I am going to try it out soon.

samma0815 commented 1 year ago

Works like charm!

{ "accessory": "HTTP-SWITCH", "name": "AVR Speaker Large", "switchType": "toggle", "onUrl": { "url": "http:///YamahaRemoteControl/ctrl", "method": "POST", "body": "<YAMAHA_AV cmd=\"PUT\">Large" }, "offUrl": { "url": "http:///YamahaRemoteControl/ctrl", "method": "POST", "body": "<YAMAHA_AV cmd=\"PUT\">Small" } },