Coder Social home page Coder Social logo

supereg / homebridge-http-switch Goto Github PK

View Code? Open in Web Editor NEW
219.0 14.0 36.0 294 KB

Powerful http switch for Homebridge: https://github.com/homebridge/homebridge

License: ISC License

JavaScript 100.00%
homebridge switch http hap homekit javascript notifications homebridge-plugin homebridge-http toggle-switch

homebridge-http-switch's Introduction

homebridge-http-switch Plugin

npm npm GitHub Workflow Status GitHub issues GitHub pull requests

homebridge-http-switch is a Homebridge plugin with which you can configure HomeKit switches which forward any requests to a defined http server. This comes in handy when you already have home automated equipment which can be controlled via http requests. Or you have built your own equipment, for example some sort of lightning controlled with an wifi enabled Arduino board which than can be integrated via this plugin into Homebridge.

homebridge-http-switch supports three different type of switches. A normal stateful switch and two variants of stateless switches (stateless and stateless-reverse) which differ in their original position. For stateless switches you can specify multiple urls to be targeted when the switch is turned On/Off.
More about on how to configure such switches can be read further down.

Installation

First of all you need to have Homebridge installed. Refer to the repo for instructions.
Then run the following command to install homebridge-http-switch

sudo npm install -g homebridge-http-switch

Updating the switch state in HomeKit

The 'On' characteristic from the 'switch' service has the permission to notify the HomeKit controller of state changes. homebridge-http-switch supports two ways to send state changes to HomeKit.

The 'pull' way:

The 'pull' way is probably the easiest to set up and supported in every scenario. homebridge-http-switch requests the state of the switch in an specified interval (pulling) and sends the value to HomeKit.
Look for pullInterval in the list of configuration options if you want to configure it.

The 'push' way:

When using the 'push' concept, the http device itself sends the updated value to homebridge-http-switch whenever the value changes. This is more efficient as the new value is updated instantly and homebridge-http-switch does not need to make needless requests when the value didn't actually change.
However because the http device needs to actively notify the homebridge-http-switch there is more work needed to implement this method into your http device.

Using MQTT:

MQTT (Message Queuing Telemetry Transport) is a protocol widely used by IoT devices. IoT devices can publish messages on a certain topic to the MQTT broker which then sends this message to all clients subscribed to the specified topic. In order to use MQTT you need to setup a broker server (mosquitto is a solid open source MQTT broker running perfectly on a device like the Raspberry Pi) and then instruct all clients to publish/subscribe to it.
For shelly.cloud devices mqtt is the best and only option to implement push-updates.

Using 'homebridge-http-notification-server':

For those of you who are developing the http device by themselves I developed a pretty simple 'protocol' based on http to send push-updates.
How to implement the protocol into your http device can be read in the chapter Notification Server

Configuration:

The configuration can contain the following properties:

Basic configuration options:

  • name <string> required: Defines the name which is later displayed in HomeKit
  • switchType <string> optional (Default: "stateful"): Defines the type of the switch:
    • "stateful": A normal switch and thus the default value.
    • "stateless": A stateless switch remains in only one state. If you switch it to on, it immediately goes back to off. Configuration example is further down.
    • "stateless-reverse": Default position is ON. If you switch it to off, it immediately goes back to on. Configuration example is further down.
    • "toggle": The toggle switch is a stateful switch however does not use the statusUrl to determine the current state. It uses the last set state as the current state. Default position is OFF.
    • "toggle-reverse"": Same as "toggle" but switch default position is ON.
  • onUrl <string | [string] | urlObject | [urlObject]> required: Defines the url (and other properties when using an urlObject) which is called when you turn on the switch.
  • offUrl <string | [string] | urlObject | [urlObject]> required: Defines the url (and other properties when using an urlObject) which is called when you turn off the switch.
  • statusUrl <string | urlObject> required: Defines the url (and other properties when using an urlObject) to query the current state from the switch. By default it expects the http server to return '1' for ON and '0' for OFF leaving out any html markup.
    You can change this using statusPattern option.

Advanced configuration options:

  • serialNumber <string> optional (Default: "SW01"): Defines a custom serial number shown in the home app.
  • statusPattern <string> optional (Default: "1"): Defines a regex pattern which is compared to the body of the statusUrl. When matching the status of the switch is set to ON otherwise OFF. Some examples.
  • statusCache <number> optional (Default: 0): Defines the amount of time in milliseconds a queried state of the switch is cached before a new request is made to the http device.
    Default is 0 which indicates no caching. A value of -1 will indicate infinite caching.
  • auth <object> optional: If your http server requires authentication you can specify your credential in this object. It uses those credentials for all http requests and thus overrides all possibly specified credentials inside an urlObject for onUrl, offUrl and statusUrl.
    The object can contain the following properties:
    • username <string> required
    • password <string> required
    • sendImmediately <boolean> optional (Default: true): When set to true the plugin will send the credentials immediately to the http server. This is best practice for basic authentication.
      When set to false the plugin will send the proper authentication header after receiving an 401 error code (unauthenticated). The response must include a proper WWW-Authenticate header.
      Digest authentication requires this property to be set to false!
  • httpMethod deprecated <string> optional: If defined it sets the http method for onUrl and offUrl. This property is deprecated and only present for backwards compatibility. It is recommended to use an [urlObject] to set the http method per url.
  • timeout <integer> optional (Default: 1000): When using a stateless switch this timeout in milliseconds specifies the time after which the switch is reset back to its original state.
  • pullInterval <integer> optional: The property expects an interval in milliseconds in which the plugin pulls updates from your http device. For more information read pulling updates.
    (This option is only supported when switchType is "stateful")
  • multipleUrlExecutionStrategy <string> optional (Default: "parallel"): Defines the strategy used when executing multiple urls. The following are available:
    • "parallel": All urls are executed in parallel. No particular order is guaranteed. Execution as fast as possible.
    • "series": All urls are executed in the given order. Each url must complete first before the next one is executed.
      When using series execution you can also have a look at the delay url.
  • debug <boolean> optional: If set to true debug mode is enabled and the plugin prints more detailed information.

Below are two example configurations. One is using simple string urls and the other is using simple urlObjects.
Both configs can be used for a basic plugin configuration.

{
    "accessories": [
        {
          "accessory": "HTTP-SWITCH",
          "name": "Switch",
          
          "switchType": "stateful",
          
          "onUrl": "http://localhost/api/switchOn",
          "offUrl": "http://localhost/api/switchOff",
          
          "statusUrl": "http://localhost/api/switchStatus"
        }   
    ]
}
{
    "accessories": [
        {
          "accessory": "HTTP-SWITCH",
          "name": "Switch",
          
          "switchType": "stateful",
          
          "onUrl": {
            "url": "http://localhost/api/switchOn",
            "method": "GET"
          },
          "offUrl": {
            "url": "http://localhost/api/switchOff",
            "method": "GET"
          },
          
          "statusUrl": {
            "url": "http://localhost/api/switchStatus",
            "method": "GET"
          }
        }   
    ]
}

UrlObject

A urlObject can have the following properties:

  • url <string> required: Defines the url pointing to your http server
  • method <string> optional (Default: "GET"): Defines the http method used to make the http request
  • body <any> optional: Defines the body sent with the http request. If value is not a string it will be converted to a JSON string automatically.
  • strictSSL <boolean> optional (Default: false): If enabled the SSL certificate used must be valid and the whole certificate chain must be trusted. The default is false because most people will work with self signed certificates in their homes and their devices are already authorized since being in their networks.
  • auth <object> optional: If your http server requires authentication you can specify your credential in this object. When defined the object can contain the following properties:
    • username <string> required
    • password <string> required
    • sendImmediately <boolean> optional (Default: true): When set to true the plugin will send the credentials immediately to the http server. This is best practice for basic authentication.
      When set to false the plugin will send the proper authentication header after receiving an 401 error code (unauthenticated). The response must include a proper WWW-Authenticate header.
      Digest authentication requires this property to be set to false!
  • headers <object> optional: Using this object you can define any http headers which are sent with the http request. The object must contain only string key value pairs.
  • requestTimeout <number> optional (Default: 20000): Time in milliseconds specifying timeout (Time to wait for http response and also setting socket timeout).
  • repeat <number> optional (Default: 1): Defines how often the execution of this urlObject should be repeated.
    Notice that this property only has an effect on ulrObject specified in onUrl or offUrl. Also have a look at the multipleUrlExecutionStrategy property. Using "parallel" execution could result in unpredictable behaviour.
  • delayBeforeExecution <number> optional (Default: 0): Defines the time in milliseconds to wait before executing the urlObject.
    Notice that this property only has an effect on ulrObject specified in onUrl or offUrl. Also have a look at the multipleUrlExecutionStrategy property.

