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 …
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]
}
}
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:
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.
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…