OK, we are dealing with hex encoded values but do you know what sort of value they represent? Mainly I’m concerned about the TEMP and RAIN. Is it a floating point number or did they do something else (e.g. it is an integer but they expect you to divide by 10 or 100).
Assuming that the device is returning celsius I’m going to guess it is encoding one decimal place and they expect you to do the divide by 10.
This is because:
00f0 = 240
00ef = 239
If this is celsius than 24.0 degrees and 23.9 degrees are reasonable values.
HUM is almost certainly percent and we will never see anything except parsable numbers from it.
RAIN is probably expecting you to divide by something too unless you have received almost 1.5 m of rain since installing this sensor, which could be reasonable. In all likelihood, you will have to observe how this number changes over time corresponding with observations of rainfall to figure how this number is being reported.
NOTE: 05b0 = 1456
OK, let’s start parsing the values.
rule "Parse RFLink messages"
when
Item RFLink_Messages received update
than
// split the message into parts on the ';'
val parts = RFLink_Messages.state.toString.split(';')
// the parts of the message start from zero, the replace removes the ID= from the message
val id = parts.get(3).replace("ID=",'')
// look at the fifth part of the message to see which type of message it is and parse accordingly
switch parts.get(4) {
// process a TEMP/HUM/BAT message
case parts.get(4).startsWith("TEMP"): {
// Get the TEMP, I broke it down into steps for legibility
val tempHex = parts.get(4).replace("TEMP=", '')
val rawTemp = new java.math.BigDecimal(Integer::parseInt(tempHex, 16))
val adjustedTemp = rawTemp / 10.0
// assumes you named your Temp Item for this device 3601_Temp, you can do some additional
// code to change the 3601 to something more friendly but the point is we use the id to construct
// the name of the Item to update.
postUpdate(id+"_Temp", adjustedTemp.toString)
// Get the Humidity, all on one line for brevity
val humidity = new java.math.BigDecimal(Integer::parseInt(parts.get(5).replace("HUM=", ''), 16))
postUpdate(id+"_Hum", humidity.toString)
// Get the Battery
val bat = if(parts.get(5) == "BAT=OK") "ON" else "OFF"
postUpdate(id+"_Bat", bat)
}
// process a RAIN/BAT message
case parts.get(4).startsWith("RAIN") {
// Get the rain
val rain = java.math.BigDecimal(Integer::parseInt(parts.get(4).replace("RAIN=", ''), 16))
// do more math based on what this number represents
postUpdate(id+"_Rain", rain.toString)
// Get the battery
val bat = if(parts.get(5) == "BAT=OK") "ON" else "OFF"
postUpdate(id+"_Bat", bat)
}
default: lofWarn("RFLink", "Received an unknown message type: " + RFLink_Messages.state.toString)
}
end
I just typed in the above and there are likely errors. Dealing with numerical values like I have is prone to cause the Rules engine problems. I tried to write it in such a way as to avoid most of the potential pitfalls but I could have caused problems.
If it doesn’t work be sure to look at the logs for errors and add lots of logging to find the line it doesn’t like and what everything is equal to.
One final question, how quickly do these messages come in?
One final note to others on the forum. This is the one case where I think it is acceptable and appropriate to use the Actions for sendCommand and postUpdate instead of the Item methods. We don’t have a reference to the Items and there is no need to go through the extra work of pulling them out of a Group like you’ve seen me do all over the place.