Control Your Milight RGBw Bulbs from Amazon Echo

Setting Up the Raspberry Pi

I have a couple of Milights RGB bulbs and control them from my Android tablet. Then I noticed some articles where you can control your lights with voice control using an Amazon Echo.

If you have an Echo you wil see that a variety of skills can be added to control devices. However there is a skill for Philips Hue lights but they are more expensive that Milight bulbs. After some extensive research I did find a number of articles but this required gathering details from several sites and then assimilate the details.

The purpose of this article is to put everything in one place but will add links for completeness.

I have friends who go on at length about the mini computer the Rasperry Pi. It is possible as far as I know to run something on your computer but of course your PC has to be on all the time. The beauty of the Raspberry Pi once set up it runs all the time without the need for the PC to be on.

I used the following

Amazon Echo or Dot
Raspberry Pi Version 3
HA- Bridge – Software

The Pi can be bought either on its own but to save time I purchased the Raspberry Pi 3 Plug and Play Kit.

In the box you get the following:-

Raspberry Pi 3 Model B single board computer,
16GB MicroSD card with NOOBS software,
5V, 2.5A UK and Euro black power supply,
Black Raspberry Pi case with clear lid,
USB optical mouse,
USB mini keyboard,
2m HDMI cable,
3m Ethernet cable.

To run the Pi for the first time you will need a monitor with HDMI connectivity. The kit contains a MicroSD card, I strongly suggest you insert the card BEFORE you put the mini-computer into its case. I found I missed the slot whilst attempting to insert the card after fitting the case.

 

Great starter video:-

  • Unbox the Raspberry Pi
  • Fit the protective case
  • Connecting the keyboard
  • Connecting the mouse
  • Connecting the HDMI cable to a monitor (also alternative ways of connecting)
  • Installing the operating system from the NOOBS MicroSD card

Once the operating system has been installed the software should be updated and to do this open a terminal window as shown below.

Open a terminal window in Raspberry Pi

A terminal window will open.

Updating and Upgrading the Operating System

To update the operating system type in the terminal window:-

sudo apt-get update <RETURN>

 Please wait until the update has fininshed.

Finally upgrade the operating system by typing in the terminal window:-

sudo apt-get ugrade <RETURN>

Please wait until the update has fininshed. This will take some time if this is the first time the upgrade has been run.

Terminal screen showing completeed upgrade

How To Install The Ha-Bridge

The previous steps to update and ugrade are optional and can be performed at any time.  The ha-bridge needs to be installed in its own directory. During this process you will use the following commands. After each press the <RETURN> or equivalent key.

pwd <RETURN> present working directory gives your current location.  For example /home/pi
mkdir <directoryname><RETURN> make directory
nano <filename> <RETURN> nano is a basic text editor easy to use.
ls <RETURN> This lists the contents of a directory

Create the required directories

The starting point is the folder /home/pi. To get there enter:-

cd /home/pi <RETURN> or cd ~ <RETURN>
pwd <RETURN> checks you are in the right location

The terminal prompt should be /home/pi. Two directories are required. Enter:-

mkdir habridge <RETURN>
mkdir habridge/data <RETURN>

Download the ha-bridge

In the terminal enter:-

cd habridge <RETURN>
pwd <RETURN> should be /home/pi/habridge
wget https://github.com/bwssytems/ha-bridge/releases/download/v4.5.5/ha-bridge-4.5.5.jar. Please note the spelling of bwssytems.

Enter the wget command

When the download has finished run ls and you will that file ha-bridge-4.5.5.jar in /home/pi/habridge

wget download completed

Creating A Systemd file

To start nano enter:-

nano habridge.service<RETURN>

In the nano editor enter the following exactly. When finished Ctr X, then Y to confirm save.

create service file

[Unit]
Description=HA Bridge
Wants=network.target
After=network.target

[Service]
Type=simple
ExecStart=/usr/bin/java -jar -Dconfig.file=/home/pi/habridge/data/habridge.config /home/pi/habridge/ha-bridge-4.5.5.jar

