Controlling Hue Bulbs With WeMo Light Switch

Previously I wrote about controlling Philips Hue bulbs with a Harmony remote here:

I finally got around to installing a WeMo light switch to have a switch type device to control these lights.

It has to be wired as described here:

That is, you need to have power to the switch but not have the switch actually control the light fixture, the light fixture must have continuous power.

Once this is done, configure your new WeMo light switch in the WeMo smartphone app and give it a name.

I have a much nicer set of code than described here in a github repository here:

Now we can use a little daemon to detect switch activation, let's call it wemo_switch_daemon and put it in ~/bin.

#!/usr/bin/env python

import subprocess
from ouimeaux.environment import Environment
from ouimeaux.signals     import statechange, receiver

env = Environment();

switch = env.get_switch('rafael_living_wemo')

@receiver(statechange, sender=switch)
def switch_toggle(*args, **kwargs):
    if kwargs['state'] == 1:['~/bin/', 'on'],  shell=True)
    else:['~/bin/', 'off'], shell=True)


You'll need to install the Python library with:

pip install --upgrade ouimeaux

Make sure the daemon runs with no error, then add a crontab entry to launch it on startup, with e.g. crontab -e:

@reboot             exec ~/bin/wemo_switch_daemon >/dev/null 2>&1 &

On Mac you can use "LaunchD Task Scheduler" and making a job to run at "load and login." On Windows you'd use Task Scheduler.

If you are not using the system python, either change the shebang or prepend the full path to your python.

Here is the toggle_hue script:

#!/usr/bin/env python

import socket, os.path, sys
from phue import Bridge

bridge = Bridge('rafael_living_hue')

arg = sys.argv[1].lower() if len(sys.argv) > 1 else 'toggle'

    on_state = { 'on': True, 'off': False, 'toggle': not bridge.get_group(1, 'on') }[arg]
except KeyError:
    raise ValueError("command must be 'on', 'off' or 'toggle'")

bridge.set_group(1, { 'hue': 33862, 'sat': 50, 'bri': 254, 'on': on_state }, transitiontime=0)

You need phue for this script, install it with:

pip install --upgrade phue

UPDATE: I made some improvements to this post and made the toggle_hue script much faster, with some help from the phue author. Also a link to my new github repo with better code has been added.


Last modified: 2016-1-24 (日) at 10:39 pm

Fixing the Microphone and Skype on a Linux Laptop

Many sound chipsets in laptops have a problem with linux where they will only work if only the left channel is enabled, and not the right channel. And this of course matters for Skype. I ran into this situation recently and it drove me utterly bonkers, because I could not find a permanent solution, but I finally did and will share it with you.

Installing Skype

I'm assuming you are using an Ubuntu or Ubuntu-like such as Mint, if not follow along and change the steps as appropriate for your own distro. The first step is to install the skype package, this is usually as simple as:

sudo apt-get install skype

If you do not have a skype package available in your repository, install the package off the website.

Skype is a 32 bit app, so the next step is to install the 32 bit pulseaudio library:

sudo apt-get install libpulse0:i386

Now you'll want to add an entry to your startup programs for your Desktop Environment to launch Skype on startup.

IMPORTANT: you must add a delay to your Skype launcher, or the icon will not appear in your notification area. Use a command such as the following:

sh -c 'sleep 3; skype'

In the skype login window, mark the checkbox in the lower right to 'login when Skype starts' so that you are logged in on startup.

Testing Skype

Once you are logged in to skype, go into preferences -> sound devices. The sound devices listed should be something like "Pulseaudio server" and not "virtual device". If it says "virtual device" you need to make sure you installed the 32 bit pulseaudio libs as described earlier.

Click "make a test sound", you should hear a sound. Check the "video devices" section to make sure your webcam works and you can see yourself.

Go back to the "sound devices" section and make a test call. When prompted, say something and wait to hear it repeated. If you heard your own voice, then you can stop here and there is nothing else you need to do, If you did not, then read on.

Open pavucontrol and go to the input sources section. Find your internal microphone, click the 'set as fallback device' button and the 'unlock channels' button. Slide the right channel to zero and the left channel to around 70%. You may hear an audible pop when you do this.

