Supereg / homebridge-http-switch

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

HowTo: Send JSON Command #85

Closed seppelicous closed 1 year ago

seppelicous commented 3 years ago

Hi,

I like to send JSON Command as HTTP POST to my Hyperion Server. I tested the command with a simple HTTP rest tool. The JSON in the body is {"command":"componentstate","componentstate":{"component":"LEDDEVICE","state":false}}

That works for me, but I am not sure if implemented it correctly. Can someone have a look at it, if this is correct? Thank you very much!

This is my Config for the Switch, but nothing happens. I also get no error.

{
    "accessory": "HTTP-SWITCH",
    "name": "HTTP-SWITCH",
    "switchType": "toggle",
    "onUrl": {
        "url": "http://192.168.178.128:8090/json-rpc",
        "method": "POST",
        "body": {
            "command": "componentstate",
            "componentstate": {
                "component": "LEDDEVICE",
                "state": true
            }
        },
        "headers": {
            "Content-Type": "application/json"
        }
    },
    "offUrl": {
        "url": "http://192.168.178.128:8090/json-rpc",
        "method": "POST",
        "body": {
            "command": "componentstate",
            "componentstate": {
                "component": "LEDDEVICE",
                "state": false
            }
        },
        "headers": {
            "Content-Type": "application/json"
        }
    }
}
redbull290 commented 3 years ago

I got the tham Problem. My Config looks like yours and also nothing happens

Is anybody out there how is explain the json part in body Tag?

wrp1002 commented 3 years ago

I'm having the same issues.

According to plugin documentation:

body: Defines the body sent with the http request. If value is not a string it will be converted to a JSON string automatically.

Hyperion logs say that it's invalid JSON. My guess is that the plugin includes quotations around the JSON, and Hyperion can't handle that.

mbierman commented 2 years ago

I have a similar? issue #95. I thought I was doing something wrong. Maybe I am?