So lets say you have an extremely small Linux (or maybe OSX) system and you would like to control your LIFX bulbs using it. This method is not very flexible, and does not attempt to confirm its commands worked so don’t use it when you need reliability. You will also need to give your lights static IP addresses in your DHCP server if you want to talk to them directly.
All you need for this method is bash, however I’ll show examples for using netcat and socat at the end (because they’re a little more powerful).
Step 1 - Make some packets
Using the LAN Documentation you build the packets that you wish to send to the bulbs and save them in files. Save them in hex format with \x
between every byte. This way we can use the /bin/echo
command to convert them to binary. Below are two examples, using the documentation you could create many more. In these examples we will save these files to /etc/lifx/
but you can save them anywhere you like.
All On - allon.echo
\x2a\x00\x00\x34\xb4\x3c\xf0\x84\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x0d\x00\x00\x00\x00\x00\x00\x00\x00\x75\x00\x00\x00\xff\xff\xe8\x03\x00\x00
All Off - alloff.echo
\x2a\x00\x00\x34\xb4\x3c\xf0\x84\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x0b\x00\x00\x00\x00\x00\x00\x00\x00\x75\x00\x00\x00\x00\x00\xe8\x03\x00\x00
Step 2 - Test the commands
This command uses the /bin/echo
command to create binary versions of our packets, then sends it to the bulbs IP address on the LIFX port. As a result you should see your bulb turn off. You should be able to use other packets to perform other actions.
/bin/echo -e "$(cat /etc/lifx/alloff.echo)" > /dev/udp/172.16.1.4/56700
Step 3 - Add aliases
Obviously these commands are annoying to type so to make it easier you can make an alias for them. Add this line to the end of your ~/.bashrc
. You can make several commands for different packets you may wish to send.
alias lifx-off='/bin/echo -e "$(cat /etc/lifx/alloff.echo)" > /dev/udp/172.16.1.4/56700'
Appendix - Multiple lights
Instead of using the bash builtin for sending packets you can use netcat
or socat
to send commands as a broadcast to multiple lights at a time. Below are examples of both broadcasting to an entire subnet.
Netcat
/bin/echo -e "$(cat /etc/lifx/alloff.echo)" | nc -u 172.16.1.255 56700
Socat
/bin/echo -e "$(cat /etc/lifx/alloff.echo)" | socat - udp-datagram:172.16.1.255:56700,broadcast