Pi temperature

If you want to read the temperature of a Pi and get this as a number in OpenHAB, you can use this setup.

It creates a thing and a String item to get the temperature. A rule is used to convert the String to a Number.

  • File: things/Pi.things
Thing exec:command:PiTemperature [command="/bin/cat /sys/class/thermal/thermal_zone0/temp", autorun=false]
  • File: items/Pi.items
String PiTemperature_String "Pi Temperature [%.4s]" { channel="exec:command:PiTemperature:output" }
Number PiTemperature "Pi Temperature [%.2f C]"  (G_MysqlPersistent)
  • File: rules/Pi.rules
rule "Pi Temperature String to Number" 
when
   Item PiTemperature_String changed 
then
val Integer = Float::parseFloat(PiTemperature_String.state.toString)/1000
   postUpdate(PiTemperature,Integer)
end