Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document how to configure Home-assistant with RGB/White lights (AI_LIGHT) and MQTT #144

Closed
xoseperez opened this issue May 24, 2017 · 11 comments

Comments

@xoseperez
Copy link
Owner

Originally reported by: JF002 (Bitbucket: JF002, GitHub: JF002)


Espurna 1.8 supports AI Thinker RGB/White light bulbs, with ON/OFF command and color switching, but te integration with Home-Assistant and MQTT doesn't seem to be completely documented.
Moreover, it's not clear if color temperature, brightness and white values are supported for now.

Here is an example of my working configuration for the light, with ON/OFF and color settings:

#!python
light
  - platform: mqtt
    name: 'AI Light'
    state_topic: '/light/AI_LIGHT_219F36/relay/0'
    command_topic: '/light/AI_LIGHT_219F36/relay/0'
    payload_on: 1
    payload_off: 0
    rgb_state_topic: '/light/AI_LIGHT_219F36/color'
    rgb_command_topic: '/light/AI_LIGHT_219F36/color'
    rgb: true
    optimistic: false

Home-assistant also supports the following settings: white value, brightness and color temp (see https://home-assistant.io/components/light.mqtt/).
I tried adding these lines in the configuration file, but it doesn't work correctly:

#!python
    color_temp: true
    color_temp_command_topic: '/light/AI_LIGHT_219F36/color'
    color_temp_state_topic: '/light/AI_LIGHT_219F36/color''
    brightness: true
    brightness_command_topic:  '/light/AI_LIGHT_219F36/color'
    brightness_state_topic: '/light/AI_LIGHT_219F36/color'
    white_value: true
    white_value_command_topic: '/light/AI_LIGHT_219F36/color'
    white_value_state_topic: '/light/AI_LIGHT_219F36/color'

Are these functionalities already supported? If yes, how to use them (topics, format,...) ?

I would be happy to write some documentation once I manage to make it work :)

@xoseperez
Copy link
Owner Author

Original comment by JF002 (Bitbucket: JF002, GitHub: JF002):


Here is the information I could gather by reading the code. Please tell me if I'm wrong in my understanding!

All the settings (color, brightness, white value and temperature) are applied throught only one MQTT topic (/light/{id}/color) :

  • Color : the color can be expressed as an RGB HEX color ('#RRGGBB', ex : '#FF4D1D') or as 3 decimal values (RRR,GGG,BBB, ex : '255,77,29');
  • White value : just write the same value for the 3 colors, ('#A1A1A1' or '161,161,161') or write only 1 digit ('161');
  • Temperature : write a value between 1000 and 40000 ending with 'K';
  • Brightness : there is no explicit way to set a brightness value from the current color, you need to set the color to another value.

I tested all these possibilities by publishling the values manually with an MQTT client (mosquitto_pub).

But I couldn't integrate all of them with Home-Assistant:

  • I don't know if it is possible to append 'K' to the temperature value
  • It is not possible to specify if the value is a white color or a brightness value
  • The 'state' topic (for the feedback) is not usable, as it would return only one value for all the settings (color, brightness, temperature, white).

I think it would be easier if multiple topics were used :

  • Color;
  • Brightness : it would scale the current color according to the setting;
  • White value : switch to white only color;
  • Temperature : switch to temperature control instead of color.

This way, the integration with home-assistant would be easier, for both the setting and the feedback topics.

What do you think about all of this?

@xoseperez
Copy link
Owner Author

Original comment by Pete (Bitbucket: xbmcnut, GitHub: xbmcnut):


I've just deployed H801 with 1.8.1 (in RGB mode) and have noticed that the brightness is around 30-40% lower than the controller I replaced it with. Anyone else see this as from above there appears to be no way to adjust the brightness level and wife not happy. :(

@xoseperez
Copy link
Owner Author

Working on this issue in branch "light", right now it supports:

  • ".../color" topic will accept the same formats as before (including a single number that will be interpreted as white)
  • ".../color/temperature" will accept a temperature in Kelvin
  • ".../brightness" will accept a value between 0 and 255

I'm not sure about the MQTT reporting these values. Internally I'm storing RGB and brightness values. Going from temperature color to RGB is easy, not so easy the other way around. Same for white since white means "same value for red, green and blue".

@xoseperez
Copy link
Owner Author

Original comment by JF002 (Bitbucket: JF002, GitHub: JF002):


Oh thanks for working on it!
Since I created this issue, I've created a class (derived from a previous project of mine), which use most of the code from the Light module of Espurna. My goal was to test the implementation before integrating it into Espurna.
Unfortunately, I haven't had the time to finish the integration since then.

However, this class worked quite well with Home-assistant.

