diff --git a/README.md b/README.md index 2a4eab13..292df7f8 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,7 @@ This is a replacement for a Milight/LimitlessLED remote/gateway hosted on an ESP 2. This project exposes a nice REST API to control your bulbs. 3. You can secure the ESP8266 with a username/password, which is more than you can say for the Milight gateway! (The 2.4 GHz protocol is still totally insecure, so this doesn't accomplish much :). 4. Official hubs connect to remote servers to enable WAN access, and this behavior is not disableable. +5. This project is capable of passively listening for Milight packets sent from other devices (like remotes). It can publish data from intercepted packets to MQTT. This could, for example, allow the use of Milight remotes while keeping your home automation platform's state in sync. See the MQTT section for more detail. ## Supported bulbs @@ -89,7 +90,7 @@ The HTTP endpoints (shown below) will be fully functional at this point. You sho 1. `GET /settings`. Gets current settings as JSON. 1. `PUT /settings`. Patches settings (e.g., doesn't overwrite keys that aren't present). Accepts a JSON blob in the body. 1. `GET /radio_configs`. Get a list of supported radio configs (aka `device_type`s). -1. `GET /gateway_traffic/:device_type`. Starts an HTTP long poll. Returns any Milight traffic it hears. Useful if you need to know what your Milight gateway/remote ID is. Since protocols for RGBW/CCT are different, specify one of `rgbw`, `cct`, or `rgb_cct` as `:device_type. +1. `GET /gateway_traffic(/:device_type)?`. Starts an HTTP long poll. Returns any Milight traffic it hears. Useful if you need to know what your Milight gateway/remote ID is. Since protocols for RGBW/CCT are different, specify one of `rgbw`, `cct`, or `rgb_cct` as `:device_type. The path `/gateway_traffic` without a `:device_type` will sniff for all protocols simultaneously. 1. `PUT /gateways/:device_id/:device_type/:group_id`. Controls or sends commands to `:group_id` from `:device_id`. Accepts a JSON blob. The schema is documented below in the _Bulb commands_ section. 1. `POST /raw_commands/:device_type`. Sends a raw RF packet with radio configs associated with `:device_type`. Example body: ``` @@ -174,6 +175,28 @@ irb(main):004:0> client.publish('milight/0x118D/rgb_cct/1', '{"status":"ON","col This will instruct the ESP to send messages to RGB+CCT bulbs with device ID `0x118D` in group 1 to turn on, set color to RGB(255,200,255), and brightness to 100. +#### Updates + +To enable passive listening, make sure that `listen_repeats` is set to something larger than 0 (the default value of 3 is a good choice). + +To publish data from intercepted packets to an MQTT topic, configure MQTT server settings, and set the `mqtt_update_topic_pattern` to something of your choice. As with `mqtt_topic_pattern`, the tokens `:device_id`, `:device_type`, and `:group_id` will be substituted with the values from the relevant packet. + +The published message is a JSON blob containing the following keys: + +* `device_id` +* `device_type` (rgb_cct, rgbw, etc.) +* `group_id` +* Any number of: `status`, `level`, `hue`, `saturation`, `kelvin` + +As an example, if `mqtt_update_topic_pattern` is set to `milight/updates/:device_id/:device_type/:group_id`, and the group 1 on button of a Milight remote is pressed, the following update will be dispatched: + +```ruby +irb(main):005:0> client.subscribe('milight/updates/+/+/+') +=> 27 +irb(main):006:0> puts client.get.inspect +["lights/updates/0x1C8E/rgb_cct/1", "{\"device_id\":7310,\"group_id\":1,\"device_type\":\"rgb_cct\",\"status\":\"on\"}"] +``` + ## UDP Gateways You can add an arbitrary number of UDP gateways through the REST API or through the web UI. Each gateway server listens on a port and responds to the standard set of commands supported by the Milight protocol. This should allow you to use one of these with standard Milight integrations (SmartThings, Home Assistant, OpenHAB, etc.). diff --git a/data/web/index.html b/data/web/index.html index 0ccb42be..d2625332 100644 --- a/data/web/index.html +++ b/data/web/index.html @@ -31,11 +31,22 @@ .error-info:before { content: '('; } .error-info:after { content: ')'; } .header-btn { margin: 20px; } + #sniffed-traffic { max-height: 50em; overflow-y: auto; } .btn-secondary { background-color: #fff; border: 1px solid #ccc; } .inline { display: inline-block; } + .white-temp-picker { + height: 2em; + background: linear-gradient(to right, + rgb(166, 209, 255) 0%, + rgb(255, 255, 255) 50%, + rgb(255, 160, 0) 100% + ); + display: inline-block; + padding: 3px 0; + } .hue-picker { height: 2em; width: 100%; @@ -124,8 +135,9 @@