Beginner Heater Script

Hello, I’m new to Openhab, but I’ve been using it for a project and now I’m lost. The basics of the project is i have a onewire temperature sensor hooked up to the pi and recognized in OH2 as well as a Wemo Outlet.

I would like to create a rule or script that will turn the outlet on if the temperature sensors temp reading lower than 75 and turns it off it the temp is over 80. I’ve done a ton of Googling trying to figure out how to do this but so far I’ve had no luck. Any help would much appreciated.

Here is a rule for the heater in the nursery.

It is probably a little more complex than you are after but I thought I would show you how it can be done.

You need a couple of virtual items for selecting the heating mode and setting the desired temp;

Number      VT_Heating_Mode_Nursery     "Nursery Heating Mode"
Number      VT_Heating_Setpoint_Nursery "Nursery Setpoint [%.1f °C]"

Then in your sitemap or other rules you can set these depending on household presence, seasons, time of day, whatever.

You will also need the nursery temp which you already have, in my config it is called FF_Nursery_Temp.

NOTE: my rule uses a +/- 0.5C hysteresis since we use celcius down here in NZ. You might want to adjust that to suit.

Then the rule is as follows;

rule "Nursery heating"
    Item VT_Heating_Mode_Nursery changed or
    Item VT_Heating_Setpoint_Nursery changed or
    Item FF_Nursery_Temp changed
    // 0="Off", 1="On", 2="Auto"
    if (VT_Heating_Mode_Nursery.state == 0) {
        // heater off
        if (FF_Nursery_Heater.state != OFF)
    } else if (VT_Heating_Mode_Nursery.state == 1) {
        // heater on
        if (FF_Nursery_Heater.state != ON)
    } else if (VT_Heating_Mode_Nursery.state == 2) {
        // get the current setpoint for the nursery
        var Number setpoint = VT_Heating_Setpoint_Nursery.state as DecimalType

        // calculate the turn on/off temperatures
        var Number turnOnTemp = setpoint - 0.5
        var Number turnOffTemp = setpoint + 0.5

        // get the current temperature in the nursery
        var Number temp = FF_Nursery_Temp.state as DecimalType
        // determine whether we need to turn on/off the heater
        if (temp <= turnOnTemp) {
            // turn on temp has been reached so switch on the heater
            if (FF_Nursery_Heater.state != ON)
        } else if (temp >= turnOffTemp) {
            // turn off temp has been reached so switch off the heater
            if (FF_Nursery_Heater.state != OFF)
1 Like

Thanks for the reply. I’m still a bit confused (programming is not one of
my skills ) , but hopefully I can figure everything out thanks to your


if you are still there what site map would you make for that rules?


Something like;

                Switch item=VT_Heating_Mode_Nursery mappings=[0="Off", 1="On", 2="Auto"]
                Setpoint item=VT_Heating_Setpoint_Nursery minValue=16 maxValue=24 step=0.5 visibility=[VT_Heating_Mode_Nursery==2]
                Text item=FF_Nursery_Heater

The last Text item is just to indicate when the heater is on/off.