Getting IP camera motion events into Home Assistant to trigger things

Oh this is exciting! I’ve been trying to figure out how to get motion events from my IP camera into my home-assistant instance running on my Raspberry Pi, and I just did a successful test! It works! Hooray. Briefly, I set up an email server on the Pi, have the camera email the Pi, have the email server trigger a script which parses the email for key words and sends MQTT signals as appropriate, at which point the home-assistant MQTT client sees them and triggers automations (like blinking a light to scare people off). Here’s how I did it.

Camera-based motion sensors in home-assistant

Continue reading Getting IP camera motion events into Home Assistant to trigger things

Cheap vacuum pump for home physics experiments

As documented earlier, I made one of those CRT-in-a-winebottle things. I used a cheap 2-stage mechanical vacuum pump for it. Well, it was so good that my boss wanted to use it as a science demo at some dinners he gives, so it’s been permanently transferred to work. So I need a new pump, and a new chamber!

Continue reading Cheap vacuum pump for home physics experiments

Fixing my motorcycle’s charging system

I got my first motorcycle,  a 1997 Suzuki GS500, in 2007. It was great for a long time. I cut my motorcycle maintenance teeth on it, starting with gas line issues, shim adjustments, and an oil leak fix. Things escalated to taking the pistons out and head off to get the top-end rebuilt. Issues kept popping up more frequently than I liked so I sold it in 2012 and got a brand new Suzuki DL650A V-Strom ABS (aka “Glee”), feeling like I had had enough maintenance for a while. I only felt a little shame when I took it in to the shop for some routine maintenance

Well…I guess I’m back in the routine. After I totaled it but kept it, I got warmed up doing basic maintenance stuff on it. So when an issue came up recently, I decided to fix it myself.

UPDATE Jan 2017: Whaddaya know? The stator was just recalled due to a tendancy for this to happen.

Trouble a-brewing

Continue reading Fixing my motorcycle’s charging system

Raspberry Pi + Home Assistant DIY Burglar Alarm

I just configured a pretty slick burglar alarm with the open-source Home-Assistant platform running on my Raspberry Pi. It can be armed to trigger when a door is opened and/or when a motion sensor goes off.

Arm the burglar alarm

Then, a sequence of events happens:

  • An IR LED turns on my stereo
  • A sound file I cobbled together starts playing. It starts with a computerized voice saying that your entry been detected and recorded, then it beeps for a while (giving you time to disarm), and then it goes into a blaring siren noise. Quite the escalation!
  • A light blinks on and off a few times
  • A camera takes a series of snapshots of the area
  • An email is sent to my phone with the snapshots, showing me what’s going on

Continue reading Raspberry Pi + Home Assistant DIY Burglar Alarm

Adding IR send and receive capabilities to my home-assistant based smart home

Or, how to control your A/C from your phone

You may have seen my earlier post about my new home automation setup. Well I just upgraded it! I just finished testing out a new infrared remote control send and receive capability and it is pure awesome. Here’s what I can do now from within home-assistant:

  • Turn on and off my new DeLonghi portable air conditioner from Costco, and set the temperature to whatever
  • Turn on and off the TV and press any buttons from its remote control
  • Turn on and off the stereo and virtually press any buttons from its remote control (which I never even had!)
  • Use an old random blueray remote control to set scenes, turn lights on and off, etc. (basically do anything under home-assistant’s control)

This post is about how I did it on my Raspberry Pi.

Update: A video!

Annotated setup with IR sensors

Continue reading Adding IR send and receive capabilities to my home-assistant based smart home

Using an Aeotech recessed door sensor in home-assistant

I went over to my friend’s house last night to help get home-assistant on a Raspberry Pi working for his z-wave door sensors and siren. The Ecotech sensor showed up fine but the Aeotech recessed one (Recessed Door Sensor Gen5 , ZW089-A) did not show up by default. After poking around in the logs for a while, we realized that it was sending BASIC_SET command classes instead of BinarySensor commands. Apparently (I thought I had fixed this already), home-assistant doesn’t recognize the BASIC_SET commands just yet. But looking at the config file for this device, we discovered that config item 121 changes which kind of report this sensor sends:
Continue reading Using an Aeotech recessed door sensor in home-assistant

