Driveway Vehicle Sensor

An Arduino and ultrasonic sensor in my driveway can detect when a vehicle arrives by measuring distance to the nearest obstacle. The Arduino notifies a Raspberry Pi, which plays an alert over my speakers, and sends an image snapshot to my phone and watch.


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


TV Mounted On Outside Corner

It’s possible to mount an 85 lb 50″ Plasma TV on an outside corner, just in case anyone is wondering.  I was able to get eight big lag screws into studs.  An LCD would be less than half the weight so it wouldn’t need as many screws.

Parts

 


Dishwasher Completed Alerts

I wanted to be sure that my dishwasher started and be alerted when it was completed.  Like most dishwashers, mine does not have any smart features or network connectivity.  Instead of directly interfacing with the dishwashser, I decided to use a smart plug that supports energy metering.  A Raspberry Pi continuously queries the smart plug to determine how much power it is consuming, then triggers IFTTT to send a notification to my phone and Watch when wattage exceeds 10 watts.  Now when my wife asks “did you start the dishwasher” I don’t have to rely on my late-night memory, and can just look at my phone.

I’m using this TP-Link HS100 smart plug because it unofficially supports network control.

This guy reverse engineered the smart plug’s network protocol.

This guy wrote a node module to simplify interfacing with the smart plug.

I wrote a node module to simplify getting notifications from an appliance when it starts and stops using power.  The script runs forever on my Raspberry Pi using PM2.

var SmartPlugPowerMonitor = require('smart-plug-power-monitor');

var smartPlugPowerMonitor = new SmartPlugPowerMonitor({
    smartPlugIP: "192.168.1.104",
    iftttMakerChannelKey: "abcdefg",
    startEventName: 'dishwasher-started',
    endEventName: 'dishwasher-completed',
    wattsThreshold: 10,
    pollIntervalSeconds: 15,
    startTimeWindowSeconds: 5,
    endTimeWindowSeconds: 20 * 60
});

smartPlugPowerMonitor.start();

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.


Echo Dot Mounted Above Doorway

My Amazon Echo Dot can hear me from all four rooms on my main floor because it is mounted in the doorway.  I can control all my lights and the TV without having to buy a second Dot, and it is out of the way with the wires concealed.

I bought a plastic wall mount on Amazon which looked nice but unfortunately it did not have a big enough cutout for the power and audio cables so I had to bore out a larger hole with my dremel.  I would not recommend mounting a Dot on the wall because it would prevent the Dot from cancelling out background noise due to sound echoing off the wall which would greatly decrease its useable range.

20′ audio and power cables.

The audio output plugs into my ceiling speakers so I can hear Alexa from every room on the main floor.  The Echo’s built in speaker would be muffled by the mount.


$60 Smart Coffee Maker controlled with Siri or Alexa

Dumb appliances can be combined with smart plugs to create inexpensive smart appliances.  This dumb coffee maker can be controlled with both Siri and Alexa.  Complex schedules can easily be configured with smart phone apps, such as only weekdays, instead of clumsy buttons on digital coffee makers.  On the weekends, when I wake up at inexact times, I just tell Alexa or Siri to turn on the coffee maker and my coffee is ready by the time I go to the kitchen.

Smart plugs only work with dumb appliances, that is the appliance must have a physical switch that is always in the on position regardless of whether the appliance is unplugged and plugged back in.  A digital coffee maker would not work because the power button would not be pressed if it was unplugged and plugged back in.

Parts Used

This video shows how Siri or Alexa can turn on the coffee maker instantly, hands-free and eyes-free.

Scheduling the coffee maker to turn on four days a week with Apple’s Home app.

 


Traditional Light Switches Controlled by Both Alexa and Siri

Alexa and Siri can both control my light switches, regardless of the position of the light switches.

Parts Used

  • Z-Wave Dual Relay – $30ish dollars
  • Z-Wave Hub (I’m using Wink but Samsung Smart Things is a good choice)
  • Raspberry Pi running homebridge-wink (exposes lights to HomeKit/Siri)
  • Amazon Echo Dot (already supports Wink hub)

A relay like this is inside the light switch.

One dual-relay supports two light switches.  A relay like this is ideal for stairways/hallways with multiple switches that control one circuit AS LONG AS THE RELAY IS INSTALLED IN THE LIGHT SWITCH CONNECTED TO THE LOAD and your light switches have a neutral wire.  A relay like this is not good for lights that you can’t see from the switch, such as an outdoor light, because you can’t be sure the light is off by flicking the switch down.  If the light is already off, and you flip the switch down, the light would turn on, which is probably not what you want, but it’s fine for stairs with multiple switches because those switches are already like that.

It can be tough to fit the relay behind the light switches.  This relay is black but it is identical to the white relay pictured above.