[Install]
WantedBy=multi-user.target

Installing Java

You will see from the .jar file extention in ha-bridge-4.5.5.jar Java 8 SDK is required to run the bridge. To update and install Java enter in the terminal window:-

sudo apt-get update && sudo apt-get install oracle-java8-jdk <RETURN>
sudo update-alternatives –config java <RETURN>
java -version <RETURN>

Enabling and Starting Your HAbridge

We want the Habridge to start after a reboot of the Raspberry Pi. To do this enter in the terminal window:-

sudo systemctl enable /home/pi/habridge/habridge.service <RETURN>

The start the bridge:-

sudo systemctl start habridge <RETURN>

 

Connecting to the Ha-bridge to set up your Milight Bulbs

To start to set up your Milight RGBw buls you will need two peices of infmoration.

  • The IP Address of the Raspbery Pi – this is the address where the ha-bridge interface can be accessed.
  • The IP address of you Milight Bulbs WiFi Bridge.

The IP address of your raspberry is easily obtained by opening up a terminal window and entering:-

ifconfig -a <RETURN>

You may have  to scroll upwards in the terminal to see the IP address. The address of ha-bridge is there 192.168.1.11 (yours will be different).

obtain ip address

To find the IP address of your Milight Wifi Bridge if you are currently controlling your Milight Bridge with an Android/IOS app then the address will be in settings. The alternative is to log onto your router and look in connected devices or wifi devices.  In this case my Milight Wifi Bridge has an address of  192.168.1.3.

To access the ha-bridge interface go to your browser on a PC and in the address bar just type in 192.168.1.11 in this case. Your IP will be different.

habridge main interface

I have already set up six devices which I have named:

  • lights – configured to turn or off white light full brigtness
  • blue – turn on with colour blue
  • disco – turn on lights in disco mode
  • red – turn on with colour red
  • reducelighting – sets brightness to 50%
  • fulllighting – sets brightness to 100%

You will notice I only have off configured in the lights device, easier to say lights off whatever other device you are using.

When entering the commands to control your Milight Bulbs the following format is used:-

udp://<your Milight IP address>:8899/0x<hex values>

So for example to turn on bulbs (group 1 in this case) you would enter:-

udp://192.168.1.3:8899/0x450055 NB substitute address 198.162.1.3  with the address of your Milight Wifi Bridge. :8899 is the port number. This may change is you are using a later verison of  Milight Wifi Bridge.

To turn off enter:-

udp://192.168.1.3:8899/0x460055

Create a new device

Click on Add/Edit displays the following page with a bewildering array of data fields. For a basic Amazon device we will only use:-

