OH 3 Rule migration from OH 2

I there I am trying to convert or migrate the following rule into OH 3 from OH 2 for my water heater.

Please help there

rule “Thermostat”
when
Item TEMP changed or
Item Temperature_Setpoint_Mode changed
// also triggers when mode changes for immediate action
// else nothing would happen until temp changed, if it ever did
then
// first we check if the temp reading is valid
if ( TEMP.state != NULL &&
TEMP.state != UNDEF &&
TEMP.state > 0) {
// that != means “not equal” in an if(condition)
// while the && means “and”

    // temp sensor is valid, so
    // let's set up a target temperature
  var Number tempMax = 55
  if (Temperature_Setpoint_Mode.state == 2) {
       // shower mode
     tempMax = 55
  } else if (Temperature_Setpoint_Mode.state == 1) {
        // normal mode
     tempMax = Temperature_Setpoint.state
  } else if (Temperature_Setpoint_Mode.state == 3) {
        // normal mode
     tempMax = 0
}

     // if the mode is anything else, the target stays 0 i.e. off

     // now let's check against upper limit
  if (TEMP.state < (tempMax - 5)) {
        // we allow 1 degree hysteresis
        // It's colder than target
        // so turn heater on if it isn't already
     if (Geyser.state != ON) {
        Geyser.sendCommand(ON)
     }

     // else lets check if we're at the target
  } else if (TEMP.state > tempMax) {
        // reached target temp
        // (our target could be 0 if mode is off)
        // so turn heater off if it isn't already
     if (Geyser.state != OFF) {
        Geyser.sendCommand(OFF)
     }
  }  // else we do nothing here
     // temp could be within 1 degree of target
     // and the heater will continue doing what it is doing
     // That's the hysteresis

} else { // this else belongs to the valid temp reading check
Geyser.sendCommand(OFF)
// temp sensor broken, turn off heater for safety
}
end

Please use code fences.

```
code goes here
```

Next please explain what the rule is supposed to do and what it not working and post any relevant logs this rule may generate.

As best as can be gathered with the mangled formatting, there is nothing about this rule to indicate it won’t work. So more information is needed.

‘’’
rule “Thermostat”
when
Item TEMP changed or
Item Temperature_Setpoint_Mode changed
// also triggers when mode changes for immediate action
// else nothing would happen until temp changed, if it ever did
then
// first we check if the temp reading is valid
if ( TEMP.state != NULL &&
TEMP.state != UNDEF &&
TEMP.state > 0) {
// that != means “not equal” in an if(condition)
// while the && means “and”

    // temp sensor is valid, so
    // let's set up a target temperature
  var Number tempMax = 55
  if (Temperature_Setpoint_Mode.state == 2) {
       // shower mode
     tempMax = 55
  } else if (Temperature_Setpoint_Mode.state == 1) {
        // normal mode
     tempMax = Temperature_Setpoint.state
  } else if (Temperature_Setpoint_Mode.state == 3) {
        // normal mode
     tempMax = 0
}

     // if the mode is anything else, the target stays 0 i.e. off

     // now let's check against upper limit
  if (TEMP.state < (tempMax - 5)) {
        // we allow 1 degree hysteresis
        // It's colder than target
        // so turn heater on if it isn't already
     if (Geyser.state != ON) {
        Geyser.sendCommand(ON)
     }

     // else lets check if we're at the target
  } else if (TEMP.state > tempMax) {
        // reached target temp
        // (our target could be 0 if mode is off)
        // so turn heater off if it isn't already
     if (Geyser.state != OFF) {
        Geyser.sendCommand(OFF)
     }
  }  // else we do nothing here
     // temp could be within 1 degree of target
     // and the heater will continue doing what it is doing
     // That's the hysteresis

} else { // this else belongs to the valid temp reading check
Geyser.sendCommand(OFF)
// temp sensor broken, turn off heater for safety
}
end
‘’’

ule "Thermostat"
when
   Item TEMP changed or
   Item Temperature_Setpoint_Mode changed
      // also triggers when mode changes for immediate action
      // else nothing would happen until temp changed, if it ever did
then
      // first we check if the temp reading is valid
   if ( TEMP.state != NULL &&
        TEMP.state != UNDEF &&
        TEMP.state > 0) {
             // that != means "not equal" in an if(condition)
             // while the && means "and"

        // temp sensor is valid, so
        // let's set up a target temperature
      var Number tempMax = 55
      if (Temperature_Setpoint_Mode.state == 2) {
           // shower mode
         tempMax = 55
      } else if (Temperature_Setpoint_Mode.state == 1) {
            // normal mode
         tempMax = Temperature_Setpoint.state
      } else if (Temperature_Setpoint_Mode.state == 3) {
            // normal mode
         tempMax = 0
	}

         // if the mode is anything else, the target stays 0 i.e. off

         // now let's check against upper limit
      if (TEMP.state < (tempMax - 5)) {
            // we allow 1 degree hysteresis
            // It's colder than target
            // so turn heater on if it isn't already
         if (Geyser.state != ON) {
            Geyser.sendCommand(ON)
         }

         // else lets check if we're at the target
      } else if (TEMP.state > tempMax) {
            // reached target temp
            // (our target could be 0 if mode is off)
            // so turn heater off if it isn't already
         if (Geyser.state != OFF) {
            Geyser.sendCommand(OFF)
         }
      }  // else we do nothing here
         // temp could be within 1 degree of target
         // and the heater will continue doing what it is doing
         // That's the hysteresis

   } else {   // this else belongs to the valid temp reading check
      Geyser.sendCommand(OFF)
          // temp sensor broken, turn off heater for safety
   }
end

OK, the rule is easier to read now but still there is nothing about this rule that should not work in OH 3. So please explain exactly how it’s not working and provide any relevant logs.

Appologies my question is on how to import this to OH 3 would I just add it as a DSL script

It will work exactly the same as it does in OH 2. If you want to move it to the UI see the Getting Started Tutorial to get started. Rules - Introduction | openHAB