0

I am trying to compare the value on an MQTT Topic. I have successfully be able to capture the value and output the value to the console via the logInfo() call.

What I am trying to do is compare what is on the MQTT Topic to a value and then execute additional openhab commands based on the value on the topic.

I have been able to get the value on the MQTT topic and convert it to a string using the .toString operation.

The result of my code is that I am getting conversion errors on my console when the comparison is executed.

enter image description here

You can see that the value is captured and output to the console "1023"

My code is

import org.eclipse.xtext.xbase.lib.*
import org.openhab.core.library.types.*
import org.openhab.core.persistence.*
import org.openhab.model.script.actions.*
import java.math.BigDecimal.*
import java.lang.Integer
import java.lang.Double
import java.lang.String
import java.lang.Number

var String feedingsensor_reading

rule "start processing feeding sensor"
when 
    Item feedingsensor changed 
then
     logInfo("Step", "***********") 
     logInfo("Step", "** Start **") 
     logInfo("Stap", "***********") 
     logInfo("Step", "** Step 1 **") 

    feedingsensor_reading = feedingsensor.state.toString

    logInfo("Step", feedingsensor_reading) 

    if (feedingsensor_reading == "0"){

       logInfo("DATA", "******* Do Nothing *****") 

    }else
    {
        ... other code to be executed
Ethan Richardson
  • 461
  • 2
  • 10
  • 28

1 Answers1

0

I had the item definition defined as a String and not Number

the correct definition is

Number feedingsensor {mqtt="<[home:{topic}:state:default]"}
Ethan Richardson
  • 461
  • 2
  • 10
  • 28