Below is an example of an urlObject containing the basic properties:

{
  "url": "http://example.com:8080",
  "method": "GET",
  "body": "exampleBody",
  
  "strictSSL": false,
  
  "auth": {
    "username": "yourUsername",
    "password": "yourPassword"
  },
  
  "headers": {
    "Content-Type": "text/html"
  }
}

MQTTObject

A mqttObject can have the following properties:

Basic configuration options:
  • host <string> required: Defines the host of the mqtt broker.
  • port <number> optional (Default: 1883): Defines the port of the mqtt broker.
  • credentials <object> optional: Defines the credentials used to authenticate with the mqtt broker.
    • username <string> required
    • password <string> optional
  • subscriptions <object | array> required: Defines an array (or one single object) of subscriptions.
    • topic <string> required: Defines the topic to subscribe to.
    • characteristic <string> required: Defines the characteristic this subscription updates.
    • messagePattern <string> optional: Defines a regex pattern. If messagePattern is not specified the message received will be used as value. If the characteristic expects a boolean value it is tested if the specified regex is contained in the received message. Otherwise the pattern is matched against the message and the data from regex group can be extracted using the given patternGroupToExtract.
    • patternGroupToExtract <number> optional (Default: 1): Defines the regex group of which data is extracted.
Advanced configuration options:
  • protocol <string> optional (Default: "mqtt"): Defines protocol used to connect to the mqtt broker
  • qos <number> optional (Default: 1): Defines the Quality of Service (Notice, the QoS of the publisher must also be configured accordingly).
    In contrast to most implementations the default value is 1.
    • 0: 'At most once' - the message is sent only once and the client and broker take no additional steps to acknowledge delivery (fire and forget).
    • 1: 'At least once' - the message is re-tried by the sender multiple times until acknowledgement is received (acknowledged delivery).
    • 2: 'Exactly once' - the sender and receiver engage in a two-level handshake to ensure only one copy of the message is received (assured delivery).
  • clientId <string> optional (Default: 'mqttjs_' + Math.random().toString(16).substr(2, 8)): Defines clientId
  • keepalive <number> optional (Default: 60): Time in seconds to send a keepalive. Set to 0 to disable.
  • clean <boolean> optional (Default: true): Set to false to receive QoS 1 and 2 messages while offline.
  • reconnectPeriod <number> optional (Default: 1000): Time in milliseconds after which a reconnect is tried.
  • connectTimeout <number> optional (Default: 30000): Time in milliseconds the client waits until the CONNECT needs to be acknowledged (CONNACK).

Below is an example of an mqttObject containing the basic properties for a switch service:

{
  "host": "127.0.0.1",
  "port": 1883,
  
  "credentials": {
    "username": "yourUsername",
    "password": "yourPassword"
  },
  
  "subscriptions": [
    {
      "topic": "your/topic/here",
      "characteristic": "On",
      "messagePattern": "on"
    }
  ]
}

Stateless Switch

Since OFF is the only possible state you do not need to declare offUrl and statusUrl

{
    "accessories": [
        {
          "accessory": "HTTP-SWITCH",
          "name": "Switch",
          
          "switchType": "stateless",
          
          "timeout": 1000,
          
          "onUrl": "http://localhost/api/switchOn"
        }   
    ]
}  

Reverse Stateless Switch

Since ON is the only possible state you do not need to declare onUrl and statusUrl

{
    "accessories": [
        {
          "accessory": "HTTP-SWITCH",
          "name": "Switch",
          
          "switchType": "stateless-reverse",
          
          "timeout": 1000,
          
          "offUrl": "http://localhost/api/switchOff"
        }   
    ]
}

Multiple On or Off Urls

If you wish to do so you can specify an array of urls or urlObjects (onUrl or offUrl) when your switch is a stateless switch or a reverse-stateless switch.
This is not possible with a normal stateful switch.

Below are two example configurations of an stateless switch with three urls. One is using simple string array and the other is using simple urlObject arrays.

{
    "accessories": [
        {
          "accessory": "HTTP-SWITCH",
          "name": "Switch",
          
          "switchType": "stateless",
          "onUrl": [
            "http://localhost/api/switch1On",
            "http://localhost/api/switch2On",
            "http://localhost/api/switch3On"
          ]
        }   
    ]
}
{
    "accessories": [
        {
          "accessory": "HTTP-SWITCH",
          "name": "Switch",
          
          "switchType": "stateless",
          "onUrl": [
            {
              "url": "http://localhost/api/switch1On"
            },
            {
              "url": "http://localhost/api/switch2On"
            },
            {
              "url": "http://localhost/api/switch3On"
            }
          ]
        }   
    ]
}

The 'delay(...)' url

When using multiple urls and "series" as multipleUrlExecutionStrategy you can also specify so called delay urls in the onUrl or offUrl arrays. This could be used to guarantee a certain delay between two urls.
The delay url has the following pattern: "delay(INTEGER)" where 'INTEGER' is replaced with the delay in milliseconds.

Here is an example:

{
    "accessories": [
        {
          "accessory": "HTTP-SWITCH",
          "name": "Delayed Switch",
          
          "switchType": "stateless",
          "multipleUrlExecutionStrategy": "series",
          
          "onUrl": [
            "http://localhost/api/switch1On",
            "delay(1000)",
            "http://localhost/api/switch2On"
          ]
        }   
    ]
}

Examples for custom statusPatterns

The statusPattern property can be used to change the phrase which is used to identify if the switch should be turned on or off. So when you want the switch to be turned on when your server sends "true" in the body of the http response you could specify the following pattern:

{
    "statusPattern": "true"
}

However using Regular Expressions much more complex patterns are possible. Let's assume your http enabled device responds with the following json string as body, where one property has an random value an the other indicates the status of the switch:

{
    "perRequestRandomValue": 89723789,
    "switchState": true
}

Then you could use the following pattern:

{
    "statusPattern": "{\n    \"perRequestRandomValue\": [0-9]+,\n    \"switchState\": true\n}"
}

Note: The statusPattern must be placed on the same level as the statusUrl property, not inside the statusUrl object. See below for example.

{
    "statusUrl": {
     },
    "statusPattern": "....",
}

More on how to build regex patterns: https://www.w3schools.com/jsref/jsref_obj_regexp.asp

Notification Server

homebridge-http-switch can be used together with homebridge-http-notification-server in order to receive updates when the state changes at your external program. For details on how to implement those updates and how to install and configure homebridge-http-notification-server, please refer to the README of the repository first.

Down here is an example on how to configure homebridge-http-switch to work with your implementation of the homebridge-http-notification-server.

{
    "accessories": [
        {
          "accessory": "HTTP-SWITCH",
          "name": "Switch",
          
          "notificationID": "my-switch",
          "notificationPassword": "superSecretPassword",
          
          "onUrl": "http://localhost/api/switchOn",
          "offUrl": "http://localhost/api/switchOff",
          
          "statusUrl": "http://localhost/api/switchStatus"
        }   
    ]
}
  • notificationID is an per Homebridge instance unique id which must be included in any http request.
  • notificationPassword is optional. It can be used to secure any incoming requests.

To get more details about the configuration have a look at the README.

Available characteristics (for the POST body)

Down here are all characteristics listed which can be updated with an request to the homebridge-http-notification-server

  • characteristic "On": expects a boolean value

homebridge-http-switch's People

Contributors

daberlin avatar dependabot[bot] avatar github0013 avatar supereg avatar yenba avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

homebridge-http-switch's Issues

Use notification sever also for stateless switches

Currently the notificationID is only registered into the notification server for stateful switches.

But a notification hook url makes also sense to switch on a stateless switch as a rising edge.
After the timeout it will be return to its original state.

Update: I understood something wrong. If the status is set via notification server the onUrl isn't called. I thought the notification could be used as a web hook for the switch. But that's not working.
Is such a feature planed?

Thank you for this useful project!

Is this possible with the current release?

Hi,

