Can't make dynamic icons to work

Hi!

Newbie question here…

I have an item ( a photocell ) and I’m receiving a mqtt feed from a ESP8266, I’d like to make the light bulb icon go on when there is light and…obviously off when there’s no light.

So far I can’t make it work… here are my files:
Item
/* Light Sensor */
Number Labo_Light_Sensor “Light [MAP(photocell.map):%d]” (Labo) {mqtt="<[mosquitto:Boubounouche/Labo/LightSensor:state:default]"}

Sitemap
Frame label=“Electronics Labo”{
Text item=Labo_Temp icon=“temperature”
{Frame{
Text item=Labo_Temp
Text item=Labo_Flood
Text item=Labo_Light_Sensor
}
}
}

I’ve seen a couple of post that people put (for the icon) but when I do it nothing appear, but when I wrote the light bulb icon did appear.

The way dynamic icons work, as documented on the wiki:

the last part of the icon’s filename must match the value of the state. Since a Number Item will never have the states ON or OFF it will never show dynamic icons for that Item.

You will either need to:

  • create a copy of the light_on.png file for each and every numerical value you want the ON light icon to appear (e.g. if you want it on between 25 and 100 that is 75 copies of the icon named light_25.png, light_26.png, …) and a copy of light_off.png for all the values where it should be OFF. NOTE: if your number isn’t an integer this approach is impossible.

  • change your Labo_Light_Sensor to a Switch and use a JavaScript transform to convert the number coming in via mqtt to an ON and OFF based on the number

  • create a separate switch and a rule to update the ON/OFF state of the switch based on the value of Labo_Light_Sensor.

1 Like

Woaw thanks, I’ll go right away working on that issue with all the cues you gave me!!!

Pascal

I took a different approach with my problem, now that I understand how the dynamic icons works I’ve instead, work on the other end, the ESP8266 that is sending the message.

I’ve made a array with the two string value that I need (ON, OFF) so when the sensor give a 0 output I’m sending array0 that is OFF and when I’m sending array1 it’s sending ON string.

Works like a charm, thank you very much for your help!!!

Pascal

Sorry for warming up this old thread. But is it possible to have a dynamic icon based on a String?

String myString

Text item=myString label="myString [%s]" icon="myweather"

myweather-09d.png

Adress from icon copied from browser:
http://raspberrypi.fritz.box:8080/icon/myweather?state=09d&format=png

Isn’t displaying any icon. I don’t get any error or warning in the logs.

Another question why are the docs differ from the merged so much?


As always. OH is confusing me much.

Yes.

Do you have a default version (i.e. myweather.png)?

Are these icons in the right folder?

Have you configured your UI to use bitmap icons instead of the default svg?

A LOT has changed since October of 2013, the date of that merge you link to. The docs are for how icons work now, not how they worked 3 years four months ago.

Damn. Thanks a lot. Will report back later.

Then, the cool feature of applying icons dynamically in the sitemap was removed?

Dynamic Icons
Similar to (and the logical extension to) colors, icons can now be changed dynamically. The existing static icon can still be used (eg icon=“temperature”), but you can now add a dynamic array of icons (eg icon=“30=temperature_high, 20=temperature_norm, 10=temperature_low”).

No. You are using that feature right now with your weather-09d.png. That IS what that feature is describing and what is documented in the docs. The only difference is instead of needing to maunally define an array of value/icon pairs OH figures out which icon to used automatically using the Item’s state and the icon’s name.

Now everything I read and you said makes sense for me. And it’s working now. I forgot to have a default icon (i.e. myweather.png).
Thank you.

Maybe it would be better not to rely on a default icon? I don’t know about this design decision, but wouldn’t it be nice that it’s just working out of the box even if one forgot to add the default icon?

And the doc says the following:

You could have icons like
dice.png
dice-1.png
dice-2.png etc.

And don’t forget, you will not receive a feedback if you forget the default icon.
Better the doc would say: “You must have dice.png or you will be left confused!”

I don’t know if this was mentioned here before. The filename has to be all lowercase or it will fail. Another thing a ran into.

This is a recent change and I believe it is required by BasicUI. I think it was required in order to support icon ranges. For example, before BasicUI if you had a range of 0 to 100 for an Item’s potential states you would have to create 101 icons. Now you can create three (e.g. temp.png, temp-20.png, temp-80.png) and OH will choose the closest icon to the current state.

The current doc for Items states:

You have to provide a default file and one icon file per state with the states name append to the icons name.

There are yet to be merged changes that also mention icon names must be all lowercase.