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

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

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

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

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

You can use open-source Linux for most stuff these days

Linux is an open-source operating system that you can download and install on your computer to complement (or even replace) your current operating system (Windows or MacOS). It started out when some guy wrote some code and gave it to the world community for free. It has become huge, and now provides the engine of Android phones and tablets, runs about 40% of the servers that make up the internet, and powers 97% of the world’s supercomputers. It’s a stunning success in the social open-source experiment.

For home use, it is just now ditching a reputation of being only for nerds, scientists, and hobbyists like me, with lots of headaches getting software and hardware working nicely with it. Really, I’ve been using it at home on my laptop since 2007 and it’s evolved to a point where I think it’s totally usable for most people. It also has a focus on privacy, security, and stability. Since the code is open (everyone can see and change how and why it works), there’s less mystery about what anyone is doing with your computer and more control to get it to do what you want. It was the speed and low-resource requirements that brought me to Linux originally, and it’s the quality and open philosophy that has made me a real proponent.

My desktop
My freshly-updated Ubuntu 15.10 desktop

Continue reading You can use open-source Linux for most stuff these days

Import precedence for different types of python extensions

I was doing some speed tests with cython in Windows and started wondering what the import precedence was between py, pyc, and pyd files (not to mention pyo). So I did a simple little test with two files, test.py and test2.py. Test.py just had a print statement in it and test2 just imported test1 (so it would create the pyc). I compiled test.py with cython into test.pyd and then changed test.py to print something else.

Conclusion: The pyd file was always imported if it was present. If it wasn’t there, then the new print statement from the new test.py was printed out. I’m sure this is documented somewhere but I’m not sure where. The conclusion holds if there are “optimized” pyo files present as well.

how to fix: ctrl-c closes ipython within console2

Just FYI, I was having a problem with ipython 0.12 running within Console, where pressing Ctrl-C to cancel an operation in a Python would actually just close the whole ipython window! It was horrible, since before I reinstalled everything it wouldn’t do that. Anyway, there’s an email chain talking about this here, but it’s irrelevant to this particular problem, since I’m using mainline (non-dev repo) versions and don’t know what an ETS is.

Thankfully, there’s a very simple solution (assuming you made my same mistake). Rather than setting the console tab to C:python27scriptsipython.exe, instead set it to C:python27python.exe C:python27scriptsipython-script.py and Ctrl+C will give a KeyboardInterrupt and leave you in ipython, just like the good old days!

Building a python extension with Trilinos 10.10 on 64-bit Windows 7

Continuing the journey, the folks at work upgraded me to 64-bit Windows 7 and the Trilinos folks updated to 10.10. Needless to say, I had to rebuild. I can’t definitively say which of these steps is necessary but I can tell you that if you follow them, you can compile a C++ python extension that uses many aspects of Trilinos on this system. And not just a few packages from Trilinos either. In fact, I’m currently using all of the following:

  • Epetra
  • AztecOO
  • Anasazi
  • Teuchos
  • epetraext
  • Amesos

To do this, first run the trilinos cmake system without shared libraries. Then build. This builds things like epetra.lib. Now, go back and turn on shared libraries and build again, this time with shared libraries turned on. This builds the dlls, which I believe are required to build a python extension. If one of the ones you needs fails, just go in to Visual Studio 2008 and open up the Trilinos solution. Right click the project. Change from a static library to a dynamic librray. Change Use of MFC to “Use MFC if a Shared DLL.” Change Use of ATL to “Dynamic Link to ATL.” The rebuild the package. The DLL should be created.

Build trilinos shared library
VS 2008 options to build shared libraries

Once all the static and shared libraries are built, I didn’t even mess with environmental variables (being a grad student and all) so I just copied them all into the build directory of my Python extension. On import, it worked just fine. Amazing!

I have yet to try linking to MSMPI and running large reactor problems on Microsoft HPC but that will be coming someday.

favorite programming language jokes

These started coming up at work and people kept chiming in new ones. Here’s a list. Sorry in advance for the offensive one.

  • What’s a pirate’s favorite programming language?
  • What’s a miner’s favorite programming language?
  • What’s a hispanic’s favorite programming language?
  • What’s a diver’s favorite programming language?
  • What’s a mongoose’s favorite programming language?
  • What’s a Seattleite’s favorite programming language?
  • What’s the army’s favorite scripting language?
  • What’s the little mermaid’s favorite scripting language?
  • What’s Beethoven’s favorite programming language?
  • What’s a Frenchman’s favorite programming language?

Hilarious. Answers below.

Continue reading favorite programming language jokes

building a python extension with trilinos on linux and windows

Continuing my python extension project, I’ve now successfully built a toy python 2.7 extension in C++ that uses the Epetra package from Trilinos 10.8. I’ve built it on Ubuntu 11.10 (with gcc) and on Windows XP (with Visual Studio 2008) using distutils. It’s a bit of a hack, but it works and is a path forward for me.

I started with Linux, because I figured it would be easier. I learned a few things along the way. First, you have to have built Trilinos with shared libraries enabled. This is required for how Python handles things, I guess, and is made clear under the heading “Shared Libraries” in this file. The PyTrilinos package (which is effectively a professional set of python-trilinos extensions, btw. I needed a custom one!) needs them as well. So run your cmake-gui and check the shared libraries button. Besides the libepetra.a in the build folder, you’ll now also find a libepetra.so. In Windows, you’ll get >500 errors if you compile all of trilinos with shared libraries, but Epetra at least worked.
Continue reading building a python extension with trilinos on linux and windows

