Skip to content

Homeassistant integration

bpohvoodoo edited this page Mar 27, 2019 · 4 revisions

The integration into Homeassistant is enabled by default. You could enable/disable the functionality by (un-)commenting the "#define ENABLE_HOMEASSISTANT" in "definitions.h". It uses the ArduinoJSON library, so you have to install it also via "Library Manager", when you want to use the integration.

MQTT topics

When you have Homeassistant integration enabled, there are three additional topics available:

  • home/HOSTNAME_ha/state/in
  • home/HOSTNAME_ha/state/out Where HOSTNAME is the current hostname set in definitions.h.

in-topic format

The in-topic consumes JSON formatted data with the following structure:

{

	"brightness": 196,  
	"color": {  
		"r": 255,
		"g": 100,
		"b": 10,
		"w": 0,
		"r2": 0,
		"g2": 0,
		"b2": 0,
		"w2": 0,
		"r3": 0,
		"g3": 0,
		"b3": 0,
		"w3": 0
	},
	"white_value": 0,
        "speed": 194,
	"color_temp": 24,
	"effect": "Rainbow",
	"state": "ON"
}

in-topic parameters

  • brightness: Value 0 - 255
  • color: Structure with Red (r), Green (g), Blue (b) and White (w) values 0 - 255
  • white_value: values 0 - 255
  • color_temp: Color temperature in mireds
  • effect: Name of the effect like defined in WS2812FX - case sensitive.
  • state: "ON" or "OFF"
  • speed: Value 0 - 255

out-topic format

Contains the current mode as JSON.

Example:

{ 
	"state": "OFF",
	"color": {  
		"r": 255,
		"g": 100,
		"b": 10,
		"w": 0,
		"r2": 0,
		"g2": 0,
		"b2": 0,
		"w2": 0,
		"r3": 0,
		"g3": 0,
		"b3": 0,
		"w3": 0
	},
	"white_value": 0,
        "speed": 194,
	"color_temp": 24,
	"brightness": 100,
	"effect": "Static"
}

Homeassistant config

You can find a sample config here.

Homeassistant MQTT Auto-Discovery

To use the MQTT Auto-Discovery feature (Plug & Play),

  • Uncomment #define MQTT_HOME_ASSISTANT_SUPPORT in definitions.h
  • Use AMQTT #define ENABLE_AMQTT in definitions.h

While compiling on Arduino IDE make sure to select "Tools" -> "IwIP Variant" -> "Higher Bandwidth" Board settings

On the Homeassistant side:

  • Enable MQTT Discovery in configuration.yaml
mqtt:
  broker: 192.168.0.xxx
  port: 1883
  client_id: home-assistant
  keepalive: 60
  discovery: true
  discovery_prefix: homeassistant
  • Restart Homeassistant and now McLighting will automatically show up in your dashboard.