Now, without closing pavucontrol go back to Skype and make another test call. You should hear your own voice now.

Unfortunately this fix is not permanent, as soon as you close pavucontrol it will stop working again, I will describe how to make this fix permanent.

Reconfiguring Pulseaudio

We will reconfigure pulseaudio to pass everything straight to alsa and not do anything to the sound chip.

Edit the file /etc/pulse/, find the load-module alsa-sink etc. lines and change them to the following, removing the hash mark at the beginning to uncomment them, they should look like this:

load-module module-alsa-sink device=dmix
load-module module-alsa-source device=dsnoop

Find the lines that look like this:

### Automatically load driver modules depending on the hardware available
load-module module-udev-detect
### Use the static hardware detection module (for systems that lack udev
load-module module-detect

And comment them out, by placing a hash mark at the beginning of each line to look like this:

#### Automatically load driver modules depending on the hardware available
#load-module module-udev-detect
#### Use the static hardware detection module (for systems that lack udev
#load-module module-detect

Save the file. Make sure that when you upgrade your system the file is not overwritten or the changes will be lost.

Installing the Nightly ALSA PPA

Some laptops need a newer ALSA for the sound to work properly, run these commands:

sudo apt-add-repository ppa:ubuntu-audio-dev/alsa-daily
sudo apt-get update
sudo apt-get install oem-audio-hda-daily-dkms

And then reboot.

NOTE: if you have a custom kernel that is newer than that of your ubuntu base, you will need to tweak dkms module a bit as follows:

First edit /etc/apt/sources.list.d/ubuntu-audio-dev-alsa-daily-trusty.list and change the dist name from "trusty" to something newer like "utopic", then run:

sudo apt-get update
sudo apt-get install oem-audio-hda-daily-dkms

If the module builds and installs, you are good to go, if it says your kernel version does not match, then do the following:

Edit /usr/src/oem-audio-hda-daily-0.201503121632~ubuntu14.04.1/dkms.conf, the version string on the directory may be different but the directory is in /usr/src. Remove the following line:


Then run:

sudo dkms install -m oem-audio-hda-daily/0.201503121632~ubuntu14.04.1

The version will probably be different, you can find it in the directory name under /usr/src .

Now reboot.

Reconfiguring the ALSA Mixer

Log out of your X session, switch to a virtual console with ctrl+alt+F1 and stop your display manager. Using a command such as:

invoke-rc.d mdm stop

The service may be gdm, kdm, lightdm, etc. Whichever your display manager is. When you press alt+f8 or alt+f7 there should not be an X session.

Make sure you are in the 'audio' group. As root, edit /etc/group and make sure the audio line looks something like this:


Once this is done, exit and log back in on the virtual console.

Now, launch alsamixer. You may need to run it with sudo if you did not add yourself to the audio group. Set the master volume to a reasonable amount, such as 70% with the up and down keys. Fix the "Internal Mic" section, make sure it's unmuted, if it's muted press M to unmute it. Likewise, unmite the 'Mic Boost' section.

Go back to the "Internal Mic" section. The Q key raises the left channel and the Z key lowers it. The E key raises the right channel, and the C key lowers it. Use these keys to set the left channel to around 70% and the right channel to zero. Do the same thing for the "Mic Boost" section. Then press Escape to exit alsamixer.

Run this command to make your settings permanent:

sudo alsactl store

Now we're going to test the microphone. Run this command to record a sample sound:

arecord foo.wav

Say something and press Ctrl+C to exit the recording. Play back the recording with:

aplay foo.wav

If you can hear yourself, the alsa mixer is configured correctly.

Final Test

Reboot the laptop with:

sudo reboot

Once you are back in your Desktop Environment, make sure sound works and open skype from the icon in the notification area and try another test call. You should hear your own voice now.


Last modified: 2015-3-15 (日) at 8:37 am

Controlling Hue Bulbs With Harmony on a Mac

I wanted to be able to press a button on my harmony smart control to turn on my Hue bulbs.

I'll briefly describe how I did this.

