How to read a value from a NUMBER and actuate a SWITCH based off that NUMBER

I am trying to turn a relay on/off based off of a temperature reading. Does anyone have an example of this?

I have tried:

  • creating a variable from the item as DecimalType
  • triggering the rule when an update is recieved
  • then running an if/else statement:

if(JakeOfficeTemp > 70){
sendCommand(MQTT3, ON)
sendCommand(MQTT3, OFF)

Hi Jake!

If JakeOfficeTemp is the name of your item, you need to change the syntax of your rule to:

if (JakeOfficeTemp.state > 70) {


Let us know if that solves the problem :wink:

Best regards,


try it like this:

if((JakeOfficeTemp.state as DecimalType) > 70)

1 Like

Thanks for the help guys! that was what i needed. for reference in the future, here is the functional code to turn on a blue LED when the temp is under 70 degrees, and turn on a red LED when the temperature is over 70 degrees:

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

rule "LED Temp Display"
        Item JAKETEMP received update
        if(JAKETEMP.state as DecimalType > 70){
        sendCommand(BlueLED, OFF);
        sendCommand(RedLED, ON)    
            sendCommand(BlueLED, ON)
            sendCommand(RedLED, OFF)