Fire rule based on changed string value

I want to create a conditional visibility rule for an item on my sitemap. I want the “Set Temp” to be hidden when the airco is just set to “Fan” and visible when the other modes are selected.
Based on the guidance here Sitemap visibility rules with “AND” I need to accomplish this with a rule and an additional item.

I created an additional visibility switch and updated the sitemap which works fine when I turn it on manually as a test. The issue is that I can not get the rule to fire when the BMode has been changed to ‘FAN’ so that the visibility switch changes to true.

I suspect it might be because i am using mappings…
Any help is appreciated

Items

//Daikin Bureau
Switch BPower     "Power"                                                             { channel="opendaikin:ac_unit:192_168_0_238:power" }
Number BSetTemp   "Set Temp"               <temperature>                              { channel="opendaikin:ac_unit:192_168_0_238:settemp" }
Number BInTemp    "B Indoor Temp[%s °C]"   <temperature>     [ "CurrentTemperature" ] { channel="opendaikin:ac_unit:192_168_0_238:indoortemp" }
Number BOutTemp   "Outdoor Temp[%s °C]"    <temperature>                              { channel="opendaikin:ac_unit:192_168_0_238:outdoortemp" }
Number BHumidity  "Humidity"                                                          { channel="opendaikin:ac_unit:192_168_0_238:humidity" }
String BMode      "Mode"                   <heating>                                  { channel="opendaikin:ac_unit:192_168_0_238:mode" }
String BFanS      "Fan Speed"              <qualityofservice>                         { channel="opendaikin:ac_unit:192_168_0_238:fanspeed" }
String BFanD      "Fan Direction"                                                     { channel="opendaikin:ac_unit:192_168_0_238:fandir" }
Switch DaikinVisibility1

Rule

// ....

rule "Set Daikin Visibility Flag 1"
when
    Item BMode changed 
then
   if (Bmode.state.toString.contains ("FAN"))
       sendCommand(DaikinVisibility1,OFF)
else   sendCommand(DaikinVisibility1,ON)
end

Sitemap

{	  
		  Frame label="Bureau" icon="climate" 
		  {
             Switch    item= BPower label="On/Off"
             Setpoint  item= BSetTemp minValue=20 maxValue=25 step=1  visibility=[DaikinVisibility1==ON]
             Selection item= BMode mappings=["AUTO"="Auto", "DEHUMIDIFIER"="Dehumidifier", "COLD"="Cold", "HEAT"="Heat", "FAN"="Fan"] visibility=[BPower==ON]
             Selection item= BFanS label="Fan" mappings=["AUTO"="Auto", "SILENCE"="Silence", "LEVEL_1"="Level 1", "LEVEL_2"="Level 2", "LEVEL_3"="Level 3", "LEVEL_4"="Level 4", "LEVEL_5"="Level 5"] visibility=[BPower==ON]		               
	     Text item= BInTemp
             Text item= BOutTemp
             Switch item= DaikinVisibility1
		  }		  

Your approach is the right one
The rule trigger, it just doesn’t do anything
Remove the space before (“FAN”)
Add { and } to your if conditions, it’s cleaner
Add some logging and check

rule "Set Daikin Visibility Flag 1"
when
    Item BMode changed 
then
    logInfo("BMODE",BMode.state.toString
    if (Bmode.state.toString.contains("FAN")) {
        logInfo("BMODE", "Visibility OFF")
        sendCommand(DaikinVisibility1,OFF)
    } else {
        logInfo("BMODE", "Visibility ON")
        sendCommand(DaikinVisibility1,ON)
    }
end

Thanks for helping out on this
There was a ) missing at the end of the first loginfo but after correcting it as above I get the below in the logs

2018-06-01 18:34:48.567 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model ‘daikin.rules’
2018-06-01 18:34:59.115 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model ‘daikin.rules’
2018-06-01 18:35:01.074 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model ‘daikin.rules’
2018-06-01 18:35:27.809 [INFO ] [eclipse.smarthome.model.script.BMODE] - COLD
2018-06-01 18:35:27.813 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule ‘Set Daikin Visibility Flag 1’: The name ‘Bmode’ cannot be resolved to an item or type; line 6, column 9, length 5
2018-06-01 18:35:59.881 [INFO ] [eclipse.smarthome.model.script.BMODE] - FAN
2018-06-01 18:35:59.896 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule ‘Set Daikin Visibility Flag 1’: The name ‘Bmode’ cannot be resolved to an item or type; line 6, column 9, length 5

The item is BMode, in the rule you use Bmode.

1 Like

I feel sooooooo stupid that I missed that. It works now.

Thanks both @hr3 and @vzorglub

Just one thing before you mark the solution,
Use

DaikinVisibility1.sendCommand(OFF)

instead of

sendCommand(DaikinVisibility1,OFF)

The first one is the item object method and is the recommended use
The second one is the openHAB action and is reserved for generic item name rule use and the like. If you know the item, use the method.

See:https://www.openhab.org/docs/configuration/rules-dsl.html#myitem-sendcommand-new-state-versus-sendcommand-myitem-new-state

Good luck