Harmony Configuration

First, you need to configure your harmony to work in Plex mode with your Mac activity and install Remote Buddy on your mac.

The Remote Buddy configuration I used is described here, and is very time consuming.

NOTE: you will need to choose the second type of apple remote when setting up the hardware remotes, it defaults to the first type which has fewer buttons and will not work. The black one, not the white one.

Hue Control Script

Next we are going to write a little Python program to turn the Hue lights on and off, here is mine:

#!/usr/bin/env python

import socket, os.path, sys
from phue import Bridge

bridge = Bridge('rafael_living_hue')

arg = sys.argv[1].lower() if len(sys.argv) > 1 else 'toggle'

    on_state = { 'on': True, 'off': False, 'toggle': not bridge.get_group(1, 'on') }[arg]
except KeyError:
    raise ValueError("command must be 'on', 'off' or 'toggle'")

bridge.set_group(1, { 'hue': 33862, 'sat': 50, 'bri': 254, 'on': on_state }, transitiontime=0)

You will need to install phue, as described here:

NOTE: I use the Homerew Python, I recommend you do the same.

The Bridge call takes a Hue bridge IP address, I recommend assigning a static DHCP lease on your router and rebooting the bridge to use it. This will give you a nice hostname like the one I'm using here.

This script will set the Concentration theme. If you want another theme, set it first using another app on your phone or whatever, then use get_light to read the hue, sat and bri values you need from one of the lights.

Someone mapped the values for the default themes here:

NOTE: you will need to test the script before we map it in Remote Buddy, and the first time you run it you will need to press the link button on your bridge first.

Put the script somewhere like:


Make sure to chmod +x it so it is executable.

Remote Buddy Mapping

- - From the Remote Buddy menu, choose Behaviour Construction Kit and make a new action in the Action Factory pane. I called mine "Toggle HUE" in group "HUE".

Under implementation add Applescript, and for the code add the following:

do shell script "/Users/your-user/bin/toggle_hue"

replace the path with the actual path of the executable script. If the script is not executable, prepend the path with "python " to run it with python.

Next, in the Metadata pane choose "Action globally available".

Close the Behaviour Construction Kit and open Preferences, go to the Mapping pane.

Go to the very top entry, Global Mappings. Find the button according to the Plex mapping described in the first section, I use the Yellow button, which is Remote 159 Select. For the action, go to "Miscellaneous" and your new global action should be there, choose it.

Now you can test the button on your harmony and it should toggle your lights on and off.

UPDATE: I added vastly better Python code for the hue toggle script.


Last modified: 2016-1-24 (日) at 10:38 pm

Windows 8 on an EEE PC 1000

Here I'll describe how to install Windows 8 on an EEE PC 1000 and have just about everything work properly. This guide may also be applicable to the 900 series, later models are generally much more simple to install Windows 8 on.

I put all the drivers you'll need here on my server:

check your RAM

The 1000 is upgradable to a max of 2gb of ram, the default is 1gb, you definitely want to do the 2gb upgrade. The proper chip should still be available and reasonably inexpensive.

check your SSD

Ideally you already have a runcore/kingspec or whatever in your eee pc, if not read on.

The stock 32 gig ssd is very slow, probably too slow to run win8. Unfortunately it's impossible to get a runcore right now, but the 70mm kingspec mini-pcie ssds can still be obtained on ebay from sellers based in china, they should work adequately. The 32gig is the minimum you need, to have windows and some more larger programs installed a 64gig is better, and the 128gig will be a bit faster.

I don't know if windows 8 is usable on the stock 32gb ssd, I do remember it being excruciatingly slow, YMMV.

There are two ssd slots, one that is very easy to get to near the ram underneath the ram cover, and one for which you have to dissassemble the whole netbook and do a bit of a hardware modification to install. The one on the bottom side of the motherboard is the primary and a half length (the 8gb one.) You'll want to gently pry off the metal bracket that holds it with a pair of pliers and secure a full length ssd with some electrical tape (be careful not to use too much to not block the sd card slot.)

