Dirt cheap USB Temperature Sensor with python SMS alerting system.

facebooktwittergoogle_plusredditpinterestlinkedinmailby feather

In the last few weeks I had to design an effective and cheap temperature monitoring system for the server room. After searching a bit on the web I found this USB Thermometer Temperature dongle on Ebay, only 10 bucks with free shipping. As soon the sensor arrived, I plugged it into one Ubuntu based server and surprisingly worked immediately, below you can see the dmesg output.

[sourcecode language=”bash”]
[12737.064004] usb 2-1.3: new low speed USB device using ehci_hcd and address 6
[12737.161227] usb 2-1.3: configuration #1 chosen from 1 choice
[12737.164379] input: RDing TEMPer1V1.1 as /devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.3/2-1.3:1.0/input/input6

Along with monitoring the temperature I wanted to have an alarming system that sends alarm SMS message to mobile phones when the temperature has passed a certain threshold. So I subscribed to textmagic, an SMS gateway provider. Textmagic has a good set of API, and of course they have the python API which I used to write my Pytemp2sms.py script.

USB dongle software and settings.

[sourcecode language=”bash”]
apt-get install libusb-dev
git clone https://github.com/petervojtek/usb-thermometer.git
cd usb-thermometer/
cp 99-tempsensor.rules /etc/udev/rules.d/
cp pcsensor /usr/local/bin/

Reboot the server.

To test the dongle run the pcsensor command .
You must get this kind of output.

2012/04/11 14:30:50 Temperature 60.58F 15.88C

SMS alarm.

Textmagic python API installation.

[sourcecode language=”bash”]

apt-get install python-setuptools
easy_install PyTextMagicSMS


Pytemp2sms script.

Script download: http://bailey.st/code/bitsofpy/Pytemp2sms/

[sourcecode language=”bash”]

import sys
import subprocess
import fileinput
import textmagic.client

#Temperature threshold in C
threshold = 5
#Balance threshold
credits = 100
#TextMagic account details, before using textmagic service
#you need to register and obtain an API password
#(different from your login password)
username = "yourusername"
password = "APIpassword"
#Owner of the Textmagic sms account.This number will receive
#the credit balance .
owner = "+44phonenumberoftheowneraccount"

”’License: This software is distributed under
the terms and conditions of GPL – GNU
General Public License.”’

def usage():

print " ——————————————"
print "| Pytemp2sms |"
print "| |"
print "|Temperature Sensor with sms alert system. |"
print "| |"
print "|www.bailey.st |"
print "|phillip@bailey.st |"
print " —————————————— "

print "\n"
print "Usage instructions:"
print "\n"
print "Pytemp2sms.py checktemp | checkbalance"
print "\n"

def checktemp():

output = subprocess.Popen(["/usr/local/bin/pcsensor"], stdout=subprocess.PIPE).communicate()[0]
output2 = output.split()[4]
temp = output2[:2]

if int(temp) > threshold:

for phonebook in fileinput.input("/usr/local/bin/phonebook.txt"):

client = textmagic.client.TextMagicClient(username, password)
client.send("WARNING – Server room temperature above threshold!!! PLEASE CHECK!!!", phonebook)


def checkbalance():

client = textmagic.client.TextMagicClient(username, password)
balance = client.account()[‘balance’]
print balance

if balance < credits:
client.send("WARNING – Textmagic credit balance below threshold, please top the account", owner)


if len(sys.argv) < 2:

if "checktemp" in sys.argv[1]:

if "checkbalance" in sys.argv[1]:


Phonebook file.

The file phonebook.txt must contain all the mobile numbers that need to receive the alarm sms. Please follow this syntax:



[sourcecode language=”bash”]