Name – a unique name of your choice for the device
Description – optional
Comments – optional
Target – leave blank, this will be populated when you create your first device
Device Type – UDP (from dropdown list not sure if this is needed)
Map Type (Legacy) – UDP Device (from dropdown list)
On Items – Type – UDP Device (from dropdown list
Target – enter udp://xxxxxxxxxxx
Delay – if required usually enter 100 (100ms)

  • Access your ha-bridge (IP of your Raspberry Pi) via you browser
  • Click on Add/Edit (as above)
  • Name – field enter a device name. You will use this when using Amazon Echo voice control
  • Device type field select UDP from the dropdown list
  • Map Type (Legacy) field select UDP Device from the dropdown list.
  • On Items section:-
    • In the Type field select UDP Device from the dropdown list
    • In the Target item enter  udp://192.168.1.3:8899/0x420055, this field can be resized by dragging the bottom right hand corner
    • As nothing else is required ALWAYS PRESS ADD. This will save your entries.
  • In the Off Items section:-
    • In the Type field select UDP Device from the dropdown list
    • In the Target item enter  udp://192.168.1.3:8899/0x410055, this field can be resized by dragging the bottom right hand corner
    • As nothing else is required ALWAYS PRESS ADD. This will save your entries.
  • When finshed click on Update Bridge Device
  • Back at the main ha-bridge interface you should see your device. Should it not be visible then it is likely that the Add button was no clicked.
  • Your deivce can now be tested Using Test ON and Test OFF. If your Milight Bulbs behave as expected we can now instruct the Amazon Echo to find your device.
  • Say “Alexa discover devices”.
  • After a successful discovery Alexa will tell you how many devices have been detected.
  • You can now sa “Alexa turn on <whatever name you gave to your device” or “Alexa turn off <whatever name you gave to your device”
Port Number 8899
All UDP Commands are 3 Bytes. First byte is from the list below, plus a fixed 2 byte suffix of 0x00 (decimal: 0) and 0x55 (decimal: 85)
i.e. to turn all RGBW COLOR LimitlessLED Smart lights to ON then send the TCP/IP UDP packet of: 0x42 0x00 0x55
udp://192.168.1.3:8899:/<hex>
On
udp://192.168.1.3:8899/0x420055 All on
udp://192.168.1.3:8899/0x450055 Group 1
udp://192.168.1.3:8899/0x470055 Group 2
udp://192.168.1.3:8899/0x490055 Group 3
udp://192.168.1.3:8899/0x4B0055 Group 4
Off
udp://192.168.1.3:8899/0x410055 All off
udp://192.168.1.3:8899/0x460055 Group 1
udp://192.168.1.3:8899/0x480055 Group 2
udp://192.168.1.3:8899/0x4A0055 Group 3
udp://192.168.1.3:8899/0x4C0055 Group 4
Set to white
udp://192.168.1.3:8899/0x420055 100ms delay All on
udp://192.168.1.3:8899/0xC20055
udp://192.168.1.3:8899/0x450055 100ms delay Group 1
udp://192.168.1.3:8899/0xC50055
udp://192.168.1.3:8899/0x470055 100ms delay Group 2
udp://192.168.1.3:8899/0xC70055
udp://192.168.1.3:8899/0x490055 100ms delay Group 3
udp://192.168.1.3:8899/0xC90055
udp://192.168.1.3:8899/0x4B0055 100ms delay Group 4
udp://192.168.1.3:8899/0xCB0055
Set to green
udp://192.168.1.3:8899/0x420055
udp://192.168.1.3:8899/0x406055
Set to blue
udp://192.168.1.3:8899/0x420055
udp://192.168.1.3:8899/0x401055
Set to red
udp://192.168.1.3:8899/0x420055
udp://192.168.1.3:8899/0x40B055
Set to violet
udp://192.168.1.3:8899/0x420055
udp://192.168.1.3:8899/0x400055
Set to Aqua
udp://192.168.1.3:8899/0x420055
udp://192.168.1.3:8899/0x403055
Disco Mode
udp://192.168.1.3:8899/0x420055
udp://192.168.1.3:8899/0x4D0055
Full bright
udp://192.168.1.3:8899/0x420055
udp://192.168.1.3:8899/0x4E1B55
50% Dim
udp://192.168.1.3:8899/0x420055
udp://192.168.1.3:8899/0x4E0D55
Milight RGBw bulbs operate in either colour or white. The brightness for each mode is set independently. So assuming the white setting is set to 100% and any colour set to say 50%, then switching between the two mode will retain the brightness for that mode.
The brightness range is decimal 1 to 27 with 27 being full on. This decimal number can be converted to hex here. For example decimal 27 is 1B as in udp://192.168.1.3:8899/0x4E1B55

Model:
Raspberry Pi 3 model B
Get it from Amazon:
Description:
Raspberry Pi 3 Official Desktop Starter Kit (16Gb, Black)
Model:
Raspberry Pi 3 model
Get it from Amazon:
Description:
Raspberry Pi 3 Model B Quad Core CPU 1.2 GHz 1 GB RAM
Model:
Raspberry Pi 3 model
Get it from Amazon:
Description:
Raspberry Pi 3 Value Starter Kit

Leave a Comment

seventeen − twelve =