The easiest way to go would be to replace the ssd under the ram cover and use the stock 8gb primary which is reasonably fast for readyboost and the page file (

install windows 8

The first part is simple, just install windows 8 using the installer, boot it either from a usb stick or usb dvd drive. It should install without any issues.

enable 1024x768 virtual resolution so that metro apps work

The 1024x600 resolution of the 1000 panel is below the minimum required for metro apps, we can solve this problem easily enough by following this guide:

After doing this registry change and rebooting and selecting the 1024x768 resolution, I suggest going into the "make text and other items bigger or smaller" under the resolution tab and choosing 125% scaling to offset some of the squashing from the increased virtual resolution.

Now metro apps should work perfectly on your 1000.

install the ACPI hotkey driver

When you go to device manager, you will see one "unknown device", next we will install the driver for it.

This happens because the 1000 like many Asus laptops does not map the Fn keys to normal keyboard key codes, but instead they are a separate physical device. The ribbon connector in the upper left corner under the keyboard is this ACPI hotkey device.

Grab the XP ACPI hotkey drivers here:

Unzip the file, then right click on AsusSetup.exe, go to compatibility and select "windows XP sp 3 mode" and "run as administrator".

Run the installer, check "this program ran correctly" after it finishes, it doesn't matter if it looks like it exited early, we don't need those programs anyway.

Reboot, then go into programs and features in control panel and uninstall the ACPI package. Reboot again, the driver should still be installed, and you should not see an "unknown device" in device manager (the asus ACPI device will be somewhere under the system devices or acpi devices list.)

install the Dell Elantech touchpad driver

I recommend the Dell Elantech driver, which you can get here: You might try the latest Asus one as well, but I like how the Dell one works better.

I was not able to get tap to click to work with either of them, unfortunately, I will try to resolve this problem somehow in the future (perhaps by adding Elantech support to the TwoFingerScroll open source driver.)

For all the other features, right click on the touchpad icons in the systray and configure all the features you want, such as two finger scrolling.

But other than having to use the physical touchpad buttons, everything else works pretty well with the Dell elantech driver, like two finger scrolling.

Note that you need to do a horizontal scroll movement in the start screen, rather than a vertical one like on most touchpads with windows 8.

install the windows 8 hotkey service

Install this driver and reboot.

After doing this, your Fn keys should work (by using the ACPI device driver you installed earlier in conjunction with this service) but you'll notice that that the volume up and down keys are reversed, and that it complains on startup about a missing touchpad driver.

To fix this problem, copy this file which I made by hacking the Asus .exe with IDA and OllyDbg and stripping the certificate with delcert to C:\Program Files\EeePC\HotkeyService as HotkeyService.exe.

Reboot again, now there should not be a message about the touchpad and the volume keys should work correctly!

all done

That's all, you now have a reasonably well performing, fully functional windows 8 netbook.

The only downside is lack of tap to click for the touchpad (although that may work for you) and I will try to solve this problem in the future.

If you have any additions/corrections/comments or questions about this guide, feel free to email me at rkitover at gmail.

Good luck!


Building XS Modules for 64bit ActivePerl on Windows

Here I'll discuss how to build extensions for 64bit ActivePerl for Windows using freely available tools.

First let's discuss which perl for Windows you need if you haven't decided that yet.

For most general use and development you want a 32bit ActivePerl or Strawberry Perl. ActivePerl has the advantage of some difficult to build modules available as easy to install PPM packages in the ActiveState repositories or some of the third-party repositories. In other ways the two are similar, ActivePerl will now automatically install the MinGW toolchain and dmake when you need it to compile an extension, the tools Strawberry Perl comes with, or you can just type ppm install MinGW.

The reason you would generally prefer a 32bit perl on Windows is that many modules, especially some Win32:: modules are not compatible with 64bit perls yet; and in the case of ActivePerl, there are far more PPMs available for the 32bit builds.

Your choice of whether to use a 32bit or 64bit perl may be dictated by factors other than convenience and compatibility however, you may need to link the interpreter into a native process of a certain bitness, or link a .dll library of a certain bitness into the perl interpreter. Or you may need to use either a 32bit or 64bit ODBC driver which will only work with that respective bitness of perl. And so on.

Once you've decided that you need to use a 64bit perl, you have a choice between Strawberry Perl and ActivePerl. Strawberry Perl comes with MinGW-w64 and dmake bundled in the distribution and pre-setup for you, so you can skip the setup I describe here for ActivePerl. If you choose to use ActivePerl, for the availability of (some) PPMs or other reasons, read on.

For 64bit ActivePerl you have the choice of two freely available tools to build extensions, the Windows SDK and the MinGW-w64 suite, setup for both is described below.

The Windows SDK

The freely available Windows SDK (current version) contains everything you need including a set of compilers. If however you are getting the Windows 8 SDK you will also need to get Visual Studio Express 11 for the compilers, as the Windows 8 SDK no longer includes a set of compilers.

Now you need to modify your environment to make the SDK tools available to perl (CPAN installations, etc..) I recommend using Rapid Environment Editor, or you can make .cmd file and modify your cmd.exe shortcut to add the /K option and the path to your .cmd file with your settings. I attempted, with some measure of success, to make a system of switching between different perls in a single cmd.exe session in this article.

The settings you need for the Windows 7 SDK are as follows (modify to taste:)

set PATH=C:\Perl64\site\bin;C:\Perl64\bin;C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\Bin\amd64;C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\x64;C:\Windows\system32;C:\Windows
set INCLUDE=C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE;C:\Program Files\Microsoft SDKs\Windows\v7.1\Include;C:\Program Files\Microsoft SDKs\Windows\v7.1\Include\gl
set LIB=C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\Lib\amd64;C:\Program Files\Microsoft SDKs\Windows\v7.1\Lib\X64
set LIBPATH=C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\Lib\amd64

Now launch cpan in cmd.exe and try to install an XS module such as Class::XSAccessor to test everything out.

If you get link errors about not being able to find bufferoverflowU.lib, edit C:\Perl64\lib\ and remove all instances of bufferoverflowU.lib. This shouldn't happen with the newer ActivePerl builds however.

The settings for the Windows 8 SDK with the Visual Studio Express 11 compilers should be similar, but I have not tried that yet, so don't know the details.


The ActivePerl MinGW mode mostly works with MinGW-w64, although it is meant for the 32bit builds with older suites so some tweaks are necessary.

First download the WIN64 native compiler suite from the MinGW-w64 download page in the WIN64 Downloads -> Personal Builds -> rubenvb -> release section. The file will be named something like x86_64-w64-mingw32-gcc-4.7.0-release-win64_rubenvb.7z. Unpack with 7-zip or WinRAR everything below the top level directory in the archive to C:\MinGW_w64 .

Modify your PATH to add C:\MinGW_w64\bin . See the part about environment settings in the previous section, I recommend Rapid Environment Editor.

Set the LIBRARY_PATH environment variable as follows:

set LIBRARY_PATH=C:\MinGW_w64\x86_64-w64-mingw32\lib

Now install dmake. We'll use a 32bit binary from CPAN so make sure that WOW64 is enabled in your OS if you are using an older server OS. Download the dmake dist from CPAN, open the archive, go into the dmake folder, and extract dmake.exe and the startup subfolder into C:\Perl64\site\bin . Then run:

icacls c:\perl64\site\bin\dmake.exe /grant your_user_name:(rx)

Next edit C:\Perl64\lib\ and remove all instances of bufferoverflowU.lib.

That's all there is to it. Now with gcc.exe in your PATH ActivePerl will go into mingw mode when it needs to build an extension, try it now by running cpan Class::XSAccessor or some such extension.

Note that if you will package Perl applications with built extensions, you will need to include the libgcc and libstdc++ (if there were any C++ extensions) DLLs with your package, to be run from the same directory as the perl interpreter or somewhere in PATH. This is also true for the new versions of the 32bit toolchain. The alternative is to include

-static-libgcc -static-libstdc++

in your LDDLFLAGS along with the default $Config{lddlflags}. I'm going to submit a bug report to ActiveState to make these options default for newer gccs.


Last modified: 2012-5-28 (月) at 10:51 am