my experience compiling against Trilinos on Ubuntu

I’m just embarking on a historic journey to learn a bit about the Trilinos math library.  To get started, I’ve gone through the hands-on tutorial a bit and after a few tries, I’ve gotten something compiled.

Trilinos 10.4 is available in the repositories for Ubuntu (11.10 confirmed). But Trilinos 10.8 is out now, so I had to build my own. Their instructions with CMAKE were quite good and the build process didn’t have too many hiccups. I found that the cmake gui is the way to go. Make sure you enable Didasko (the tutorial) in the cmake gui. When you do this, a few more Didasko options show up so you have to go enable those too.
Continue reading my experience compiling against Trilinos on Ubuntu

Installing ERANOS 2.1 on a 64-bit linux workstation

I just built ERANOS 2.1 reactor analysis suite from France on a 64-bit linux workstation with Red Hat 7. It wasn’t that bad, as the CEA has done a great job at automating the installation process. I’ll briefly discuss how things went.

First of all, don’t cd into the UTILS folder and run Install. You have to do as it says and run UTILS/Install if it doesn’t work the first time. Also as it says, it’s smart to copy all the library disks over before loading the code DVD.
Continue reading Installing ERANOS 2.1 on a 64-bit linux workstation

ipython on windows

iPython is a very nice way to fiddle around with Python interactively. Most beginners just use IDLE for this, since it comes with Python. But as you get to plotting stuff, you’ll find that IDLE just doesn’t cut it (it freezes every time you plot anything). So you try the regular python command line (on the black screen) but get frustrated that you can’t change directories or use tabbed completion or anything. You hear about ipython and try to use it but it’s not very obvious. Well all you have to do is make a shortcut and you’ll be off and running.By the way, if you had started on Linux in the first place, you wouldn’t have to deal with all this! Anyway, on Windows,

0. Make sure you have Python installed with matplotlib and numpy modules.

1. Get ipython from http://ipython.scipy.org/ install it from the download page for your version of python

2. Make a shortcut to python.exe and then right click it and hit properties to change where it points to to:

3. Double click the shortcut.

Yay. Now you have ipython on windows with matplotlib interactive capabilities! I suggest having your text editor open in one window and this ipython window in the other. Edit your code, save it, and then type “run mycode.py” to run it in the interpreter.

A nice screenshot of an interactive matplotlib session on Windows

Anyway.

online happiness

I’ve found four excellent things online recently and think I should re-share them to all zero of my faithful blog readers. Hi friends! Anyway, I just posted a rant about Twitter, so no need to go there again. That’s the first one.

My friend Adam showed me this excellent free PDF book by David MacKay called Sustainable Energy – without the hot air. It is straight talk about all the crazy myths and misconceptions going around about renewables and other energy issues. The first few items on that link are raving review one-liners by high-profile peeps. Well written with much infused sarcasm.

And from Slashdot, I read a bit of this pdf (A Mathematician’s Lament) on the status of the USA mathematical education system. It’s twenty-five pages of welcome truth. Again sarcastic and wonderful.

Finally, there’s the DropBox. I’d heard about it earlier, but at work in Seattle where I’m actually using 2 computers, it’s become invaluable. It seamlessly integrates into my file managers (My Computer in windows, Nautilus in Ubuntu, and I think Finder in Mac). When I drag or change a file in my designated drop box folder on any computer, it automatically synchronizes across all computers. It’s superbly wonderful. As a bonus, it’s web interface keeps versions of every single update. So if you want to go back to the file you overwrote 2 days ago, no problem, there it is. Click this link to accept my referral and give me 250 extra MB! Or this one to sign up without giving me a bonus.

the value of twitter

OK, I used to think twitter was stupid. I imagined it as just a big collection of facebook status updates. Personally, I couldn’t care less about you going to the grocery store. But then I went to the ANS conference in Atlanta and realized what the big deal was. You can embed tags in your twitter posts, using the # symbol. For instance, at the ANS conference, if you say something and put #ans09 in it, everyone who searches #ans09 can see what everyone who said #ans09 has posted. So you go there and it’s like: “hey a group of us here at #ans09 are going to max’s down the street. come on by!” You try #fremontfair for the solstice parade happening in seattle tomorrow and it’s all “PCC RT @amyhale: Getting prepped to live-blog, tweet tomorrow’s #Seattle #Fremontfair the “Center of the Universe”! Watch 4 updates + audio too!”

Another feature: you can do it all on SMS on your phone. So imagine a group of people going out. If they all set their phones to “follow” the same person, he or she can just say: “ok going to Brown Jug now.” Or “going to Bab’s now.”  and everyone will get texts with that info. That’s actually new and useful communication right there.

So sign up for it. Do some searches for stuff you’re interested in. Up-to-date collective knowledge is at hand.

Actually the real reason I checked it out was all the buzz about the Iranians using it to organize protests. Apprently the US state department asked twitter to delay a scheduled maintenance window so the Iranians wouldn’t be left in the dark. Cool.

BTW, if you’re all interested in whether or not I’m at the grocery store, I’m partofthething on twitter.