I have a fire place which I can turn of and on with the same http post command (url)
But to turn it of, I have to sent it twice
There is no status url

So I want a simple switch which sends this command to turn it on
"http://localhost:8282/hubs/woonkamer/devices/openhaard/commands/power_toggle"

And sends the same url twice to turn off

I cannot use stateful, because I have no status url and I cannot use stateless because for of I have to sent the url twice.

Any help is welcome.

Beste regards,
Rien

LG HomeBot support

How can I configure the plugin to get the switch status from this page? I gave the data that is displayed in the browser. Link format ends with /status.txt

There is also a battery charge level here, and it would be nice to see it in Homekit.

The status of the switch must be taken from the parameter JSON_ROBOT_STATE

Thank!

JSON_ROBOT_STATE="CHARGING" JSON_BATTPERC="100" LGSRV_VERSION="lg.srv, V2.34 compiled 10.01.2016, by BigBadaBoom" LGSRV_SUMCMD="0" LGSRV_SUMCMDSEC="0.000000" LGSRV_NUMHTTP="12" CPU_IDLE="82.39" CPU_USER="5.14" CPU_SYS="12.45" CPU_NICE="0.00" JSON_TURBO="false" JSON_REPEAT="false" JSON_MODE="SB" JSON_VERSION="16552" JSON_NICKNAME="HOMBOT" CLREC_CURRENTBUMPING="20759" CLREC_LAST_CLEAN="2018/11/29/20/23/17.252300"