Building a low-pass filter to remove alternator whine in my car

Ever since I installed a mobile ham radio in my Subaru, there has been a pretty noticeable whine that revs up and down with the engine. I got a few complaints that the whine was on my transmitted signal. I can also hear the whine through my subwoofer, though it is quieter. I needed a low-pass filter to let the DC from my battery make it through to the radio while blocking any alternator-induced AC coming along for the ride. I was going to just buy one but then I searched the web a little and found that it was fun and easy to build my own!

Continue reading Building a low-pass filter to remove alternator whine in my car

Determine your location from relative FM radio signal strengths

In this post, we’ll take a brief measurement of regular old FM radio stations and try to determine where we are. It’s like a GPS but with local FM transmitters instead of satellites. I did this just for fun. I wonder if it could be used for indoor location and stuff? It is nowhere near as accurate as GPS. But whatever.

calibrated_result1Reading FM radio signal power

The first step is to get a reading of all the nearby radio stations. I used gnuradio and a HackRF One software defined radio. A simple flow-chart that takes the FFT and dumps it to a file is all I needed. I had to throttle the I/O or else my computer would freeze. I used 16M sample rate to have as wide a bandwidth as possible.

The gnuradio flow-chart used to gather data
The gnuradio flow-chart used to gather data

The file sink saves the FFT results in 4-byte integers and just has one 1024-length vector after the other. In a few seconds, I had a 50 MB of data. I did all the post-processing in an external Python script.

Continue reading Determine your location from relative FM radio signal strengths

Home automation with Z-Wave, Home-Assistant, Aeon Multisensor, HUE lights, and a Raspberry Pi 2

I’ve always dreamed of having a “smart-home.” There’s just something cool about being able to flip switches and read sensors and have a program turn a light on when you open the door, but only if it’s dark. This post is about home automation.

UPDATE: I made a video demoing everything:

Continue reading Home automation with Z-Wave, Home-Assistant, Aeon Multisensor, HUE lights, and a Raspberry Pi 2

Why your 32nd birthday is a momentous ordeal

Turning 32 may not seem like a very exciting birthday, but it is! In fact, it is the most momentous birthday of all, because it’s the first time in your life that you can’t show your age on a single hand.

Counting in binary.

First, a refresher. Binary, (popularly known as the number system of computers which think in terms of ons and offs, as represented by ones and zeros) is base-2, whereas good old decimal is base-10.

This means that in the decimal system, we have:

One 0001 100
Ten 0010 101
One hundred 0100 102
One thousand 1000 103

Whereas in the binary system, we have:

One 0001 20
Two 0010 21
Four 0100 22
Eight 1000 23

Continue reading Why your 32nd birthday is a momentous ordeal

My new color-changing LED lights

UPDATE 2023: After a decade of fun with HUE, I’m phasing them out now because they switched their policy to require connecting to their cloud rather than allowing local-only control. Screw those guys and get something else.

My wife got me an early birthday present: Philips HUE Color-Changing LED lights! They’re incredible. Look:

Right now I’m controlling them with my tablet, which is fine for changing colors and setting light alarms. I can even control them from afar thanks to my VPN. I will soon hook them up to my nascent Raspberry Pi powered home automation system (using the open-source Home Assistant program) that will allow me to trigger them based on various events like motion, doors opening, weather changing, or whatever. The future is here!

Each bulb uses 9 Watts but makes the same amount of light as a 60W conventional bulb, so they’re very eco-friendly. Furthermore, since they’re LEDs, they should last for 15 years of normal use! They communicate with a little hub that uses the ZigBee protocol (like Bluetooth but lower power and lower speed, good for home automation stuff).

Downside: They’re pretty pricey. I expect their coolness to drive demand enough to bring supply up. Expect these bulbs for $10 in the next few years.

Sending and receiving Morse code with a laser and a Raspberry Pi

