Software builded and deployed on Fedora 31 and Centos 7
Update 2022-11-19
Page is no longer maintained. I’m not using the sensor anymore.
Update 2020-11-25:
A beter script on Centos88 is:
source: https://gist.github.com/artms/5356eafcd1244c6fabc0f735e5de7096
updated: 2019-11-13
There are several expensive solution to monitor room temperature, rely on cloud solutions or maybe you need to pick up the soldering iron. There is an alternative on the market that comes cheap: The TEMPer device. It can be bought from Ebay or big known e-commerce websites like dx.com. I bought my TEMPer devices (413d:2107) from Ebay for 8,58 USD each.
To be able to successfully deploy a TEMPer device you need to have a little knowledge how to compile C code and Linux. To monitor properly the room temperature you want to use an USB extension cord.
The sellers I bought the hardware from are:
Step 1: Look up the device USB ID
There are several TEMPer devices sold as the same. They all do the same job, however be aware that the USB ID’s are different. Currently the 413:2107 is being sold and does not work out of the box with code to be found on the internet. Since I’m having the 413:2107 I’ll explaining how to make it work. I do not have the other versions. USB ID’s can be found with:
$ lsusb
If it is correct, there will be a rule containing this: Bus 006 Device 003: ID 413d:2107 , to be sure we also verify this with dmesg. You will find the following rules:
$ dmesg
input: HID 413d:2107 as /devices/pci0000:00/0000:00:10.0/usb6/6-2/6-2:1.0/0003:413D:2107.0003/input/input13
hid-generic 0003:413D:2107.0003: input,hidraw1: USB HID v1.11 Keyboard [HID 413d:2107] on usb-0000:00:10.0-2/input0
hid-generic 0003:413D:2107.0004: hiddev97,hidraw2: USB HID v1.10 Device [HID 413d:2107] on usb-0000:00:10.0-2/input1
If both are verified we are good to go and know that Linux recognizes the TEMPer device.
Step 2: Get the developer Distro packages needed to compile the TEMPer software
$ sudo dnf install hidapi-devel bc
Step 3: Git clone the needed software
$ sudo -i
$ cd /opt/
$ git clone https://github.com/edorfaus/TEMPered
$ cd TEMPered
$ cmake .
$ cd /opt/TEMPered/utils
$ make
$ cp hid-query /usr/local/bin
Step 4: Find out which hidraw device is our TEMpered device by trying to get metrics out of it:
$ ./hid-query /dev/hidraw1 0x01 0x80 0x33 0x01 0x00 0x00 0x00 0x0
0
No data was read from the device (timeout)../hid-query /dev/hidraw2 0x01 0x80 0x33 0x01 0x00 0x00 0x00 0x00
Device /dev/hidraw2 : 413d:2107 interface 1 : (null) (null)Writing data (9 bytes):
00 01 80 33 01 00 00 00 00
Response from device (8 bytes):
80 80 0a 21 4e 20 00 00
Our TEMPered device is allocated at /dev/hidraw2
Step 5: Create TEMPered script
$ vi TEMPered
#!/bin/bash
OUTLINE=”/usr/local/bin/hid-query /dev/hidraw2 0x01 0x80 0x33 0x01 0x00 0x00 0x00 0x00|grep -A1 ^Response|tail -1″
OUTNUM=”echo $OUTLINE|sed -e ‘s/^[^0-9a-f]*[0-9a-f][0-9a-f] [0-9a-f][0-9a-f] \([0-9a-f][0-9a-f]\) \([0-9a-f][0-9a-f]\) .*$/0x\1\2/'”
HEX4=${OUTNUM:2:4}
DVAL=$(( 16#$HEX4 ))
CTEMP=$(bc <<< “scale=2; $DVAL/100”)
echo $CTEMP$ chmod +x TEMPered
Test the script:
$ ./TEMPered
25.93
This is ‘all’ it takes to make it working. I tested the TEMPered sensor next to an analogue temperature sensor and the values matched. Unfortunately this script needs to be executed as root.
To avoid running the script as root, I suggest this udev rule (all on one line):
SUBSYSTEMS==”usb”, ACTION==”add”, ATTRS{idVendor}==”413d”, ATTRS{idProduct}==”2107″, MODE=”666″
Works on a debian 9 machine running 4.14 kernel.
I put this into /etc/udev/rules.d/99-tempsensor.rules
Dear Jean,
Thank you, I was struggeling with this. I will try this solution this week on a Centos 7 server.
Kind regards,
Maikel
Works great on Ubuntu 18.04 once I fixed all the backward quotes.
For Ubuntu you need to install libhidapi-dev:
sudo apt-get install libhidapi-dev
then compile as you outlined.
Thank you for this post!
Dear Anatoli,
I fixed the backward quotes. Something went wrong with a copy and paste. Thanks for pointing out and nice to hear it works 🙂
Having a problem in centos 7 using either line at
./hid-query /dev/hidraw
gets this response
Writing data (9 bytes):
00 01 80 33 01 00 00 00 00
Write failed: (null)
Try to play with hidraw device nummers. Here I have 3 and only one works (hidraw0% hidraw1% hidraw2%)
Also it is worth noting that maybe SElinux is blocking it. Check this with: $ sudo audit2allow -a
It responded to /dev/hidraw4
But now when executing the TEMPer script I get
./TEMPered: line 5: 16#ho: value too great for base (error token is “16#ho”)
(standard_in) 1: syntax error
Thanks
The difference I see is in the dmesg output.
[591817.570035] usb 6-2: New USB device found, idVendor=413d, idProduct=2107, bcdDevice= 0.00
[591817.570040] usb 6-2: New USB device strings: Mfr=0, Product=0, SerialNumber=0
[591817.576427] input: HID 413d:2107 as /devices/pci0000:00/0000:00:1d.0/usb6/6-2/6-2:1.0/input/input12
[591817.627401] hid-generic 0003:413D:2107.0006: input,hidraw3: USB HID v1.11 Keyboard [HID 413d:2107] on usb-0000:00:1d.0-2/input0
[591817.630411] hid-generic 0003:413D:2107.0007: hiddev0,hidraw4: USB HID v1.10 Device [HID 413d:2107] on usb-0000:00:1d.0-2/input1
note: usb-0000:00:1d.0-2/input0
Jim
Got it! It was backward quotes on the third line in the sed statement. Now to get fahrenheit..
Thanks, I altered the backward quotes. I do believe changing to fahrenheit isn’t that difficult, see last post @ https://www.linuxquestions.org/questions/ubuntu-63/shell-script-to-convert-celsius-to-fahrenheit-929261/
Good Day
I keep getting this error even though I have corrected all the backward quotes. I am running Ubuntu 16.04.
./TEMPered: line 5: 16#ho: value too great for base (error token is “16#ho”)
(standard_in) 1: syntax error
Dear Phinda,
I should install Ubuntu for this, because I only run Centos systems or RedHat. Let me check later this week in Vagrant.
I have the same error on debian 10.3
Can’t figure it out…
Did some scripting on my own, based on the work described above, so here is my version. You can divide by 100 if you need to
/usr/local/bin/hid-query /dev/hidraw1 0x01 0x80 0x33 0x01 0x00 0x00 0x00 0x00|grep -A1 ^Response|tail -1 > /tmp/temper
sed -i -e ‘s/^[^0-9a-f]*[0-9a-f][0-9a-f] [0-9a-f][0-9a-f] \([0-9a-f][0-9a-f]\) \([0-9a-f][0-9a-f]\) .*$/0x\1\2/’ -e ‘s/[a-z]/\U&/g’ /tmp/temper
hex=$(cat /tmp/temper)
printf ‘%d\n’ $hex > /tmp/temper
echo $(date +%H:%M)”,””$(cat /tmp/temper)” >> path/to/file
I was able to modify this to work in debian/ubuntu
#!/bin/bash
OUTLINE=$(/usr/local/bin/hid-query /dev/hidraw1 0x01 0x80 0x33 0x01 0x00 0x00 0x00 0x00|grep -A1 ^Response|tail -1)
OUTNUM=$(echo $OUTLINE|sed -e ‘s/^[^0-9a-f]*[0-9a-f][0-9a-f] [0-9a-f][0-9a-f] \([0-9a-f][0-9a-f]\) \([0-9a-f][0-9a-f]\) .*$/0x\1\2/’)
echo $OUTNUM
HEX4=${OUTNUM:2:4}
DVAL=$(( 16#$HEX4 ))
CTEMP=$(bc <<< "scale=2; $DVAL/100")
FTEMP=$(echo "scale=2;((9/5) * $CTEMP) + 32" |bc)
echo $CTEMP
echo $FTEMP
Sample output looks like this, first line is celcius, second line is ferenhight
If the ambient temperature is subzero this gives a wrong result. To manage also negative hex-numbers you need to add
if [[ $DVAL -gt 32767 ]]; then
DVAL=$(($DVAL-65536))
fi
I have corrected badly copy-paste ‘ and ‘ characters. This shall work.
#!/bin/bash
OUTLINE=$(/usr/local/bin/hid-query /dev/hidraw4 0x01 0x80 0x33 0x01 0x00 0x00 0x00 0x00|grep -A1 ^Response|tail -1)
OUTNUM=$(echo $OUTLINE|sed -e ‘s/^[^0-9a-f]*[0-9a-f][0-9a-f] [0-9a-f][0-9a-f] \([0-9a-f][0-9a-f]\) \([0-9a-f][0-9a-f]\) .*$/0x\1\2/’)
HEX4=${OUTNUM:2:4}
DVAL=$(( 16#$HEX4 ))
CTEMP=$(bc <<< "scale=2; $DVAL/100")
FTEMP=$(echo "scale=2;((9/5) * $CTEMP) + 32" |bc)
echo $CTEMP
#echo $FTEMP
Thanks. Now have this device working on CentOS 7.8, Fedora 31 and ClearOS 7.7 (a derivative of CentOS)
Had the usual problem with back ticks and single quotes 🙂
Hey Tony, would you mind mailing me the correct version? I will then upload this to Github, see contact page 😉
Hi Maikel
First glitch – rebooted the system and the device changed from /dev/hidraw1 to /dev/hidraw3. Now using “/usr/local/bin/hid-query -e” to check which is active to use…
My script version can be downloaded from https://www.sraellis.tk/TEMPered/TEMPered
Wonder if this is a user code page problem?
see also
https://www.clearos.com/clearfoundation/social/community/what-is-your-office-or-computer-room-temperature#reply-295911
https://www.sraellis.tk/frame.php?number=26&monitor=room_temp
I can confirmd that since 3 days (and thus a reboot) the device name changed. Changing /dev/hidraw1 to /deb/hidraw2 did the trick.
Just to show the device detection used here, pretty simplistic and could be better written – but this does the job. Is now part of my script…
device=`/usr/local/bin/hid-query -e | grep “413d:2107 interface 1” | awk ‘{print $1}’`
Tony
You can avoid hid-query and stay in bash:
`
#!/bin/bash
exec 5\ /dev/hidraw1
echo -e ‘\x00\x01\x80\x33\x01\x00\x00\x00\x00\c’ >&5
OUT=$(dd count=1 bs=8 /dev/null | xxd -p)
HEX4=${OUT:4:4}
DVAL=$((16#$HEX4))
CTEMP=$(bc <<< "scale=2; $DVAL/100")
echo $CTEMP
`
You can avoid hid-query and stay in bash. See https://gist.github.com/artms/5356eafcd1244c6fabc0f735e5de7096
Nice!
How can i alter the values above to register the humidy from the temper-hum?
How did you get the hex bytes to use to query the device?
The reason I ask is that I need humidity also, and the device is advertised to supply both.
Hi Thanks for the bash code, super helpful. Like others my hidraw reference changed between a Pi and other hardware, so did a check with dmesg to find the device name:
#!/bin/bash
#
# Get the temperature from a USB Temper Thermometer
#
hid=$(dmesg | grep -E -m 1 ‘Device.*413d:2107’ | awk ‘{ p=index($4,”,”); print “/dev/” substr($4,p+1,7) }’)
if [ $hid = “” ]; then
echo “No TEMPer device found”
else
echo “TEMPer device found on: $hid”
exec 5 $hid
echo -e ‘\x00\x01\x80\x33\x01\x00\x00\x00\x00\c’ >&5
OUT=$(dd count=1 bs=8 /dev/null | xxd -p)
HEX4=${OUT:4:4}
DVAL=$((16#$HEX4))
CTEMP=$(bc <<< "scale=2; $DVAL/100")
echo "$CTEMP 'C"
fi
I use
sudo ./hid-query /dev/hidraw1 0x01 0x80 0x33 0x01 0x00 0x00 0x00 0x0
Device /dev/hidraw1 : 413d:2107 interface 1 : (null) (null)
result :
Writing data (9 bytes):
00 01 80 33 01 00 00 00 00
No data was read from the device (timeout).
how can I do ? QQ