Sitemap visibility rules with "AND"

Hi!
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.
Example:

   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: https://github.com/openhab/openhab/blob/master/bundles/model/org.openhab.model.sitemap/src/org/openhab/model/Sitemap.xtext
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:

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

Sitemap:

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

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

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"
when
Item Garage_Port_1_State_Closed updated or
Item Garage_Port_1_State_Open updated
then
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)
end

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.

:slight_smile:

1 Like

thanks, that helped!