`

how to use the custom statusPattern

Can you please help me ?
I dont know what I am doing wrong...

code

cmd

[2018-11-22 09:06:42] [shelly2 2] Body of status response is: '{"ison":true,"has_timer":false,"overpower":false,"is_valid":true}'
[2018-11-22 09:06:42] [shelly2 2] Switch is currently OFF

Can you please help me to find the right statusPattern?

Config question

Describe the bug
I am trying to use a switch to send an http command to a local URL.

Expected behavior
I was expecting that when switching the switch "On" on HomeKit, it would send the URL and then switch off after a set amount of time

To Reproduce
Steps to reproduce the behavior:
Switch the switch "on"

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

  • homebridge: 0.4.50
  • homebridge-http-switch: 0.5.24

Configuration
"accessories": [
{
"accessory": "HTTP-SWITCH",
"name": "Night Switch",
"switchType": "stateless",
"timeout": 10,
"onUrl": "http://username:password@192.168.1.44/api/HomebridgeTEST"
}
],

Additional context
It does not appear to send the http command. Here is the details from the Homebridge Log file
[9/12/2019, 4:12:51 PM] [Night Switch] Error occurred setting state of switch: ESOCKETTIMEDOUT
[9/12/2019, 4:12:51 PM] [Night Switch] { Error: ESOCKETTIMEDOUT
at ClientRequest. (/usr/local/lib/node_modules/homebridge-http-switch/node_modules/request/request.js:816:19)
at Object.onceWrapper (events.js:286:20)
at ClientRequest.emit (events.js:198:13)
at Socket.emitRequestTimeout (_http_client.js:662:40)
at Object.onceWrapper (events.js:286:20)
at Socket.emit (events.js:198:13)
at Socket._onTimeout (net.js:442:8)
at ontimeout (timers.js:436:11)
at tryOnTimeout (timers.js:300:5)
at listOnTimeout (timers.js:263:5) code: 'ESOCKETTIMEDOUT', connect: false }
[9/12/2019, 4:12:51 PM] [Night Switch] Resetting switch to OFF

Set status form url

Hello, I have an problem with status url. When I'm adding url status, it don't have coverage on real states. Link for reading status is for example: https://svr1.supla.org/direct/554/yDzzMYYMmUN/read
output for curl is:
{"connected":true,"on":false}
I think that's a problem is a response for this url. How can I can fix this? I don't have any option to change server response.

My switch isn't showing in the Home-App

Hello!

At first thank you for the great plug-in it looks very nice but unfortunately Home doesn't show my switch at all.

I set up everything fine and also I got no errors while running.

I also updatet homebrige, reloaded the http-switch plugin and it still wont work for me.

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

  • homebridge: 0.4.45
  • homebridge-http-switch: 0.5.2

Configuration

{
        "bridge": {
                "name": "Homeserver",
                "username": "CC:22:3D:E3:CE:32",
                "port": 51826,
                "pin": "111-11-111"
        },


        "accessories": [{
                        "accessory": "AppleTVTheaterMode",
                        "name": "AppleTV",
                        "credentials": "7B84BB0-6DS4-48E63-89B9-321"
                },
                {
                        "accessory": "HTTP-SWITCH",
                        "name": "Hausture",

                        "switchType": "stateless",

                        "timeout": 5000,

                        "onUrl": "http://192.168.178.41/toggle"
                }
        ],

        "platforms": [{
                        "platform": "Hue",
                        "users": {
                                "001788FFFExxxxx": "xxxxxxxxxxxxxxx"
                        },
                        "lights": true,
                        "nupnp": false
                }

        ]
}

My Homebridge.log seems to be correct. But my "Hausture" wont show up in the Home app.

[2018-9-14 14:25:08] Loaded config.json with 1 accessories and 2 platforms.
[2018-9-14 14:25:08] ---
[2018-9-14 14:25:12] Loaded plugin: homebridge-dacp
[2018-9-14 14:25:12] Registering platform 'homebridge-dacp.DACP'
[2018-9-14 14:25:12] ---
[2018-9-14 14:25:13] Loaded plugin: homebridge-esplock
[2018-9-14 14:25:13] Registering accessory 'homebridge-esplock.EspLock'
[2018-9-14 14:25:13] ---
[2018-9-14 14:25:15] Loaded plugin: homebridge-http-switch
[2018-9-14 14:25:15] Registering accessory 'homebridge-http-switch.HTTP-SWITCH'
[2018-9-14 14:25:16] ---
[2018-9-14 14:25:18] Loaded plugin: homebridge-hue
[2018-9-14 14:25:18] Registering platform 'homebridge-hue.Hue'
[2018-9-14 14:25:18] ---
[2018-9-14 14:25:18] Loaded plugin: homebridge-lock
[2018-9-14 14:25:18] Registering accessory 'Homebridge – Door Lock.HTTPLock'
[2018-9-14 14:25:18] ---
[2018-9-14 14:25:19] Loaded plugin: homebridge-theater-mode
[2018-9-14 14:25:19] Registering accessory 'homebridge-theater-mode.AppleTVTheaterMode'
[2018-9-14 14:25:19] ---
[2018-9-14 14:25:19] Loading 2 platforms...
[2018-9-14 14:25:19] [Kein Name] Initializing DACP platform...
[2018-9-14 14:25:19] [Kein Name] DACP Platform Plugin Loaded - Version 0.9.2
[2018-9-14 14:25:19] [Kein Name] Found accessory in config: "Fernseher"
[2018-9-14 14:25:19] [Kein Name] Initializing platform accessory 'Fernseher'...
[2018-9-14 14:25:19] [Kein Name] Initializing Hue platform...
[2018-9-14 14:25:19] [Kein Name] homebridge-hue v0.10.0, node v8.11.4, homebridge v0.4.45
[2018-9-14 14:25:19] Loading 1 accessories...
[2018-9-14 14:25:19] [AppleTV] Initializing AppleTVTheaterMode accessory...
[2018-9-14 14:25:19] [Kein Name] Starting DACP browser...
[2018-9-14 14:25:21] [Kein Name] The accessory Fernseher is announced as 192.168.178.42:3689.
[2018-9-14 14:25:21] [Kein Name] It's an AppleTV5,3 named TV
[2018-9-14 14:25:21] [Kein Name] Attempting to reconnect to Fernseher in 0.1 seconds.
[2018-9-14 14:25:21] [Kein Name] Connecting to Fernseher (192.168.178.42:3689)
[2018-9-14 14:25:21] [Kein Name] Creating status connection to 192.168.178.42:3689
Established connection to 192.168.178.42:3689 with session ID 65
[2018-9-14 14:25:23] [Kein Name] Connected to TV
[2018-9-14 14:25:23] [Kein Name] Creating properties connection to 192.168.178.42:3689
[2018-9-14 14:25:24] [AppleTV] Opened connection to AppleTV
[2018-9-14 14:25:25] [Kein Name] Philips hue: Philips BSB002 bridge v1806051111, api v1.26.0
[2018-9-14 14:25:26] [Kein Name] Philips hue: 3 accessories
[2018-9-14 14:25:26] [Kein Name] masked debug info dumped to /home/pi/.homebridge/homebridge-hue.json.gz
[2018-9-14 14:25:26] [Kein Name] Initializing platform accessory 'Philips hue'...
[2018-9-14 14:25:26] [Kein Name] Philips hue: 3 services
[2018-9-14 14:25:26] [Kein Name] Initializing platform accessory 'Vitrine'...
[2018-9-14 14:25:26] [Kein Name] Initializing platform accessory 'Bar Beleuchtung'...
Setup Payload:
X-HM://0023RHWCIOHLG
Scan this code with your HomeKit app on your iOS device to pair with Homebridge:

Or enter this code with your HomeKit app on your iOS device to pair with Homebridge:

┌────────────┐     
│ 111-11-111            │     
└────────────┘     

[2018-9-14 14:25:26] Homebridge is running on port 51826.

I noticed that "Hausture" wasn't initialized in this log which came from start Homebridge automatically after reboot. When I use $ homebridge, it will initialized but still not showing in my App.

I just deleted my homebridge from Home and gave it a new identity. It works now.

Zeptrion http Switch

Hello

This is not an issue.

Inside the manual of my switch the channel notify is described by this:

"This web service is very special because it will not return immediately! It gives a device (a HTTP server) a chance to notify the requesting client as soon as something has happened in the device. The device will keep this request open until one of the channels has changed its state. Then the device will send the response. The response looks similar to that of a /zrap/chscan service. To be nice to naive clients each /zrap/chnotify request will also get a response after 30 seconds, even if no channel has changed its state! After each response the client must restart a new /zrap/chnotify to keep track of every state change."

When I query the state with Postman (http://zapp-17170017.hal.abc.ch/zrap/chnotify/?ch1) I get the following XML response:

0 = OFF
100 = ON

 <?xml version="1.0" encoding="US-ASCII"?>
 <chnotify>
     <ch1>
        <val>0</val>
     </ch1>
</chnotify>

My regex to query the switch state is /<val>100</ and use it as the statusPattern

I build the following JSON for the string.

    {
        "accessory": "HTTP-SWITCH",
        "name": "DEMO Eingang Licht",
        "switchType": "stateful",
        "statusPattern": "/<val>100</",
        "statusCache": "30000",
        "pullInterval": "35000",
        "onUrl": {
            "url": "http://zapp-17170017.hal.abc.ch/zrap/chctrl/ch1/?cmd=on",
            "method": "POST"
        },
        "offUrl": {
            "url": "http://zapp-17170017.hal.abc.ch/zrap/chctrl/ch1/?cmd=off",
            "method": "POST"
        },
        "statusUrl": {
            "url": "http://zapp-17170017.hal.abc.ch/zrap/chnotify/?ch1",
            "method": "GET"
        }
    }

I got inside the Hombridge log the following events.

Error occurred while pulling update from switch: ESOCKETTIMEDOUT
getStatus() failed: ESOCKETTIMEDOUT

My question is, do I something wrong or does the switch with the notify behavior not work with homebridge-http-switch?

Mqtt config

Hi is this config right for mqtt or how does it have to Look. Got. noch reaction when topic Is sent.

mosquitto_pub -h localhost -t 'siedle/cmnd' -m ring_E_D

{
"accessory": "HTTP-SWITCH",
"name": "Türgong",
"switchType": "toggle",
"timeout": 1000,
"debug": true,
"onUrl": "http://192.168.0.50:5005/clipall/fury.mp3/5",
"offUrl": "http://192.168.0.50:5005/clipall/fury.mp3/5",
"mqtt":{
"host": "192.168.0.50",
"subscriptions": [
{
"topic": "siedle/cmnd",
"messagePattern": "ring_E_D",
"characteristic": "On"
}
]

    }}

Says ring_E_D has wrong characteristic
Why Not working with stateless Switch Need it for my doorbell

Challenges when talking to Python http.server for HTTP POST

Greetings,

First let me say thank you for the creation of such a well thought out solution. I'm certain that my issue is relative to something that I've misunderstood.

I've written a basic server using the Python 3.5 http.server module. This server is configured to respond to GET and POST requests. For testing outside of HomeKit I've written a tool in PHP that successfully demonstrates the intended use of the Python based server. Observing packet captures when the test tools are used reveals that the POST is about 36 bytes in length.

Observing packet captures when attempting to use the homebridge-http-switch reveals that the POST is 0 bytes in length.

I'd be most grateful for your thoughts as to what might be the cause.

Thank you, again.

Packet Capture for http-switch communication:
screenshot from 2018-12-30 20-42-09

Packet Capture for test Utility:
screenshot from 2018-12-30 20-44-01

Output of the http.server module running my basic Python server:
screenshot from 2018-12-30 20-44-45

No answer with Version 0.5.20

After updating to Version 0.5.20 all devices are shown as offline (not answering).

The Log shows "[Steckdose 0] getStatus() http request returned http error code: 200".

Without digging deeper… The Status-URL is somewhat broken. Because the MQTT-Stuff is received properly an written to the Log "[Steckdose 0] MQTT updating characteristic On to false".

Every device has a statusPattern set.

Repeat STATELESS button with same http command multiple times with a delay.

Is your feature request related to a problem? Please describe.
Not really a problem.
I have an Auping connect bed and currently use this plugin to rise or lower the bed using https calls like this:

"url" : "http://IP:80/api/cbu/motor?move=1&cbu=0&motor=2",
"method" : "GET",
"headers" : {
"accept" : "/",
"connection" : "keep-alive",
"accept-charset" : "utf-8",
"proxy-connection" : "keep-alive",
"host" : "IP:80",
"accept-language" : "en-us",
"user-agent" : "Auping%20Connect/17 CFNetwork/976 Darwin/18.2.0",
"X-Key" : "xxxx",
"accept-encoding" : "gzip, deflate"

However, this only moves the bed a little bit.
I have to do this action 8 times to get the bed to a good level.
I currently use the series option and add a
},
"delay(1000)",
{ in between the URL ubjects.
This unfortunately makes my config.json file huge.

Describe the solution you'd like
I would love an option where you can add 2 extra parameters to a URL object.
==> Repeat:
==> DelayBeforeRepeat

"url" : "http://IP:80/api/cbu/motor?move=1&cbu=0&motor=2",
"method" : "GET",
"Repeat": 6,
"DelayBeforeRepeat": 1000,

"headers" : {
"accept" : "/",
"connection" : "keep-alive",
"accept-charset" : "utf-8",
"proxy-connection" : "keep-alive",
"host" : "IP:80",
"accept-language" : "en-us",
"user-agent" : "Auping%20Connect/17 CFNetwork/976 Darwin/18.2.0",
"X-Key" : "xxxx",
"accept-encoding" : "gzip, deflate"

Thanks for the great work. Love the plugin!

Getting "keyword alert" at start

I have this component setup and working great on two Homebridge instances. In only one of them, I get this when starting:

homebridge-http-base package.json does not contain the keyword 'homebridge-plugin'

Anything I can do about it?

Group switch’s

Could you please add a feature to group accessories under 1 accessory?
Thanks

getStatus() Response from server

Hello, I have an Arduino(esp8266) being interfaced with my homebridge setup running on my raspberry pi. I've gotten both computers to communicate with each other and I'm able to process requests on the arduino sent by the homebridge-http-switch plugin but I cant figure out how to send the statusUrl response. On the README.md, it says the plugin "expects to return 0 for OFF or 1 for ON without any html markup". I cant figure out what kind of response I should have the Arduino send to the homebridge to stop getting the getStatus() failed: Parse Error. Any help would be appreciated. Thanks

Stateful switch not retrieving status after Homebridge restart

After restarting homebridge, the stateful http switch doesn't call to get its initial status, it gets status only when the switch is actively changed.

If the switch is on after restarting homebridge I would expect it to be initialized as "on".

I also tried to play with the "statusCache" option but it doesn't seem to fix it.

─ homebridge @ 0.4.52
─ homebridge-http-switch @ 0.5.27

Configuration

{
            "accessory": "HTTP-SWITCH",
            "name": "Marantz",
            "switchType": "stateful",
            "debug": false,
            "pullInterval": 2000,
            "statusCache": -1,
            "onUrl": {
                "url": "http://10.0.0.6:8080/goform/AppCommand.xml",
                "method": "POST",
                "body": "<?xml version=\"1.0\" encoding=\"utf-8\" ?><tx><cmd id=\"1\">SetPower</cmd><zone>Main</zone><value>ON</value></tx>",
                "headers": {
                    "Content-Type": "application/xml"
                }
            },
            "offUrl": {
                "url": "http://10.0.0.6:8080/goform/AppCommand.xml",
                "method": "POST",
                "body": "<?xml version=\"1.0\" encoding=\"utf-8\" ?><tx><cmd id=\"1\">SetPower</cmd><zone>Main</zone><value>STANDBY</value></tx>",
                "headers": {
                    "Content-Type": "application/xml"
                }
            },
            "statusUrl": {
                "url": "http://10.0.0.6:8080/goform/AppCommand.xml",
                "method": "POST",
                "body": "<?xml version=\"1.0\" encoding=\"utf-8\" ?><tx><cmd id=\"1\">GetAllZonePowerStatus</cmd></tx>",
                "headers": {
                    "Content-Type": "application/xml"
                }
            },
            "statusPattern": ".*ON.*"
        }

Feature Request Switch Subtype "Valve"

Hi,

I would like to use "homebridge-http-switch" to switch my valves for watering the garden.
Is it possible to change the device type to "valve"? (iOS11 supports these new "switches", which turn off after a specific time…)

Thx,

desq

Using the POST method in a UrlObj

Hello, me again.

Should we expect to be able to use a POST method in our UrlObj? I ask because packet captures of these show zero bytes:

image

Configure state request socket timeout

I'm using http-switch to connect to the Nissan Leaf online service to get the status of the charger. The http request for the charger state is working, but it seems to be slightly too slow to respond.

I typically get "ESOCKETTIMEDOUT" errors, with the occasional state request working. I'd love to be able to configure the socket timeout for this request to be more forgiving.

Stateless switch with too long delay()

Hi,
first of all, thank you for this plugin, it's perfect!

I have a stateless switch with delay(13000) between two URLs.

"onUrl": [
  "http://localhost/api/switch1On",
  "delay(13000)",
  "http://localhost/api/switch2On"
]

The problem is, that the delay is too long. When I ask Siri to turn the switch on, she replies "Sorry, I couldn't hear back from your devices".
Is there a way you could add a typical "timeout : 1000" response, the same way it works with single URL switches? So before it executes rest of the onUrl, it already replies to Homebridge.

Thank you.
Best regards and Merry Christmas.
Lukas

help with using the custom statusPattern

Hi
I have a status that is very unstructured

The entries @678ftp , @456gtr and @123df5 are the relay devices.
"value": 0 is the status of on or off (shows 1 when on)

what is the correct way to search for a device and then it's status using statusPattern?

{
  "success": true,
  "@678ftp": {
    "type": "RELAY QS-R-S5",
    "firmware": "32",
    "epoch": "1587511930",
    "rssi": "55%",
    "value": 0
  },
  "@456gtr": {
    "type": "RELAY QS-R-S5",
    "firmware": "32",
    "epoch": "1587511930",
    "rssi": "39%",
    "value": 0
  },
  "@123df5": {
    "type": "RELAY QS-R-S5",
    "firmware": "32",
    "epoch": "1587511933",
    "rssi": "58%",
    "value": 0
  }

On and off works perfectly it is the status that is not working. I have the following:

            "statusUrl": "http://qwikswitch.com/api/v1/state/XXX/",
            "statusPattern": "/@456gtr0/\u000balue=1",
            "http_method": "GET"

Caching stateful switch state locally

When there are a lot of accessories, many of them http-based and running on low-power hardware like ESP8266, updating their state in Home can sometimes take a long time.

If there are http switches configured with the notification server support, their state reported to Home app could be sourced from recently known state by the plugin, not the accessory itself, since its state is known in all cases (provided the notification server settings are configured properly).

Even if there is an issue with the notification server not receiving the state changes, there'a also the pull timer already that could make sure the plugin has somewhat current state of the accessory.

I'd like the http-switch accessory to not retrieve the http accessory's state from it every time it's requested by the Home app.

If you want, I can create a PR with necessary changes and we can discuss the changes there.

Log error/error on Home tile

This is a really useful module!

I'm having a couple of minor errors.

1/ A stateless switch rebooting 3 Raspberry Pis, each running lighttpd and PHP 7.3-FPM. This seems to work but generates the following error:

[2019-11-12 10:12:44] [Reboot Blinds] setStatus() doing http request...
[2019-11-12 10:12:50] [Reboot Blinds] 2 requests successfully set switch to ON; 1 encountered and error:
[2019-11-12 10:12:50] [Reboot Blinds] [ { index: 0,
    error: { Error: socket hang up
    at createHangUpError (_http_client.js:331:15)
    at Socket.socketOnEnd (_http_client.js:423:23)
    at emitNone (events.js:111:20)
    at Socket.emit (events.js:208:7)
    at endReadableNT (_stream_readable.js:1056:12)
    at _combinedTickCallback (internal/process/next_tick.js:138:11)
    at process._tickCallback (internal/process/next_tick.js:180:9) code: 'ECONNRESET' } } ]

Here is the relevant config excerpt:

{
"accessory": "HTTP-SWITCH",
"name": "Reboot Blinds",
"switchType": "stateless",
"timeout": 20000,
"multipleUrlExecutionStrategy": "series",
"onUrl":
[
"http://[internal IP]/reboot.php",
"delay(1000)",
"http://[internal IP]/reboot.php",
"delay(1000)",
"http://[internal IP]/reboot.php"
]
}

It also leaves an exclamation mark on the Home tile.

Using UrlObjects and/or specifying httpmethod doesn't seem to make a difference. I have a more complex switch in which I've set those options and I get the same error.

2/ A stateless switch pinging 8 URLs in order. This is to issue an http command stopping 8 blinds moving. The blind controls are not particularly reliable. Although the switch works well sometimes the response from the server is a 500 error with a webpage which contains 'Error - cannot read property'. (This can be seen in the 'value' line below.) This doesn't actually mean it hasn't worked, usually.

Here is the log extract:

[2019-11-12 10:20:33] [Stop Blinds] 4 requests successfully set switch to ON; 4 encountered and error:
[2019-11-12 10:20:34] [Stop Blinds] [ { index: 2,
    error: Error: HTTP request returned with error code 500
    at results.forEach (/usr/local/lib/node_modules/homebridge-http-switch/index.js:448:32)
    at Array.forEach (<anonymous>)
    at http.multipleHttpRequests.results (/usr/local/lib/node_modules/homebridge-http-switch/index.js:438:21)
    at multipleUrlExecutionStrategy (/usr/local/lib/node_modules/homebridge-http-switch/node_modules/homebridge-http-base/http.js:143:13)
    at err (/usr/local/lib/node_modules/homebridge-http-switch/node_modules/async/dist/async.js:2959:19)
    at wrapper (/usr/local/lib/node_modules/homebridge-http-switch/node_modules/async/dist/async.js:272:20)
    at replenish (/usr/local/lib/node_modules/homebridge-http-switch/node_modules/async/dist/async.js:439:29)
    at iterateeCallback (/usr/local/lib/node_modules/homebridge-http-switch/node_modules/async/dist/async.js:428:21)
    at /usr/local/lib/node_modules/homebridge-http-switch/node_modules/async/dist/async.js:325:20
    at result (/usr/local/lib/node_modules/homebridge-http-switch/node_modules/async/dist/async.js:2957:17),
    value: '<!DOCTYPE html>\n<html lang="en">\n<head>\n<meta charset="utf-8">\n<title>Error</title>\n</head>\n<body>\n<pre>TypeError: Cannot read property &#39;00001530b87f490c92cb11ba5ea5167c&#39; of undefined<br> &nbsp; &nbsp;at Gatt.write (/usr/local/lib/node_modules/soma-ctrl/node_modules/noble/lib/hci-socket/gatt.js:526:58)<br> &nbsp; &nbsp;at NobleBindings.write (/usr/local/lib/node_modules/soma-ctrl/node_modules/noble/lib/hci-socket/bindings.js:364:10)<br> &nbsp; &nbsp;at Noble.write (/usr/local/lib/node_modules/soma-ctrl/node_modules/noble/lib/noble.js:325:19)<br> &nbsp; &nbsp;at Characteristic.write (/usr/local/lib/node_modules/soma-ctrl/node_modules/noble/lib/characteristic.js:74:15)<br> &nbsp; &nbsp;at SomaShade.stop (/usr/local/lib/node_modules/soma-ctrl/src/SomaShade.js:104:34)<br> &nbsp; &nbsp;at express.post (/usr/local/lib/node_modules/soma-ctrl/src/WebConnector.js:56:20)<br> &nbsp; &nbsp;at Layer.handle [as handle_request] (/usr/local/lib/node_modules/soma-ctrl/node_modules/express/lib/router/layer.js:95:5)<br> &nbsp; &nbsp;at next (/usr/local/lib/node_modules/soma-ctrl/node_modules/express/lib/router/route.js:137:13)<br> &nbsp; &nbsp;at Route.dispatch (/usr/local/lib/node_modules/soma-ctrl/node_modules/express/lib/router/route.js:112:3)<br> &nbsp; &nbsp;at Layer.handle [as handle_request] (/usr/local/lib/node_modules/soma-ctrl/node_modules/express/lib/router/layer.js:95:5)</pre>\n</body>\n</html>\n' },

I am wondering if there is a way to suppress/remap the response returned by the server above so that http-switch will accept it as success so the Home tile won't show an exclamation mark. Which I realise is appropriate behaviour for a 500 error, but since it ACTUALLY works in my case, I want it to show in the UI as successful.

Thanks
Mark

Group switch’s

Could you please add a feature to group accessories under 1 accessory? I saw the other one and I don’t care if the config is crowded
Thanks

Not supported

Describe the bug
Starting from 0.5.16, I get a "device not supported" in homekit (the icon of the button is now a house!)

Expected behavior

To Reproduce
Steps to reproduce the behavior:

  1. homebridge v 0.4.45
  2. http-switch v 0.5.16
  3. stateful switch with all three url (on, off, status) correctly configured

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

  • homebridge: v 0.4.45
  • homebridge-http-switch: v 0.5.16

Configuration
{
"accessory": "HTTP-SWITCH",
"switchType": "stateful",
"name": "Specchio Bagno Max",
"onUrl": "http://spbagnomax.maxhome/on",
"offUrl": "http://spbagnomax.maxhome/off",
"statusUrl": "http://spbagnomax.maxhome/status"
},
{
"accessory": "HTTP-SWITCH",
"switchType": "stateful",
"name": "Specchio Bagno Fede",
"onUrl": "http://spbagnofede.maxhome/on",
"offUrl": "http://spbagnofede.maxhome/off",
"statusUrl": "http://spbagnofede.maxhome/status"
},

Additional context
Add any other context about the problem here.

Not able to get Switch State using statusPattern

Hi there ,

Im currently using this for the Shelly1 Relay and provided is my config for this accessory. Im am not able to get current state of switch in homebridge. I can do everything else switch on and off, just not able to get current state when I exit and or restart HomeApp. I think my string pattern is not correct. When I make the call to the switch it returns
{ "ison": true, "has_timer": false } meaning the relay is on.

Can you please confirm below if I am making the right Regex expression to accommodate this response.

`"accessories": [
{
"accessory": "HTTP-SWITCH",
"name": "Truck Heater",

      "switchType": "stateful",

      "onUrl": {
        "url": "http://localhost/relay/0?turn=on",
        "method": "POST"
      },
      "offUrl": {
        "url": "http://localhost/relay/0?turn=off",
        "method": "POST"
      },
    
      "statusUrl": {
        "url": "http://localhost/relay/0/status",
        "method": "GET"
      },
"statusPattern": "{\n    \"ison\": true,\n    \"has_timer\":false\n}"

}
]`

Limit on switch number?

Hello
in the last days I added two more switches on my configuration and the last I added (some configuration as the previous ones with same hardware wemosd1 + relay) don't appear correctly on homebridge whereas I can reach them using http.
Do you know if there is a limit on how many switch can I use?
Problematic are "Irrigazione Camera", "WIFI extender", "Router Box".
My config.json extract is below:

{
"accessory": "HTTP-SWITCH",
"name": "Specchio Bagno Fede",
"onUrl": "http://192.168.0.19/on",
"offUrl": "http://192.168.0.19/off",
"statusUrl": "http://192.168.0.19/status"
},
{
"accessory": "HTTP-SWITCH",
"name": "Scrivania Max",
"onUrl": "http://192.168.0.22/on",
"offUrl": "http://192.168.0.22/off",
"statusUrl": "http://192.168.0.22/status"
},
{
"accessory": "HTTP-SWITCH",
"name": "Ventola Bagno Fede",
"onUrl": "http://192.168.0.20/on",
"offUrl": "http://192.168.0.20/off",
"statusUrl": "http://192.168.0.20/status"
},
{
"accessory": "HTTP-SWITCH",
"name": "WIFI extender",
"onUrl": "http://192.168.0.12/on1",
"offUrl": "http://192.168.0.12/off1",
"statusUrl": "http://192.168.0.12/status1"
},
{
"accessory": "HTTP-SWITCH",
"name": "Irrigazione Camera",
"onUrl": "http://192.168.0.12/on2",
"offUrl": "http://192.168.0.12/off2",
"statusUrl": "http://192.168.0.12/status2"
},
{
"accessory": "HTTP-SWITCH",
"name": "Router Box",
"onUrl": "http://192.168.0.26/on",
"offUrl": "http://192.168.0.26/off",
"statusUrl": "http://192.168.0.26/status"
},
{
"accessory": "HTTP-SWITCH",
"name": "Luce Box",
"onUrl": "http://192.168.0.27/on1",
"offUrl": "http://192.168.0.27/off1",
"statusUrl": "http://192.168.0.27/status1"
},
{
"accessory": "HTTP-SWITCH",
"name": "Stampante Box",
"onUrl": "http://192.168.0.27/on2",
"offUrl": "http://192.168.0.27/off2",
"statusUrl": "http://192.168.0.27/status2"
},

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:
�[37m[2019-11-19 0:34:30]�[39m �[36m[Switch]�[39m 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>
}

Status Updating

HTTP GET changes state upon on/off command however after awhile the switch appears OFF even though GET is 1 and physical state is still on. There is no external program changing the state.

Multiple "onUrl" and "offUrl" with "stateful" switches

Can you add multiple "onUrl" and "offUrl" with "stateful" switches?
When i use this

        {
			"accessory": "HTTP-SWITCH",
			"name": "Test",
			"switchType": "stateful",
			"onUrl": [
			"http://localhost/api/switch1On",
			"http://localhost/api/switch2On"
			],
			"offUrl": [
			"http://localhost/api/switch1Off",
			"http://localhost/api/switch2Off"
			],
			"statusUrl": "http://localhost/api/powerstate",
			"pullInterval": "10000",
			"statusPattern": "false",
			"auth": {
			"username": "user",
			"password": "pass"
			  }
        }

homebridge starts with this error

[2018-9-25 21:00:07] [TV Schlafzimmer] Error occurred while parsing 'onUrl': property cannot be an array!
[2018-9-25 21:00:07] [TV Schlafzimmer] Aborting...

When i use this

        {
			"accessory": "HTTP-SWITCH",
			"name": "Test",
			"switchType": "stateful",
			"onUrl": [
			{
			"url": "http://localhost/api/switch1On"
			},
			{
			"url": "http://localhost/api/switch2On"
			}
			],
			"offUrl": [
			{
			"url": "http://localhost/api/switch1Off"
			},
			{
			"url": "http://localhost/api/switch2Off"
			}
			],
			"statusUrl": "http://localhost/api/powerstate",
			"pullInterval": "10000",
			"statusPattern": "false",
			"auth": {
			"username": "user",
			"password": "pass"
			  }
        }

homebridge crashes on start.
Would be nice if you can add this festure.

Support for HTTP POST and 'data' / 'form' elements in the post

Is your feature request related to a problem? Please describe.
While the documentation for the solution indicates that GET is the default configuration parameter for ObjUrl, it does indeed appear that it is the only option at this time. I had my ObjUrl configured for POST commands and can confirm that each of the POST (from a network packet capture standpoint) were empty. I'm not sure if this is a problem with the plugin itself, homebridge, or HomeKit.

Describe the solution you'd like
I'd like to be able to use ObjUrl parameters that are both configured for POST and that use the 'data' element of the POST as well as the 'form' element. I would like to be able to choose which parts of the POST content to use.

Ocassional random behaviour

Describe the bug
Occasionally this will hang the remote HTTP server due to not closing connection. On looking at the log I can see that the first few minutes - hours are ok.

  1. HomeKit App launched
    -All API Status requested
  2. While HomeKit App is still launched
    -Toggling a switch to on sends On status to the remote server
    -Toggling a switch to off sends Off status to the remote server
    Output when ok--
    Lights Toggle On
    new client
    GET /?LightingON HTTP/1.1
    host: 192.168.0.130
    Connection: close
    Lights Toggle Off
    new client
    GET /?LightingOFF HTTP/1.1
    host: 192.168.0.130
    Connection: close

The problem arises when the app is still open and http-switch starts requesting Status and then On/Off after every toggle command. Once this occurs, it locks up the remote server.

Output when error starts occuring--
Lights Toggle On
new client
GET /?LightingStatus HTTP/1.1
host: 192.168.0.130
Connection: close
new client
GET /?LightingON HTTP/1.1
host: 192.168.0.130
Connection: close

Lights Toggle Off
new client
GET /?LightingStatus HTTP/1.1
host: 192.168.0.130
Connection: close
new client
GET /?LightingOFF HTTP/1.1
host: 192.168.0.130
Connection: close

Expected behavior
NA

To Reproduce
Steps to reproduce the behavior:
Unable to reproduce on demand

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

Configuration
``
{
"accessory": "HTTP-SWITCH",
"name": "Tank Light",

		"switchType": "stateful",

		"httpMethod": "GET",
		"onUrl": "http://192.168.0.130/?LightingON",
		"offUrl": "http://192.168.0.130/?LightingOFF",

		"statusUrl": "http://192.168.0.130/?LightingStatus"
	},
	{
		"accessory": "HTTP-SWITCH",
		"name": "ATO Pump",

		"switchType": "stateful",

		"httpMethod": "GET",
		"onUrl": "http://192.168.0.130/?ATOON",
		"offUrl": "http://192.168.0.130/?ATOOFF",

		"statusUrl": "http://192.168.0.130/?ATOStatus"
	},
	{
		"accessory": "HTTP-SWITCH",
		"name": "Drain Pump",

		"switchType": "stateful",

		"httpMethod": "GET",
		"onUrl": "http://192.168.0.130/?DRAINON",
		"offUrl": "http://192.168.0.130/?DRAINOFF",

		"statusUrl": "http://192.168.0.130/?DrainStatus"
	},
	{
		"accessory": "HTTP-SWITCH",
		"name": "Pump Lock",

		"switchType": "stateful",

		"httpMethod": "GET",
		"onUrl": "http://192.168.0.130/?PUMPLKON",
		"offUrl": "http://192.168.0.130/?PUMPLKOFF",

		"statusUrl": "http://192.168.0.130/?PumpLKStatus"
	}


],

**Additional context**
Happens randomly until a reset of the remote HTTP Server (Arduino Ethernet)

Homebridge starts but is in the "Home" app not available

When i add this

        {
          "accessory": "HTTP-SWITCH",
          "name": "Test",
          "switchType": "stateful",
          "onUrl": "http://localhost/api/switchOn",
          "offUrl": "http://localhost/api/switchOff",
          "statusUrl": "http://localhost/api/switchState",
          "pullInterval": "10000",
          "statusPattern": "false",
          "auth": {
          "username": "user",
          "password": "pass"
          }
        }

to my config, homebridge starts normal but is in the "Home" app not available.
The pullInterval and statusPattern works.

Just asking for some help, regarding pushing a state.

I have managed to setup the HTTP Notification server with a switch.

{
            "accessory": "HTTP-SWITCH",
            "name": "Hot Water Pump Relay",
            "notificationID": "F27902",
            "onUrl": "http://192.168.113.231/relay/0?turn=on",
            "offUrl": "http://192.168.113.231/relay/0?turn=off",
            "statusUrl": "http://192.168.113.145:8183/F27902/status"
}

I have also setup a Webserver that whenever it turns on and off it sends a post request to the Notification Server. Which one should I use the notification server or could you give me an example of what to POST to the plugin to update switch state?

toggle switch shows no response in HomeKit

I tried to setup a toggle-reverse switch using your plugin but when restarting Homebridge after adding the configuration, the switch appears in Home, but shows "no response" error immediately without being able to actually toggle the switch.

logs in debug mode show a successful initialization of the switch.

As a workaround, I now created 2 stateless switches. One with the original toggle OnUrl, one with the OffUrl and both work fine.

Hence I guess there is something with the toggle switch. Maybe related to issue #32 ?

Accessory has type Switch in Homekit

I have the following configuration

    {
        "accessory": "HTTP-SWITCH",
        "name": "Light 1",
        "switchType": "stateful",
        "onUrl": "https://mydyndnssite/api/HomebridgeLighting/switchOn?light=Study",
        "offUrl": "https://mydyndnssite/api/HomebridgeLighting/switchOff?light=Study",
        "statusUrl": "https://mydyndnssite/api/HomebridgeLighting/switchStatus?light=Study"
    },
    {
        "accessory": "HTTP-SWITCH",
        "name": "Light 2",
        "switchType": "stateful",
        "onUrl": "https://mydyndnssite/api/HomebridgeLighting/switchOn?light=Front facade",
        "offUrl": "https://mydyndnssite/api/HomebridgeLighting/switchOff?light=Front facade",
        "statusUrl": "https://mydyndnssite/api/HomebridgeLighting/switchStatus?light=Front facade"
    }

All my accessories have the type Switch and I can change it to Light, Fan or Switch in the accessory's settings. Can I specify it somewhere so they would be Lights from the start?

multiple http commands in a serie

Hello,

I use "homebridge http switch" from @Supereg. It works fine but I would like to use it to go to a sequence of urls. Now I can use it with Siri to close my blinds one at the time. Is it possible to close two or more blinds or.... with only one serie of http commands.
Sorry for my bad english. Also I'm new with almost no knowledge of programming.

An other solution would be fine also.

Regards,

Luc

statusPattern ESPEasy

Hi
I'm using Sonoff basic with ESPEasy firmware and I'm unable to get the ON/OFF status.

Status Link: http://192.168.1.52/control?cmd=Status,GPIO,12

image

LOG:

image

Tested patterns:

"statusPattern": "{\n\"log\":[abc] ,\n\"plugin\":[0-9],\n\"pin\":[0-9],\n\"mode\":[abc],\n\"state\":1\n}"

Also try

"statusPattern": "{\n \"log\": ,\n\"plugin\":1, \n\"pin\":12, \n\"mode\":output, \n\"state\":1\n}"

And

"statusPattern": "{\"log\": ,\"plugin\":1, \"pin\":12, \"mode\":output, \"state\":1}"

And many more pattern options, no metter what, still I get Switch is currently OFF even when the state is 1

Full Config:

    {
        "accessory": "HTTP-SWITCH",
        "name": "EspEasy",
        "switchType": "stateful",
        "pullInterval": 3000,
        "onUrl": {
            "url": "http://192.168.1.52/control?cmd=GPIO,12,1",
            "method": "POST"
        },
        "offUrl": {
            "url": "http://192.168.1.52/control?cmd=GPIO,12,0",
            "method": "POST"
        },
        "statusUrl": {
            "url": "http://192.168.1.52/control?cmd=Status,GPIO,12",
            "method": "GET"
        },
        "statusPattern": "{\n\"log\":[abc] ,\n\"plugin\":[0-9],\n\"pin\":[0-9],\n\"mode\":[abc],\n\"state\":1\n}",
        "debug": true
    }

Hope that someone can Help

multiple switches

can we add additional switches?

I have not been able to figure out how

Basic telnet support?

Is your feature request related to a problem? Please describe.
I have a device on my intranet that accepts commands via telnet. Some of the commands are simple toggles (no response), while others return state. I'd like to use the http-switch but with single telnet commands to implement the toggle and state sniffing protocols.

Describe the solution you'd like

{
  "accessory": "HTTP-SWITCH", "name": "TOGGLE1", "switchType": "stateful",
  "onUrl": "telnet://xxx.xxx.xxx.xxx/ON-COMMAND",
  "offUrl": "telnet://xxx.xxx.xxx.xxx/OFF-COMMAND",
  "statusUrl": "telnet://xxx.xxx.xxx.xxx/STATE-REQUEST-COMMAND",
  "statusPattern": "STATE-ON-PATTERN"
}   

Where "ON-COMMAND", "OFF-COMMAND", and "STATE-REQUEST-COMMAND" are some ASCII sequences to pass via telnet. For the statusUrl, the telnet server would return a status that should match "STATE-ON-PATTERN".

Thanks a ton in advance!

Changing the Service of the Accessory

Hello,

do you think it is possible to change the Service of the Accessory in the Config ?
I have a Window Covering / Blinds with simple on/off (on=down - off=up) (no percentage etc.)
Its my goal to have a adequate symbol in the Apple Home App.

Greetings
Dominic

Service type

Hi Supereg,

Your plugin so awesome.
But i would like to recommend some feature is Service type Ex. Lamp, Light (like a old plugin) because i use you plugin with light.

Thank.

Digest auth support

Describe the bug
Basic auth is not working

Expected behavior
When using the "auth" parameter for your plugin I still get 401 not authorized for each request. I was testing the same setup but with homebridge-http and its working all fine. I would prefer using your plugin though. Could you have a look into that?

Version

Configuration
{
"accessories": [
{
"accessory": "HTTP-SWITCH",
"name": "Switch",
"switchType": "stateful",
"auth": {
"username": "myUsername",
"password": "myPassword"
},
"onUrl": "http://localhost/api/switchOn",
"offUrl": "http://localhost/api/switchOff",

      "statusUrl": "http://localhost/api/switchStatus"
    }   
]

}

Property 'statusUrl' is defined though it is not used with switchType stateless. Ignoring it!

Describe the bug
Property 'statusUrl' is defined though it is not used with switchType stateless. Ignoring it!

Expected behavior
Switchin the http switch because I used OnUrl switch switchType stateless

Version (output of npm list -g homebridge homebridge-http-switch)
/usr/local/lib
├── [email protected]
└── [email protected]

Configuration

{
	"bridge": {
		"name": "Homebridge",
		"username": "XX:XX:XX:XX:XX:XX",
		"port": XXXXX,
		"pin": "XXX-XX-XXX"
	},
	"description": "Configuration file for (e)xtended Domoticz platform.",
	"platforms": [{
		"platform": "eDomoticz",
		"name": "eDomoticz",
		"server": "127.0.0.1",
		"port": "8080",
		"ssl": 0,
		"roomid": 12,
		"mqtt": {
			"host": "127.0.0.1",
			"port": "1883",
			"topic": "domoticz/out",
			"username": "username",
			"password": "password"
		},
		"excludedDevices": []
	}],
	"accessories": [{
			"accessory": "HTTP-SWITCH",
			"name": "Zender NPO een",
			"switchType": "stateless",
			"timeout": 1000,
			"onUrl": "http://10.0.0.219/web/zap?sRef=1:0:19:36BA:72:8C9:FFFF0000:0:0:0:"
		},
		{
			"accessory": "HTTP-SWITCH",
			"name": "Zender NPO twee",
			"switchType": "stateless",
			"timeout": 1000,
			"onUrl": "http://10.0.0.219/web/zap?sRef=1:0:19:80FC:85:8C9:FFFF0000:0:0:0:"
		}, {
			"accessory": "HTTP-SWITCH",
			"name": "Zender NPO drie",
			"switchType": "stateless",
			"timeout": 1000,
			"onUrl": "http://10.0.0.219/web/zap?sRef=1:0:19:8106:85:8C9:FFFF0000:0:0:0:"
		}, {
			"accessory": "HTTP-SWITCH",
			"name": "Zender RTL vier",
			"switchType": "stateless",
			"timeout": 1000,
			"onUrl": "http://10.0.0.219/web/zap?sRef=1:0:19:84E4:86:8C9:FFFF0000:0:0:0:"
		}, {
			"accessory": "HTTP-SWITCH",
			"name": "Zender RTL vijf",
			"switchType": "stateless",
			"timeout": 1000,
			"onUrl": "http://10.0.0.219/web/zap?sRef=1:0:19:84EE:86:8C9:FFFF0000:0:0:0:"
		}, {
			"accessory": "HTTP-SWITCH",
			"name": "Zender SBS zes",
			"switchType": "stateless",
			"timeout": 1000,
			"onUrl": "http://10.0.0.219/web/zap?sRef=1:0:19:948E:8A:8C9:FFFF0000:0:0:0:"
		}, {
			"accessory": "HTTP-SWITCH",
			"name": "Zender RTL zeven",
			"switchType": "stateless",
			"timeout": 1000,
			"onUrl": "http://10.0.0.219/web/zap?sRef=1:0:19:8CAA:88:8C9:FFFF0000:0:0:0"
		}, {
			"accessory": "HTTP-SWITCH",
			"name": "Zender RTL Z",
			"switchType": "stateless",
			"timeout": 1000,
			"onUrl": "http://10.0.0.219/web/zap?sRef=1:0:19:AC26:90:8C9:FFFF0000:0:0:0:"
		}, {
			"accessory": "HTTP-SWITCH",
			"name": "Zender RTL acht",
			"switchType": "stateless",
			"timeout": 1000,
			"onUrl": "http://10.0.0.219/web/zap?sRef=1:0:19:8CB4:88:8C9:FFFF0000:0:0:0:"
		}, {
			"accessory": "HTTP-SWITCH",
			"name": "Zender SBS negen",
			"switchType": "stateless",
			"timeout": 1000,
			"onUrl": "http://10.0.0.219/web/zap?sRef=1:0:19:AC1C:90:8C9:FFFF0000:0:0:0:"
		}, {
			"accessory": "HTTP-SWITCH",
			"name": "Zender VERONICA",
			"switchType": "stateless",
			"timeout": 1000,
			"onUrl": "http://10.0.0.219/web/zap?sRef=1:0:19:9484:8A:8C9:FFFF0000:0:0:0:",
		}
	]
}

**Additional context**
Trying to zap my enigma2 box with this plugin. Been trying for few days now.

getting esclamation mark in home app when clicking on switch icon

Hi all

I am using http-switch to open/close my blinds (did not find anything better to steer the as they do not send back their position so i can only either open or close them with 2 different switches)

I use stateless-reverse mode and everything works fine besides that i get esclamation marks in the home app when I click on the icons (they still work fine)... the esclamation marks remain displayed after i clicked on it but go away when i exit and enter again the home app. However, esclamation mark comes back as soon as i Click again on it...

Does anybody know how I could get rid of the esclamation marks?

following my json file:

"bridge": {
	"name": "xsxsxsx",
	"username": "xsxsxsx",
	"port": xsxsx,
	"pin": "xxx-xx-xxx"
},
"accessories": [
	{
		"accessory": "HTTP-SWITCH",
		"name": "Switchon_EG",
		"switchType": "stateless-reverse",
		"offUrl": {
			"url": "http://xxx.xx.1.1xx/zrap/chctrl/ch1/",
			"method": "POST",
			"body": "cmd=on"
		}
	},

	{
		"accessory": "HTTP-SWITCH",
		"name": "Switchoff_EG",
		"switchType": "stateless-reverse",
		"offUrl": {
			"url": "http://xxx.xx.1.1xx/zrap/chctrl/ch1/",
			"method": "POST",
			"body": "cmd=off"
		}
	}

and a picture of my home app with the esclamation mark on the icon:
IMG_2994

Boolean with true/false

Hello again ;)
nice to see that you are activ and updates your plugin. With your help , i can controll my Enigma2 receiver with homebridge. Thanks again for that.
At this time, i use only the onUrl and the offUrl. I don´t can use the statusUrl, because the status use boolean function with true and false. The plugin doesn´t know that 0 is false and 1 is true. So the switch in the Home App is always off. It would be nice if you can add these to statusUrl.
But the receiver gives only a status if the receiver is in standby (true) or is not in standby (false).

<e2powerstate>
<e2instandby> true </e2instandby>
</e2powerstate>

So the switch in the Home App was inversely. Maybe you can also add a option which inverts the status and the switch in the Home App shows the right status.

Sorry for my bad english, it is not my first language. I hope you have understand what i want :).
Best regards.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.