I publish the project on Github : https://github.com/JF002/ESP8266_HASS_ESPURNARGB, you can use the code if you want to :)

Basically, it uses the following mqtt topics for the settings:

  • color
  • temperature
  • brightness
  • white

And the following ones for the state:

  • color_state
  • temperature_state
  • brightness_state
  • white_state

The function mqtt_callback() in main just forward the values to the class EspurnaLight which does all the work.
I tested this project with a WS8212 RGB LED (Neopixel), but it should behave the same with any light bulb (just replace the calls to the neopixel library).

And finally, here is the configuration from home-assistant:

#!bash

light:
  - platform: mqtt
    name: 'AI Light TEST'
    state_topic: '/light/AI_LIGHT_TEST/relay/0'
    command_topic: '/light/AI_LIGHT_TEST/relay/0'
    payload_on: 1
    payload_off: 0
    rgb_state_topic: '/light/AI_LIGHT_TEST/color_state'
    rgb_command_topic: '/light/AI_LIGHT_TEST/color'
    rgb: true
    optimistic: false
    color_temp: true
    color_temp_command_topic: '/light/AI_LIGHT_TEST/temperature'
    color_temp_state_topic: '/light/AI_LIGHT_TEST/temperature_state'
    brightness: true
    brightness_command_topic:  '/light/AI_LIGHT_TEST/brightness'
    brightness_state_topic: '/light/AI_LIGHT_TEST/brightness_state'
    white_value: true
    white_value_command_topic: '/light/AI_LIGHT_TEST/white'
    white_value_state_topic: '/light/AI_LIGHT_TEST/white_state'

Hope this helps :)

@xoseperez
Copy link
Owner Author

Original comment by Jonathan Hatter (Bitbucket: jhatter, GitHub: jhatter):


Can someone explain what I need to do to make this work? I'm using a Magic Home type LED controller but I had to to flash the board as esp8285 and switch the green and red pin numbers for it to respond correctly and set it to rgbw since it has separate white LEDs. I have added all the MQTT topics shown above in to Home Assistant. I have all of the options listed but the only one that works is the color change. Brightness, color temperature, and white value don't change anything. From the espurna webpage the rgb LEDs and white LEDs work correctly. Excuse me if this isn't going to be implemented until a future release. I wasn't sure from the comments above if it was already supposed to work or not.

@xoseperez
Copy link
Owner Author

This feature is not yet released. As I say in my last comment it in a development branch called "light". And the implementation by @JF002 is different from mine. Part of the work to do is to reach a common point between both...

@xoseperez
Copy link
Owner Author

Light support changed a bit with 1.9.0. The HA configuration file should go like this:

light:
  - platform: mqtt
    name: 'AI Light TEST'
    state_topic: '/light/AI_LIGHT_TEST/relay/0'
    command_topic: '/light/AI_LIGHT_TEST/relay/0/set'
    payload_on: 1
    payload_off: 0
    rgb_state_topic: '/light/AI_LIGHT_TEST/color'
    rgb_command_topic: '/light/AI_LIGHT_TEST/color/set'
    rgb: true
    optimistic: false
    color_temp: true
    color_temp_command_topic: '/light/AI_LIGHT_TEST/mired/set'
    brightness: true
    brightness_command_topic:  '/light/AI_LIGHT_TEST/brightness/set'
    brightness_state_topic: '/light/AI_LIGHT_TEST/brightness'
    white_value: true
    white_value_command_topic: '/light/AI_LIGHT_TEST/channel/3/set'
    white_value_state_topic: '/light/AI_LIGHT_TEST/channel/3'

Basically: command topics now should end with "/set" by default. Light topics are "color", "brightness", "mired" (for temperature color) and "channel/#" for each channel. For RGB or RGBW lights the first 3 channels are mapped to the "color" topic but you can also drive them using the "channel" topic. So "/light/AI_LIGHT_TEST/channel/0/set" to 255 will turn RED LEDs on. The AiLight has 4 channels so "/light/AI_LIGHT_TEST/channel/3/set" maps to the white LEDs.

@xoseperez
Copy link
Owner Author

Removing milestone: 1.8.4 (automated comment)

@xoseperez
Copy link
Owner Author

Original comment by Jonathan Hatter (Bitbucket: jhatter, GitHub: jhatter):


Thank you for your efforts. I updated the firmware and changed the HA assistant code. I can control the led controller from within HA and all functions work great! I did notice that I couldn't do white by itself. I had to have the brightness of the rgb on at least 1 or the whole switch would be off. No problem at all. At that level you really can't tell that it's not white by itself.

@xoseperez
Copy link
Owner Author

Closing this. Opened #192 for the brightness issue with the white channel.

@xoseperez
Copy link
Owner Author

Removing milestone: 1.9.1 (automated comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant