Temperature & Humidity Log

First posted on the 13th March, 2011 – IT
Last modified on the 17th March, 2011, at 1:19 am

The aim of this project started out with then need to know current temperature and humidity in my house and expanded into a little bit more. It started out as just one perl script to locally log the temperature and humidity but soon expanded to a log aggregator and a dynamic webpage that can be accessed from anywhere. Finally it was integrated as a page on a WordPress blog being used as a CMS for my homepage.


The setup is based on five wireless temperature and humidity sensors, four S-300-TH units which are used indoors in the kitchen, living room, bedroom and bathroom and one special weather proof ASH-2200 unit, which is placed outdoors. The five sensors all connect to a USB-WDE1 receiver unit connected to a computer by USB.

indoor sensor ASH-2200
outdoor sensor USB-WDE1

Although off-the-shelf software is available (LogView) functionality was limited to only logging every minute. To enable extra functionality, and as a bit of a geek challenge, a custom software solution was created. This consist of the following parts:

  • A perl script (tempget.pl) run in the background that constantly gets reading from the receiver via a serial interface and writes out a log.
  • A shell script (templog.csh) run by cron every 15 mins that reads the log and writes out an hourly, daily and monthly logs.
  • A php script (tempweb.php) that reads the logs and dynamically creates a webpage with plots created using PHPlot.
  • None of these scripts is particularly pretty, nor efficient, but they work. As reading a serial interface and reporting results via a web interface was something I thought I would never be able to achieve with my basic programming knowledge I thought I would share this to encourage others to try such things. Although setup for Mac OS X 10.6 scripts should also work under Linux with appropriate modification. Note that PHP is not enabled by default in Mac OS X 10.6, PHP. To do this make a backup of the original http.conf file:
    sudo cp /etc/apache2/httpd.conf /etc/apache2/httpd.conf.original

    Then enabled PHP by editing the http.conf file:
    sudo nano /etc/apache2/httpd.conf

    and un-commenting the following line in /etc/apache2/httpd.conf and restarting the web server:
    #LoadModule php5_module libexec/apache2/libphp5.so

    Revision History

    Over time a number of new features have been added:

  • created perl script
  • created shell script to create hourly, daily and monthly logs
  • added php script to real last log entry and display current values
  • added inside value as average of all four indoor sensors
  • added delta values to outside
  • added separate delta value between living room and bedroom
  • added room colour code to match plot
  • calculates daily maximum and minimum and reports it to daily log
  • added plot of last two hours by the minute
  • made las two hour plot only show one reading per minute to ignore two logs per minute
  • added date and time of last log read and current time
  • added reload button
  • added favicon and iphone icon
  • added plot of last two days by the hour
  • added plot of average temperature for last 28 day
  • added links to both raw logs and contracted logs used to plot
  • added automatic reload every minute
  • added javascript to remember current scroll location upon reload (3rd party code)
  • added css to harmonise look
  • added countdown till next reload using javascript (3rd party code)
  • added buttons to go directly to minute, hour and day plots
  • added links to plots to jump to next plot and then loop back
  • added plot of last month showing only inside and outside with max and min
  • added daily running max and min temperature to current values
  • made running max and min ignore sensor dropouts
  • made templog script ignore sensor dropouts
  • corrected averaging error that skewed averages (initiate counter as zero not 12!)
  • added plot of average temperature for last year
  • changed log location as Time Machine in Mac OS X does not backup ~/Library/Logs
  • added daily running average and plot it as day zero on day view.
  • added weekly and monthly running average and plot it as zero point on week and month view
  • tidyied up HTML of PHP output for easier debugging
  • added time of daily max and min temperature as mouse over in table
  • added plot of time of daily max and min temperature for last four weeks
  • made templog script record time of daily max and min
  • extended year plots to two year plots
  • fixed humidity axes to 0-100±20 %
  • calculate temperature axis based max and min values plotted and quantised with ±5°C.
  • corected wrong reading of bathroom humidity
  • transfered to wordpress usinf exec-php