Controlling the Microwave Light with a Raspberry Pi + Relay

I can control every light in my house thanks to Z-Wave switches and Philips Hue.  Every light EXCEPT the bulb in the microwave above the stove.  This really bothered me for some reason, even though it was an LED that would consume $0.0001 per year.  So I took apart my microwave and attached a relay to this bulb.  Now when I tell Siri to turn off all the lights, ALL the lights go off, and that is very satisfying.

Parts

Raspberry Pi Relay Code (node.js)

//require the wiring-pi node library
var wpi = require('wiring-pi'); 
//use GPIO pin 3
var configPin = 3; 
//setup wiring-pi library
wpi.setup('wpi'); 
//configure pin 3 to be used for output, instead of input like for a sensor
wpi.pinMode(configPin, wpi.OUTPUT); 
//turn on relay by writing 1 to the pin which sends voltage to the relay, send 0 to turn off
wpi.digitalWrite(configPin, 1);

Amazon Echo Bridge allows Alexa control

https://github.com/armzilla/amazon-echo-ha-bridge

Amazon Echo Bridge simulates a Philips Hue bridge for controlling web services with an Amazon Echo.  It supports on, off and brightness.  An Express web server on my Raspberry Pi handles Alexa’s requests, then triggers the relay.

Homebridge-http allows Siri Control

https://github.com/rudders/homebridge-http


Amazon Echo Pauses My TV

I can say “alexa, turn on TV pause” or “turn on TV play” to control my TV.  A Raspberry Pi receives the request from the Amazon Echo, then the Pi queries my receiver to find out if I am watching my TiVo or my smart TV’s built in apps like Hulu, YouTube or Netflix.  Then the Pi pauses either the TiVo or the smart TV.  I am fortunate that my LG TV, TiVo and Marantz receiver can all be network controlled, so I don’t have to rely on a stateless infrared blaster.

Using Alexa is very handy in case I abruptly have to walk out of the room, I can pause my TV while walking, so I am not slowed down but also do not have to miss my TV show.  If the phone rings, I can quickly pause the TV without waiting to answer my phone.  Another use case is when somebody turns on the blender or gets ice from the fridge.

Next I plan to implement an “alexa turn on rewind” to skip back 30 seconds both with the TiVo or smart TV.

Software Libraries

  • https://github.com/armzilla/amazon-echo-ha-bridge
  • https://github.com/hobbyquaker/lgtv2
  • Custom code that talks to my TiVo (telnet) and Marantz stereo (http)

All the code and libraries are kept running forever on my Raspberry Pi using PM2.

PM2 is designed for node scripts, not Java, so to keep Amazon Echo Bridge running forever I use this PM2 process configuration.  (Thanks Zalym)

{
    "name": "Amazon Echo Jar",
    "args": [
        "-jar",
        "/home/pi/Downloads/amazon-echo-ha-bridge/target/amazon-echo-bridge-0.4.0.jar",
        "--upnp.config.address=192.168.1.2"
    ],
    "script": "java",
    "node_args": [],
    "log_date_format": "YYYY-MM-DD HH:mm Z",
    "exec_interpreter": "none",
    "exec_mode": "fork"
}

Control Stereo Volume with Siri and Alexa

Denon and Marantz receivers have a web interface that allows the volume to be changed using standard HTTP requests.  Siri and Alexa can change the brightness of a lightbulb between 0% – 100%.  My Raspberry Pi simulates a light bulb but instead of changing the brightness of a light, the Raspberry Pi sends an HTTP message to my receiver to adjust the volume according to the simulated brightness percentage.

  • “hey siri, set the stereo volume to 25%”
  • “alexa, set the stereo to 50%”

Now I can control my TV volume with these devices

  • TV remote
  • Stereo remote
  • TiVo remote
  • Siri on my iPhone or Apple Watch
  • Siri on my wife’s iPhone, Watch or iPad
  • Stereo’s web interface
  • Amazon Echo Dot’s Alexa
  • iPhone light bulb brightness shortcut
  • Apple Watch digital crown

I almost always set the volume using Alexa, because she is in the same room as the stereo.  If I turn up the stereo so loud that Alexa can’t hear me well enough to turn it down, then I can speak directly into the mic of my Apple Watch, which will always hear me over any background noise since my mouth is so close to the mic.

 

A Node.js HTTP PUT request to the stereo’s control URL changes the volume

var relativeVolume = (newVolume - 80).toFixed(1);
request.get('http://stereo/goform/formiPhoneAppVolume.xml' + '?1+' + relativeVolume, function(error, response, body) {
    if (!error && response.statusCode == 200) {
        callback(null, response.statusCode);
    } else {
        callback(error);
    }
});

 

Homebridge allows Siri control

https://github.com/robertvorthman/homebridge-marantz-volume

A Raspberry Pi running Homebridge uses this plugin to create a fake lightbulb which changes the stereo volume when you use your iPhone to change the brightness.

Amazon Echo Bridge allows Alexa control

https://github.com/armzilla/amazon-echo-ha-bridge

Amazon Echo Bridge simulates a Philips Hue bridge for controlling web services with an Amazon Echo.  It supports on, off and brightness.  An Express web server on my Raspberry Pi handles Alexa’s requests, then forwards them to my stereo.