Skip to content

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

feature overview

Installation

Setup intro

Linux and OS X

Windows

FreeBSD


Configuration

Automation*

User Interfaces

Persistence


Community

(link to openHAB forum)

Development


Bindings


Application Integration

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.

Binding configurations

Use case examples

Item definition examples

Sitemap definition examples

Collections of Rules on a single page

Single Rules

Scripts

Syntax highlighting for external editors


Release Notes

Clone this wiki locally
You can’t perform that action at this time.