Conditional action rounding issue

Trying to refine my bathroom humidity driven fan rules.
Created a new rule, were one of the IF arguments should check the current speed on the fan.
As a test, I set the fanspeed to 220 (integer) and in the rule I compare it to 220.
Somehow RM places an extra decimal after the set value, and is not seeing the device interger as the same value as the value it should check for.

If I use a relative value, ( < or > ) RM just crashes, and all the actions of that rule are gone. Nothing else to do but delete the whole rule, and start over.

Is this a rulemachine defect, or am I doing something wrong?

1 Like

It certainly should see 220.0 as equal to 220 regardless of the presence of the decimal place!

Unless one is a string....

1 Like

What is 'ITHO FAN FanSpeed'? A variable? If so, of what type? A device attribute?

1 Like

It should be a integer, but will check in the driver.

Ok, handeling it now as a string, and indeed now it works:

It is strange that Rulemachine just crashed, and nog give a warning of sorts.

So, is the attribute a string? I want to investigate the issue with RM. Please provide details...

If the attribute is of type String, RM doesn't offer > or < comparison operators. So how did you get the circumstances that caused the 'crash'?

@bravenel, I’ll send you a PM as soon as I’m behind my desktop again.

PM sent

This problem arose because a custom driver was returning a string value for an integer attribute. It became resolved once the attribute declaration and value were made to conform with each other. RM would crash when attempting to compare a string as if it were an integer. This won't happen in the next release; instead, it will detect and report the driver error, like this:

The rule would also log an error to the logs reflecting the same mismatch.

2 Likes

Still tinkering around with this one.
I want to convert the string to a integer to be able to evaluate it better.
So far, no luck.

What I did:

void poll()
{
    String DeviceInfoURI = "http://${ipAddress}/api.html?username=${username}&password=${password}&get=currentspeed" 
    httpGet([uri:DeviceInfoURI, contentType: "application/json"])

	{ resp->
			def contentType = resp.headers['content-type']
        if (enableDebug) { log.debug "Found value: ${resp.data}" }
        if (resp.status == 200) {
     def numerical = "${resp.data}"
            if (enableDebug) { log.debug "Numerical value: ${numerical}" }
            def FanSpeed = numerical.toInteger()
            if (enableDebug) { log.debug "Found value: ${FanSpeed}" }
            sendEvent([name: "FanSpeed", value: "${FanSpeed}", unit: "RPM"])
        }
   } 
}

The .toInteger() should convert the string to an integer, but when I nest request the type of the attribute, it still states it is a sring.

What am I doing wrong here?

At the top of the driver how is the attribute defined?

The "${FanSpeed}" is equivalent to FanSpeed.toString(), but really doesn't matter as attributes IIRC are stored as strings. The attribute dataType allows RM and other apps to bring back the values in the correct form.

attribute "FanSpeed", "integer"

Should be

attribute "FanSpeed", "number"
1 Like

That's it!
Cheers :+1:

2 Likes