*/30 * * * * /usr/local/bin/Pytemp2sms.py checktemp >/dev/null 2>&1
*/60 * * * * /usr/local/bin/Pytemp2sms.py checkbalance >/dev/null 2>&1



  1. Armando Ruddiger McGillacuddy
    June 11, 2012 - 9:37 am

    Thanks for the write-up, going to use this as a cheap and easy way to measure the temperature in my garage and workshop remotely. I’ll try to output it to something I can use in a web format and run Apache on the shop PC. Should be easy enough, but at least having the temp at will from an SSH session will be mighty helpful.


  2. thanks to you, i finally got my temper running on my nslu2. thanks a lot!

  3. Hi, pcsensor does report a temperature (good!):

    sander@R540:~/Temper/pcsensor-0.0.1$ sudo ./pcsensor
    2012/07/21 06:21:13 Temperature 83.75F 28.75C

    … but the problem is it is only about 20C here, so pcsensor is reporting 8C too high. The temper is not close to a cooler outlet, but just to be sure I will connect a long USB cable between laptop and Temper, and see what happens.

    Some more details:

    Bus 002 Device 013: ID 0c45:7401 Microdia

    [24450.941551] usb 2-1.5: new low-speed USB device number 13 using ehci_hcd
    [24451.043670] input: RDing TEMPerV1.2 as /devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.5/2-1.5:1.0/input/input21
    [24451.043937] generic-usb 0003:0C45:7401.0013: input,hidraw0: USB HID v1.10 Keyboard [RDing TEMPerV1.2] on usb-0000:00:1d.0-1.5/input0
    [24451.046547] generic-usb 0003:0C45:7401.0014: hiddev0,hidraw1: USB HID v1.10 Device [RDing TEMPerV1.2] on usb-0000:00:1d.0-1.5/input1

    This is on a Ubuntu 12.04 64-bit machine. I both used the original pcsensor, and one I compiled.
    My goal is too use the Temper in a Raspberry Pi (“Raspi”)

  4. PS:

    I put the TEMPer into a freezer for 5 minutes, and then put it back into my Ubuntu: temperature was at 0.75C, and then went up.

    So the Temper / driver combo is actually measuring temperature, but I’m not sure about it’s correctness.

    sander@R540:~/Downloads$ pcsensor
    2012/07/21 10:34:23 Temperature 33.35F 0.75C
    sander@R540:~/Downloads$ pcsensor
    2012/07/21 10:34:30 Temperature 36.73F 2.62C
    sander@R540:~/Downloads$ pcsensor
    2012/07/21 10:34:31 Temperature 37.17F 2.88C
    sander@R540:~/Downloads$ pcsensor
    2012/07/21 10:38:01 Temperature 65.53F 18.62C
    sander@R540:~/Downloads$ pcsensor
    2012/07/21 10:40:19 Temperature 70.93F 21.62C
    sander@R540:~/Downloads$ pcsensor
    2012/07/21 10:45:39 Temperature 77.00F 25.00C

  5. thank you

  6. FYI using this device on a Raspberry Pi. I did not need a powered hub as this was the only device connected (no keyboard or mouse) but without a USB cable to keep the sensor physically away from the Pi tempertures reported wer 8-10 degrees higher than the expected ambiant.
    30cm USB cable and the works fine.
    Mmmmmm hot Pi.

  7. I am using the thermometer with raspberry pi and works well (i am positively surprised with thermometer accuracy, but maybe I just won the good one).
    pcsensor lib has a minor bug – temperatures below zero are wrongly computed (e.g., instead of providing -10 C, the output is 246 C) due to some int overflow.
    here a fixed version:

  8. I got one of these in 2010 – works like a charm.

    FWIW, I just checked your link – did you notice that they are NOW changing folks $50 for S&H? They have others for $14, with the classic free shipping. Looks like classic cross-cultural victimization here.

    Also, wget http://www.isp-sl.com/pcsensor-0.0.1.tgz is now a 404.



  9. tobias adelgren
    January 8, 2014 - 6:52 pm

    I followed the instructions but the file “pcsensor” is no longer in the file package from Peter V. Instead there is a file called “pcsensor.c” I can run that file :-(

  10. Hi there. I’d love to set up the SMS aspect of this but I’m breaking down at this point:

    Pytemp2sms script.
    Script download: http://bailey.st/code/bitsofpy/Pytemp2sms/

    The install of PyTextMagicSMS goes ok. On the next command line I type #!/usr/bin/python. But then when I type import.sys I get an error that says -bash: import: command not found

    Not sure what I’m doing wrong here.

  11. GAaaaaaaaaaddddddAAAAAAAAAM you da man!
    I went through about 30 different blogs trying to get this to work and they all seemed to point to the same broken links.

    no matter how many times I wiped and reinstalled it wouldn’t work.
    This never appeared:
    2014/06/09 22:56:26 Temperature 84.09F 28.94C
    until now…

    mad props.

  12. Here is how to do it in CentOS with email alert and as a service deployment in less that 5 minutes

Leave a Reply

Your email address will not be published / Required fields are marked *