Connecting the ANAVI Light Controller with Home Assistant

TL:DR;

light:
  - platform: mqtt_json
    command_topic: "cmnd/<device-id>/color"
    state_topic: "stat/<device-id>/color"
    brightness: true
    rgb: true

Background

I recently received my ANAVI Light Controller in the mail and was excited to try it out. The easiest way to get set up is to follow Leon's excellent intro video (included below).

While you're connecting to your WiFi network, you'll have the option of setting your own MQTT broker, and here make sure here you change it from the default eclipse.org broker to the broker your Home Assistant install is using.

As the interface warns you, make certain that you grab the device ID (for future reference, the device ID is the MD5 sum of your Chip ID).

Checking your controller

If your MQTT broker also supports a Websockets connection, you can also use the demo.anavi.technology website, but if you're using a local/self-hosted MQTT broker, that's probably not the case. If you really want to make sure, you can always fire up MQTTSpy, connect to your broker and watch the messages. You can add a subscription for # to see all messages on the broker.

Controlling your Controller

If you just want to add your Controller to Home Assistant, jump down to the next topic.

The Controller uses the following MQTT topics:

Command Topics

There are two command topics:

cmnd/<device-id>/power: This is the simple on/off switch topic. Publishing a message with a payload of either "ON" or "OFF" will turn the strip on or off.

cmnd/<device-id>/color: This is the more advanced topic and can even replace the normal /power topic. This topic expects a simple payload with the following structure:

{
    "state": "ON",
    "brightness": 255
    "color": {"r": 255, "g": 0, "b": 0}
}

You can quickly set the state, brightness and color in one hit using this topic, or any of the three keys individually (which is also what Home Assistant will do).

State Topics

The controller will automatically publish a status message to the two topics below whenever it acts on an incoming MQTT message.

stat/<device-id>/power: Just like its cmnd equivalent, messages on this topic will have their payloads set to the string "ON" or "OFF" to reflect the current state.

stat/<device-id>/color: Again, this topic works much like its cmnd equivalent, publishing the same JSON payload (with one exception) to reflect the current LED state.

Adding the Controller to Home Assistant

To add your controller to Home Assistant, just add the following YAML to your configuration.yaml, substituting your device ID from the earlier step (and changing the name to match your lights):

light:
  - platform: mqtt_json
    name: Lounge LEDs
    command_topic: "cmnd/<device-id>/color"
    state_topic: "stat/<device-id>/color"
    brightness: true
    rgb: true

You should then be able to restart your Home Assistant and you will have a new entry in your Home Assistant "Lights" panel.

Bonus Round

Every single MQTT payload, complete with which topic it's published on, is actually also written directly to the serial console, so even if you are having trouble with your broker, you can watch the console. This output even includes all the configuration details such as the broker details, and any user/password configured (if you bought the Starter or Advanced Kits, you will have received a USB UART adapter in the kit).

Comments

comments powered by Disqus