Tomdee

7Nov/160

Triggering Philips Hue Lights using Amazon Dash and OpenWRT

There are plenty of existing blog posts describing Amazon Dash hacks. I don't think I've seen any with this approach so I'd thought I'd share.

I own a router running OpenWRT and I wanted a way to respond to Amazon Dash events without needing to sniff all my traffic for ARPs (the "normal" way people are triggering using dash buttons). My method involves listening for wireless events from the "iw" tool.

This line can be placed in /etc/rc.local (or edited through the OpenWRT web page under Admin->Startup and putting it in the box at the bottom)

nohup ash -c 'iw event |awk  "/new station a0:02:dc:c9:07:62/" | while read -r line; do if hue get 2 | grep "\"on\":true"; then hue set 2 --off ; else hue set 2 --on ; fi; done ' &

I run the script with "nohup" at the start and "&" at the end so it runs in the background.

"iw event" prints out all the wireless events. I pipe that through "awk" to filter out just the events I want (my dash button connecting).

The filtered events are then passed to a while loop which blocks reading each line of input (which is one line per event or button press).

The body of the while loop is the actual command that it runs for each press. It checks the current state of a hue bulb and toggles it between on and off.

This relies on the excellent "hue-shell" script, which was simple to install on OpenWRT - see http://josef-friedrich.github.io/Hue-shell/docs/

Comments (0) Trackbacks (0)

No comments yet.


Leave a comment

No trackbacks yet.