Sending and receiving text with Morse code light pulses across the room (or to your neighbor) is a fun and cheap project you can do on a Raspberry Pi or Arduino or any other microcontroller.  This post explains how I did it, and how you can do it too.

Laser blinking
It’s working!

Hardware

The hardware is simple and cheap. Here’s my parts list:

  • Raspberry Pi B+ as the controller. This does the sending, receiving, and signal processing.
  • Photoresistor – Just a little guy that has variable resistance based on how much light is hitting it
  • A 220 Ohm resistor – to make a voltage divider with the photoresistor for reading the input signal
  • MCP3008 10-bit Analog-to-Digital Converter (ADC) – Since the RPi doesn’t come with an ADC, this is required for converting analog voltage from the photoresistor into a signal I can process on the RPi.
  • Laser module – to transmit with laser light. I got one from sunfounder.com for like 3 bucks.
  • Breadboard, wires

You can learn how to use the ADC at this Adafruit tutorial. I decided to talk to the ADC with the RPi’s hardware SPI interface, which I had already enabled. I wanted to be able to go very fast. (You can alternatively do SPI off of GPIO ports with software, if you prefer.) The laser just hooks directly between a GPIO and +5V. Here’s the layout:

Wiring diagram
The wiring diagram

And what it actually looks like:

The actual laserComm hardware.
The actual laserComm hardware.

Continue reading Sending and receiving Morse code with a laser and a Raspberry Pi

Data acquisition and live-plotting over the network with a Raspberry PI and Python

Sensors are fun! I wanted to keep an eye on the temperature of one of my home physics projects and realized I needed a thermocouple and a convenient way to read it. This post is about how I got one and wrote a Python program to send the data from a Raspberry PI over the network to my laptop, which plots the results in real time.

Thermocouple in fridge
Thermocouple in fridge

I bought a K-type thermocouple for several dollars that ranges from -100°C to 500°C. The Seebeck effect that makes it work only gives microvolts per degree so I needed a good amplifier for it. And since I wanted to read it on a Raspberry PI (which only has digital inputs), I’d need an analog-to-digital converter (ADC). Conveniently, the MAX31855 does amplification and ADC and is like $15, so I got one. Sweet. There’s even a Python library for it that makes it easy to access. Double-sweet.

The MAX31855 thermocouple amp and ADC
The MAX31855 thermocouple amp and ADC

Continue reading Data acquisition and live-plotting over the network with a Raspberry PI and Python

My old flux capacitor project

Alright, this is an oldie, but ah… well… it’s and oldie where I come from. In 2005, I  had some healthy spare time and decided to build a flux capacitor. I posted the details on my old webpage. I just rewired a battery pack on it and it’s working fine so I figured it was time to get it back online again. So, here it is. How to build a LED flux capacitor.

The Concept

In the movie Back to the Future, Dr. “Doc” Emmett Brown completed his life goal of making the flux capacitor a reality. Here’s the story:

“I was standing on the edge of the toilet hanging a clock, the porcelain was wet, I slipped, hit my head on the edge of the sink — and when I came to I had a revelation! A vision! A picture in my head! A picture of this! This is what makes time travel possible! The Flux Capacitor.”

-Doc, Back to the Future

The Flux Capacitor
The Flux Capacitor

Unfortunately, I didn’t have room for the time circuits or nuclear reactor to generate the 1.21 jigawatts that the flux capacitor needs to travel in time so we’re going to have to go with the next best thing: A 30 LED sequencer!

Continue reading My old flux capacitor project

Reading out a Crookes radiometer (light-mill) with Python and OpenCV

Since I’m on a late 1800s physics kick, I’ve been staring at my Crookes radiometer a lot.

My Crookes radiometer, or light-mill
My Crookes radiometer, or light-mill

You might remember these from the hands-on museum. Today, these are just novelty items, but back in the 1800’s, there were actually scientific instruments that could quantitatively read out the amount of incoming radiation (like visible or infrared light). They were generally read out using a calibrated spinning disk with slots in it. It’s like when you have a fan spinning in a dark room, and you adjust a strobe light until it looks like the fan isn’t spinning. Then, if you know how fast the strobe is blinking, you know how fast the object is spinning. This is called a stroboscope.

