Temperature indicator

I have a sony vaio f11 laptop. It’s pretty quick for a laptop, but it also runs pretty hot. (Sony has a bios update that supposedly cools it down a bit – by some reports at the expense of performance – but it only installs under windows, which I’ve no longer got.) Two or three times, during the dog days of summer, it has shut itself down due to heat.

Under /sys/devices/virtual/thermal/thermal_zone*, you can get some information about this. In particular, /sys/devices/virtual/thermal/thermal_zone1/trip_point_1_temp appears to be where the bios decides to work harder to cool down, while trip_point_0_temp is where it shuts down. The former is 94 (degrees Celsius, presumably) while the latter is 98. Unfortunately these are read-only and can’t be changed.

So I decided I should keep closer watch over the actual temperatures (to what end? dunno). My two main window managers are wmii and Unity – I use the two about equally. One great thing about wmii is that the status bar is filled in with a script, so adding the temperatures was trivial. My ‘Action status’ line simply became

        while true
        do
                if [ $((count % 2)) -eq 0 ]; then
                        t0=$(cat /sys/devices/virtual/thermal/thermal_zone0/temp)
                        t1=$(cat /sys/devices/virtual/thermal/thermal_zone1/temp)
                        t0=$((t0/1000))
                        t1=$((t1/1000))
                fi
                status $t0 $t1 | wmiir write /rbar/status
                count=$((count+1))
                sleep 1
        done

where the function ‘status’ adds some other info like uptime and battery state.

For Unity, I of course wanted a nicely integrated application indicator. So I spent a few minutes on the following python program, which I’m now using. You can find it packaged at ppa:serge-hallyn/indicators.

#!/usr/bin/python

#
# This program creates an indicator showing the current temp for each
# cpu on a sony vaio F11.
#
# Copyright 2009-2011 Canonical Ltd.
#
# Authors: Neil Jagdish Patel 
#          Jono Bacon 
#          Serge Hallyn 
# Used
# http://bradmont.net/wp-content/uploads/2011/08/maildir-indicator.py_.txt
# as an example.
#
# This program is free software: you can redistribute it and/or modify it 
# under the terms of either or both of the following licenses:
#
# 1) the GNU Lesser General Public License version 3, as published by the 
# Free Software Foundation; and/or
# 2) the GNU Lesser General Public License version 2.1, as published by 
# the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful, but 
# WITHOUT ANY WARRANTY; without even the implied warranties of 
# MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR 
# PURPOSE.  See the applicable version of the GNU Lesser General Public 
# License for more details.
#
# You should have received a copy of both the GNU Lesser General Public 
# License version 3 and version 2.1 along with this program.  If not, see 
# 
#

import gobject
import gtk
import appindicator
import os
import commands

CHECK_FREQUENCY = 2 # seconds
BAT_DIR="/sys/devices/virtual/thermal/"
BAT_FILE="temp"

def quit(widget, data=None):
  gtk.main_quit()

def read_file(i, dir):
  filename = BAT_DIR + dir + '/' + BAT_FILE
  f=open(filename, 'r')
  val=f.read()
  f.close()
  v = int(val)
  return "CPU%d: %dC" % (i, v/1000)

def update_temps(ind):
  tempstr = ''
  i = 0
  for d in os.listdir(BAT_DIR):
    if d[0:12] == "thermal_zone":
      if i > 0:
        tempstr += '|'
      tempstr += read_file(i, d)
      i += 1
  ind.set_label(tempstr)
  return True

if __name__ == "__main__":
  ind = appindicator.Indicator ("CPUTemp",
                              "ubuntu-logo",
                              appindicator.CATEGORY_SYSTEM_SERVICES)
  ind.set_status (appindicator.STATUS_ACTIVE)
  update_temps(ind)

  ind.set_icon("ubuntu-logo")

  menu = gtk.Menu()
  image = gtk.ImageMenuItem(gtk.STOCK_QUIT)
  image.connect("activate", quit)
  image.show()
  menu.append(image)

  ind.set_menu(menu)

  gtk.timeout_add(CHECK_FREQUENCY * 1000, update_temps, ind)

  gtk.main()

Now, when I’m watching a movie on Amazon Prime, I can watch the temperature go to about 80. If compiling while running a VM, I can watch it jump up to perhaps 95 and (before a bead of sweat can start down my forehead) back down into the 80s.

This entry was posted in Uncategorized and tagged , . Bookmark the permalink.

8 Responses to Temperature indicator

  1. jeff says:

    Hi,
    I am looking to buy a new sony z series laptop then putting Ubuntu on it. I would
    like your opinion on using linux with sony laptops and if you recommend me using sony
    or are other brands (lenovo) better suited for this. Also do you know how hard it would be
    to swap out the ssd hard drive that comes with the sony? Thanks in advance for your time.

    Jeff

  2. Thanks for writing this application. It also seems to work in Natty just fine. Perhaps you can package it for natty too.

  3. jeff says:

    this is their “official” response to my question to sony that I wanted to buy the Z laptop and have
    them put Ubuntu on it.
    Thank you for contacting Sony Support.

    “I understand that you’re interested in purchasing a VAIO Z series with Linux operating system. Sony?s computers are designed to work with Windows. As such, VAIO engineering has not released – and is not in the process of developing Linux drivers for the hardware components of our VAIO systems.

    Thank you for understanding.”

    If you would like to be the first to know about our latest products and receive exclusive offers, please sign up for our newsletter: http://www.sonystyle.com/webapp/wcs/stores/servlet/SYNewsletterOptInView?storeId=10151&catalogId=10551&langId=-1&XID=M:cs_email

    The Sony Email Response Team

Leave a comment