Sitemap: visibility=[item operator ITEM] (instead of VALUE)

Hi folks,

openHAB-noob here.

In my sitemap, I’d like to change visibility of an item depending on a constant temperature threshold defined in my rules-file. In order to access the threshold within the sitemap, I store the threshold in an item like this:

//
// file my.items
//
Number iICY_ROADS_TEMP "enable constant in sitemap [%.1f]" {}

//
// file my.rules
//
import org.openhab.core.library.types.*

var Number ICY_ROADS_TEMP = 4.0

rule "setConstants"
when
 Time cron "* * * * * ?"
then
 iICY_ROADS_TEMP.postUpdate(ICY_ROADS_TEMP)
end

The threshold is available in the sitemap – as expected, the following item shows a value of 4.0:

//
// my.sitemap file
//

sitemap my
{
  Frame
  {
    Text item=iICY_ROADS_TEMP // shows 4.0
  }
}

What does NOT work is to toggle visibility using the threshold:

//
// my.sitemap file
//

sitemap my
{
  Frame
  {
    Text item=OutsideTemp visibility=[OutsideTemp<=iICY_ROADS_TEMP]
  }
}

The OutsideTemp item does not show up, regardless of the threshold used. What am I doing wrong?

  • In the visibility condition, replacing iICY_ROADS_TEMP with (iICY_ROADS_TEMP.state as DecimalType).floatValue does not work, too …
  • The openhab.log does not show any messages.

Thanks in advance!

Cheers
ugh_bough

Me again.

For anyone who is interested, I solved the problem by introducing an additional Switch item, which is set ON in a rule that reacts to temperature changes like this

//
// my.items
//
Switch WarnIcyRoads {}

//
// my.rules
//
import org.openhab.core.library.types.*

var Number ICY_ROADS_TEMP = 4.0

rule "WarnIcyRoads"
when
 Time cron "0 */5 * * * ?"
then
 if ((OutsideTemp.state as DecimalType).floatValue <= ICY_ROADS_TEMP) {
  sendCommand(WarnIcyRoads, ON)
 } else {
  sendCommand(WarnIcyRoads, OFF)
 }
end

In the sitemap I can now compare the Switch item to the value ON like this

//
// my.sitemap
//
sitemap my
{
  Frame
  {
    Text item=OutsideTemp visibility=[WarnIcyRoads==ON]
  }
}

Cheerio.

Hey!
That’s interesting. Great you found a solution but a better one should be available.
I do not have a comparison with an item in my sitemaps. These are working for me:

visibility=[SZ_Heizung_Battery < 2.2]
visibility=[SZ_Heizung_Fault != NO_FAULT]
visibility=[SZ_Heizung == ON]

As you can see, at least the direct comparison with 4.0 should work…

Btw. Thanks for taking the time to thoroughly describe your problem AND even a possible solution! :wink:

Ooops, thank you for pointing this out. Comparing with 4.0 does work!
(Edited the initial post accordingly.)

However, this is not an option for me, since I’d rather have exactly one definition of any constant instead of multiple definitions or even using the same number in many different places.

Comparison with another item would be beneficial indeed. Maybe @Kai can give insight on if or how this is possible.

Additionally you said there is no error in openhab.log when testing with an item name?

Correct – I tried by comparing two number items by name like this:

// my.items
Number Temp "Temperatur [%.1f °C]" {
 weather = "
  locationId = home,
  type = temperature,
  property = current
 "
}

Number TempFeel "gefühlte Temperatur [%.1f °C]" {
 weather = "
  locationId = home,
  type = temperature,
  property = feel
 "
}

// my.sitemap
sitemap my
{
  Frame
  {
    Text item=TempFeel visibility=[TempFeel<=Temp] // should be visible, but is not
  }
}

If necessary, I can also try with logging set to the most verbose level – unfortunately, however, I do not know how to set the log level…

http://docs.openhab.org/administration/logging.html#config-file

Thanks for the link. I forgot to mention that I’m running OH 1.8.3 on Raspbian 8. Setup debug logging via DEBUG=yes in /etc/default/openhab.

Still, no messages regarding the unsuccessful comparison in the sitemap :frowning:

Does it work if you use TempFeel<=Temp.state?

Probably not but I am finding it odd that you can use the state of a Switch but not of a Number Item.

Unfortunately, no :frowning: