homebridge-http-switch icon indicating copy to clipboard operation
homebridge-http-switch copied to clipboard

HowTo: Send JSON Command

Open seppelicous opened this issue 3 years ago • 3 comments

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"
        }
    }
}

seppelicous avatar Jan 30 '21 15:01 seppelicous

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?

redbull290 avatar Jan 31 '21 19:01 redbull290

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.

wrp1002 avatar Feb 26 '21 05:02 wrp1002

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

mbierman avatar Sep 14 '21 04:09 mbierman