Sitemap visibility rules with "AND"

I’ve made magic using visibility in my sitemap! But now I want to go a step further and make visible some item only when 2 items state are true.

   Switch item=KodiPlaylist visibility=[SceneRoom==6 && KodiMedia=="music"] mappings=["add"="ADD", "clear"="CLEAR", "show"=SHOW]

Unfortunately this example does not work and I can’t find anyway to do this. I know that I could separate visibility rule by comma, but it’s performing an “OR” statement and not an “AND”. Also, I’ve search there:
But I can’t find or understand a working example. Is this even possible!?

According to the description on the Sitemap wiki page there is no way to do this in the Sitemap itself. It does an OR and there is no support for AND.

However, you can do this with a rule and a third item.

New Item:

Switch KodiPlayListVisibility


rule "Set KodiPlayListVisibility Flag"
    Item SceneRoom updated or
    Item KodiMedia updated
    if(SceneRoom.state == 6 && KodiMedia.state == "music") KodiPlayListVisibility.sendCommand(ON)
    else KodiPlayListVisibility.sendCommand(OFF)


Switch item=KodiPlaylist visibility=[KodiPlayListVisibility=="ON"]

Thanks for the fast reply! This is working great! I tried a rule before but without success but this one work!

Hi everyone,

I’m trying to use this rule for my garage doors.

The motor has build-in reed sensors. When one sensor is OPEN the garage door is fully open, when the other is OPEN the door is fully closed.

When both sensors are CLOSED the doors are ajar.

I’m trying to make it so I only have one visible switch item depending on the door state. It is working fine when fully open or closed but not when I need to combine the state of both sensors.

My item:

Contact Garage_Port_1_State_Status_test2 “Garage | Port 1 | Status - test2” (Garage)

My sitemap:

Switch item=Garage_Port_1_State_Status_test2 icon=“garagedoor-ajar” mappings=[CLOSED=“På klem”] visibility=[Garage_Port_1_State_Status_test2==“CLOSED”]

My rule:

import org.openhab.core.library.types.*
import org.openhab.core.persistence.*
import org.openhab.model.script.actions.*

rule "Set GaragedoorAjar Flag"
Item Garage_Port_1_State_Closed updated or
Item Garage_Port_1_State_Open updated
if(Garage_Port_1_State_Closed.state == “CLOSED” && Garage_Port_1_State_Open.state == “CLOSED”) Garage_Port_1_State_Status_test2.sendCommand(CLOSED)
else Garage_Port_1_State_Status_test2.sendCommand(OPEN)

I have tried sendCommand(ON) and (OFF) without any luck, also tried ‘Item Garage_Port_1_State_Closed CHANGED’

I think I’m doing something wroing in the rule department but can not figure it out.

Thanks and BR Søren

Figured it out, the “CLOSED” needed to be without “” ie. CLOSED.


1 Like

thanks, that helped!