Skip to content
This repository has been archived by the owner on May 17, 2021. It is now read-only.

Convert Fahrenheit and Celsius

bigbasec edited this page Mar 18, 2016 · 2 revisions

The example can be used to convert a Fahrenheit temperature value to Celsius:

import org.openhab.core.library.types.*
import org.openhab.core.persistence.*
import org.openhab.model.script.actions.*

rule "Convert_Temp_EG"
when
	Item ZwaveTemperatureEGF changed 
then
    var tempFahrenheit = (ZwaveTemperatureEGF.state as DecimalType).doubleValue
	var tempCelsius = (tempFahrenheit -  32)  *  5/9
	postUpdate(ZwaveTemperatureEG, tempCelsius)
end

This example can be used to convert Celsius to Fahrenheit, mostly useful for Fibraro motion sensors :

import org.openhab.core.library.types.*
import org.openhab.core.persistence.*
import org.openhab.model.script.actions.*
rule "Convert ZwaveTempC to F"
	when
		Item ZwaveTempC changed
	then
		var Number temp
		if (ZwaveTempC.state instanceof DecimalType) temp = ZwaveTempC.state as DecimalType
		var Number temp2 = (temp * 1.8) + 32
		ZwaveTempF.postUpdate(temp2)
	end

Installation


User Interfaces


Community

(link to openHAB forum)

Development



Misc


Samples

A good source of inspiration and tips from users gathered over the years. Be aware that things may have changed since they were written and some examples might not work correctly.

Please update the wiki if you do come across any out of date information.

Use case examples

Collections of Rules on a single page

Single Rules

Scripts


Release Notes

Clone this wiki locally