Start cheap build from there
After my first steps in Home Automation, I soon got a couple of cheap lightbulbs from Milight that were controllable by Home Assistant. At that time I didn’t know about a serious drawback, which is the reason I do not recommend them. There is no feedback from the bulbs to the controller. Which means that the controller has no idea about the real state of the bulbs. For instance, they are controllable with a remote when you use the remote to turn a bulb on Home Assistance still think that bulb is off.
Fix the lights
I solved this by not using the gateway from Milight itself, but a gateway based on a Wemos D1 with a radio transceiver. This hub which is running firmware written by Chris Mullins this firmware esp8266_milight_hub can not only talk to the bulbs but also receive the signal from the remote. I use MQTT to connect the gateway with Home Assistant. To let Home Assistant know about a button press on the remote, I use the following automation.
alias: MiLight Forwarder
initial_state: True
trigger:
- platform: mqtt
topic: 'milight/updates/XXXX/rgb_cct/+'
action:
- service: mqtt.publish
data_template:
topic: 'milight/commands/XXXX/rgb_cct/{{ trigger.topic.split("/")[4] }}'
payload_template: '{{ trigger.payload }}'
This automation listens to the topic where my hub posts the updates and forwards them to the commands topic, and then Home Assistant “knows” the state of the bulbs.
Another thing is that the remote can control all the groups connected to the remote. To fix that I use the following automation.
alias: Milight remote Fix
initial_state: True
trigger:
- platform: mqtt
topic: 'milight/updates/xxxx/rgb_cct/0'
action:
- service: mqtt.publish
data_template:
topic: 'milight/xxx/rgb_cct/1'
payload_template: '{{ trigger.payload }}'
- service: mqtt.publish
data_template:
topic: 'milight/xxxx/rgb_cct/2'
payload_template: '{{ trigger.payload }}'
- service: mqtt.publish
data_template:
topic: 'milight/xxxx/rgb_cct/3'
payload_template: '{{ trigger.payload }}'
- service: mqtt.publish
data_template:
topic: 'milight/xxxx/rgb_cct/4'
payload_template: '{{ trigger.payload }}'
Hacky but reliable
With above automations and defining the light bulbs as MQTT there is no real drawback they work reliable via manual control by remote, manual via the interface of Home Assistant or by my automation. It can happen that the bulb have a different state than in Home Assistant for instance after a power loss when the power comes back the bulbs go to an on state which Home Assistant doesn’t know. Turning the bulbs on or off manually resolve this.