Well, I don’t have a stroboscope. But I do have a digital camera and a computer. As it turns out, I can read the Crookes radiometer using that!

Continue reading Reading out a Crookes radiometer (light-mill) with Python and OpenCV

The modern era passed through a cathode ray tube

Or, why I built a cathode ray tube in a wine bottle.

I was leisurely reading Linus Pauling’s textbook, General Chemistry, the other day, and I found the history he threw in there with the science to be thrilling. For instance, I learned quickly that the Greek word for amber, elekton, forms the base of our word electricity, so named by William Gilbert in the late 1500s because the ancient Greeks knew that rubbing amber with wool would attract feathers and stuff. As a nuclear engineer whose job it is to make electricity, this was a fun revelation. Pauling continues to mix physical realities with the experiments used to prove them, and doing so, he quickly arrives at the cathode ray tube. After reading and thinking about it, I had another revelation. It turns out, I realized, that some large fraction of modernity, from the world order to modern health, the environment, politics, and the media passed through a cathode ray tube. Here’s how.

General Chemistry cover
General Chemistry by Linus Pauling

Continue reading The modern era passed through a cathode ray tube

Remote ham radio operation through a Raspberry Pi

This post is about how I set up remote operation on my ham radio through a Wifi network, over a VPN, and around the world using a Raspberry Pi, like this:

radio-link-global

This could be useful for people who travel a lot and want to be able to use their rig while away. Or for people who want to set up their radio and antenna far away from where they actually live (e.g. apartment dwellers who have friends or parents who live in the boonies and wouldn’t mind you erecting an antenna). If you want to skip the VPN and just control your ham shack from your kitchen, that’s even easier.

I did this all with an ICOM-7100 all-mode radio, a Raspberry Pi B+, a Buffalo DD-WRT router/VPN server, and a laptop running Ubuntu 15.04. This post focuses on the radio control and networked audio but not on setting up the VPN.

Continue reading Remote ham radio operation through a Raspberry Pi

My first day on the amateur radio HF bands

I got into ham radio a few months ago and upgraded to a General-class license last weekend. This is a big step for ham radio people… the moment where you go from being able to talk to people ~30 miles away to being able to talk around the world. Anyway I went out and got a new 100W all-band, all-mode radio, an auto antenna tuner, a deep cycle battery, a 30A power supply, and a mini-Buddipole antenna. Woo!

I had a lot of trouble getting my first contact. I tried every night after work all week. I tried from Volunteer Park, my communal rooftop deck, and my friend’s roof on the 33rd floor of his building. I set the Buddipole up for 20m and heard people from the park but they couldn’t hear me. On my rooftop, I got nothing but S9 noise everywhere and couldn’t hear a thing. Same story from friend’s roof.

Well, I found that you can’t just use the settings that come in the Buddipole manual. Especially if you have the 8ft mast. It’s not high enough to do a 20m dipole efficiently (all RF goes straight up in the air. Read this whole book to understand). So you have to set it up as a vertical like this:

Buddipole as 20m vertical
Buddipole set up as a 20m vertical.

Continue reading My first day on the amateur radio HF bands

Installing the RF shield in a HackRF One

I recently got a HackRF One software defined radio (SDR) to go along with my new Ham radio hobby. I’m new to all this, but one of the first things I noticed was that I was picking up a lot of radio frequency interference (RFI). I had purchased a RFI shield as part of the kit but had to install it myself. This post shows how I did it.

Opening the HackRF enclosure

The first challenge is opening the enclosure. To do this, first take the bolts and washers off of each of the SMA antenna connectors. Now, go in above one of the connectors with a little screwdriver (maybe put electrical tape over it) and start popping up the enclosure. Eventually you will pop it all up.

Installing the RF shield

Now we have to solder the RF shield onto the board. There’s a dotted line that shows where it goes.

Here's where the RF shield will go.
Here’s where the RF shield will go.

Continue reading Installing the RF shield in a HackRF One