Setting an items icon dynamically

532 views
Skip to first unread message

Jonathan Giles

unread,
Oct 12, 2014, 8:23:05 PM10/12/14
to ope...@googlegroups.com
Hi all,

I would like to be able to dynamically alter the icon for some items in my sitemap. My specific case is that I have three items representing the state of my water tank. What I would really like to do is use the cistern images included with openhab (which include cistern-100.png through cistern-0.png) to provide a visual representation in the normal icon area of the sitemap (in the same way that dimmer and roller blind support this).

I could easily write a rule to determine which image to use (by rounding the current percentage full down to the nearest 10 percent), but that doesn't help with modifying the image in the sitemap itself. Is there a way to do this, or is it just not possible? I could create a Dimmer item to represent the image, but I don't think there is any way of saying to the other items to use the Dimmer items image as their image.

Thanks!
-- Jonathan

Ben Jones

unread,
Oct 12, 2014, 8:39:31 PM10/12/14
to ope...@googlegroups.com
What is the type of your item? Assuming it is a number, what is the range of values it can be? From what you have said about percentages it sounds like 0-100?

If so you should just be able to specify the base icon name - 'cistern' - and openHAB will pick the closest icon, rounding down I think.

So if you have 3 icons, cistern-0, cistern-50 and cistern-100, you would see the -0 icon for any value from 0-49, the -50 icon for values 50-99, and -100 for 100. 

You might need to test that as I am not certain which way the bias is. 


Jonathan Giles

unread,
Oct 12, 2014, 8:45:48 PM10/12/14
to ope...@googlegroups.com
I read at [1] that this doesn't apply to Numbers, just Dimmer and RollerShutter. My testing seems to back this up.

The other (probably bigger) issue is that I have three items that I want to have the same image. One is percent-based, but the other two are just numbers. Ideally I would use the percent-based item (or a Dimmer / RollerShutter derived from it if needs be) as the image for all three items. I have a feeling it isn't possible, but it would be cool if it was.

[1] https://groups.google.com/d/msg/openhab/0A7ii5MuvXk/3n4R68fqQa8J

Thanks,
-- Jonathan

--
You received this message because you are subscribed to a topic in the Google Groups "openhab" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/openhab/fCGliEj2cLU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to openhab+u...@googlegroups.com.
To post to this group, send email to ope...@googlegroups.com.
Visit this group at http://groups.google.com/group/openhab.
For more options, visit https://groups.google.com/d/optout.

Ben Jones

unread,
Oct 12, 2014, 8:56:37 PM10/12/14
to ope...@googlegroups.com, Jona...@jonathangiles.net
Apologies - I thought this range matching worked for numbers as well. Switching that percentage item to a Dimmer item will resolve it as you noted.

If the number items have a distinct (known) set of values you can just copy the cistern icon a number of times, and rename to 'cistern-xx' for each value. openHAB should pick up the correct icon that way. 

Can you post your item definitions here for us to have a look?

Jonathan Giles

unread,
Oct 12, 2014, 9:01:05 PM10/12/14
to Ben Jones, ope...@googlegroups.com
Here's the relevant section of my items file. The three items I am
displaying in my sitemap are the second, third, and fourth line. Ideally
I would base the cistern image for all three off of the fourth line (the
percentage full).

Number Water_Tank_Ultrasonic_cm "Ultrasonic reading [%.2f cm]" <cistern> (Water_Tank) { http="<[http://192.168.1.101:8081/homePi/waterTank/ultrasonic/reading/5:3600000:REGEX((.*?))]" }
Number Water_Tank_Water_Height "Water height [%.2f cm]" <cistern> (Water_Tank)
Number Water_Tank_Water_In_Tank "Water in tank [%.0f Litres]" <cistern> (Water_Tank)
Number Water_Tank_Percentage_Full "Percentage Full [%.0f Percent]" <cistern> (Water_Tank)
Switch Water_Tank_Fill "Water Tank Filling" (Water_Tank) { openSprinkler="1" }

-- Jonathan

Ben Jones

unread,
Oct 12, 2014, 9:04:05 PM10/12/14
to ope...@googlegroups.com, ben.j...@gmail.com, Jona...@jonathangiles.net
Don't think it is possible to link two items together on the one sitemap widget - as cool as that would be. I.e. the label from one and the icon from another. Maybe in v2.0....

Jonathan Giles

unread,
Oct 12, 2014, 9:06:35 PM10/12/14
to Ben Jones, ope...@googlegroups.com
Yeah - I assumed as much. Nonetheless, it would definitely be a nice
thing to consider for a future release.

-- Jonathan
Reply all
Reply to author
Forward
0 new messages