Rules with String input

  • Platform information:
    • Hardware: Rpi3
    • OS: Raspbian / Linux 4.19.66-v7+
    • Java Runtime Environment: which java platform is used and what version
    • openHAB version: 2.5.6-2
  • Issue of the topic:

I try to make rules. But don’t get out because it is a string. Can anyone help me on my way? Thanks.

  • Items
String HumBadkamerBG "Vochtigheid WC-Badkamer BG [%s %%]" <humidity> {channel="mqtt:topic:broker:BadkamerBG:Humidity"}
  • Sitemap
Text item=HumBadkamerBG
  • Rules
rule "Badkamer BG Humidity FAN"
	Item HumBadkamerBG changed
	if(HumBadkamerBG.state > 58) {
	logInfo("Badkamer-BG Fan 100%")
	else if(HumBadkamerBG.state > 56) { 
	logInfo("Badkamer-BG Fan 50%")
	else if(HumBadkamerBG.state <= 40) { 
	logInfo("Badkamer-BG Fan OFF")

Easiest to change your Item into a Number type. You’d be able to make charts with that as well.

And I think you also miss a command if the state is between 41 and 56. What happens if the humidity is first 60% and drops to 41%. The fan stays at 100%

My suggestion, change the item to Number (as @rossko57 have said) and use a switch-case statement with also a command for the 41-56 range.

You mean this?

Number HumBadkamerBG "Vochtigheid WC-Badkamer BG [%s %%]" <humidity> {channel="mqtt:topic:broker:BadkamerBG:Humidity"}

That does not work…

2020-07-04 17:26:18.970 [ERROR] [pse.smarthome.core.items.GenericItem] - Tried to set invalid state 59.2 (StringType) on item HumBadkamerBG of type NumberItem, ignoring it

I then put “var” in the rules, but I don’t know enough about that.

Right. To test I set the first at 40%. That was 54%. Because the rule does nothing, I wanted to fix that first.

What is the exact string that is passed into your item from the thing channel="mqtt:topic:broker:BadkamerBG:Humidity"?

Actually, also ensure that your thing’s channel type is actually a number too!

Well, you do have to use a number type MQTT channel with a Number type Item.

Thanks! Stupid of me, not thought of at all!

          Type number : Temperature [stateTopic="tele/BadkamerBG/SENSOR"]
        //Type string : Temperature [stateTopic="tele/BadkamerBG/SENSOR", transformationPattern="JSONPATH:$.BME280.Temperature"]

I will continue to puzzle …

Where do I look for this error?

2020-07-04 19:06:49.208 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Badkamer BG Humidity FAN': An error occurred during the script execution: index=1, size=1

Hopefully you kept the transformationPattern for your new number channel?

:+1: Thanks