homebridge-http-switch: Can't get a stateful switch to work :(

Describe the bug Can’t get a stateful switch to work. The logs report invalid header token. I have a relay which works with REST APIs. simply by sending a get request like: http:/IP/on http:/IP/off http:/IP/state http:/IP/toggle

Everyting works if doing from a browser or a command line. It also works if I use a stateless switch. But I need a stateful.

Version (output of npm list -g homebridge homebridge-http-switch)

  • homebridge: 4.6.3
  • homebridge-http-switch: 0.5.26

Configuration

Your configuration goes in here
      {
          "accessory": "HTTP-SWITCH",
          "name": "Switch",
          
          "switchType": "stateful",
          
          "onUrl": "http://IP/on",
          "offUrl": "http://IP/off",
          
          "statusUrl": "http://IP/state"
        }  

**Additional context**
From logs:
[2019-11-19 0:34:30] [Switch] Error: Parse Error: Invalid header token
    at Socket.socketOnData (_http_client.js:456:22)
    at Socket.emit (events.js:210:5)
    at addChunk (_stream_readable.js:308:12)
    at readableAddChunk (_stream_readable.js:289:11)
    at Socket.Readable.push (_stream_readable.js:223:10)
    at TCP.onStreamRead (internal/stream_base_commons.js:182:23) {
  bytesParsed: 21,
  code: 'HPE_INVALID_HEADER_TOKEN',
  reason: 'Invalid header token',
  rawPacket: <Buffer 48 54 54 50 2f 31 2e 30 20 32 30 30 20 4f 4b 0d 0a 6c 77 49 50 2f 31 2e 34 2e 31 20 28 68 74 74 70 3a 2f 2f 73 61 76 61 6e 6e 61 68 2e 6e 6f 6e 67 6e ... 300 more bytes>
}

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 17 (8 by maintainers)

Most upvoted comments

Hey I think I did manage to get it working! Thank you. I just set the pullInterval to 1 second, so for that to be more or less realtime. The reason is that the option I’m after isn’t only controlled via homekit but from the device’s app and I’m not the only one controlling it (there are some android guys as well). Here’s the config part.

{ "accessory": "HTTP-SWITCH", "name": "Switch", "switchType": "stateful", "onUrl": "http://ip:port/set_alarm.cgi?user=admin&pwd=password&audio=1", "offUrl": "http://ip:port/set_alarm.cgi?user=admin&pwd=password&audio=0", "statusUrl": "http://ip:port/get_params.cgi?user=admin&pwd=password", "statusPattern": "var alarm_audio=1;", "pullInterval": 1000, "debug": true }

I want to thank you again for this cool plugin and for the quick help!