[SOLVED] Custom dynamic icons

Hi,

i searched the fourm and did not find a solution. I have 2 custom icons in svg format. I rename it to
blindup.svg
blindup-on.svg
blindup-off.svg

I have a virtual item called shutterKitchenDown. If the item, a switch changed to ON the new icon with blindup-on does not show the ON-icon. I can see ee the logs, that the rule and the item is triggered and change its state to ON. What is the exact naming?

I copied these icons into \openhab\openHAB2-conf\icons\classic

I do not know what i am doing wrong.

Thank you for your help in advance.

Look correct.
Can you post the item definition, please?

Also, is your UI set to use SVG icons?

Switch shutterKitchenUp "shutterKitchenUp" <blindup>

Switch shutterKitchenDown "shutterKitchenDown" <blinddown>

Switch shutterKitchenPause "shutterKitchenPause" <blindup>

Paper Ui / Configuration / Services / UI / Basic UI / IconFormat = Vector

It is all set.

Here are the icons:

blindup blindup blindup-on

My rules are followin. The names “ON” and “OFF” is switching the color, but not the icons

rule "rule_shutterKitchenUp"
when
Item shutterKitchenUp received command
then
if(receivedCommand == ON ){        
    //rfxcom_rfy_usb0_Kueche_shutter.sendCommand(UP)
    Thread::sleep(5000)
    shutterKitchenUp.postUpdate(OFF)
}   
end

rule "rule_shutterKitchenDown"
when
Item shutterKitchenDown received command
then
if(receivedCommand == ON ){        
   // rfxcom_rfy_usb0_Kueche_shutter.sendCommand(DOWN)
    Thread::sleep(5000)
   shutterKitchenDown.postUpdate(OFF)
}   
end

I found the fault. I had icons with the same name weeks ago. I deleted them and add the new ones. I did not chnage the name, so that i do not haveto change every widget in the dashboard. But somehow the framework keep these old icons. Even a restart of the whole machine does not work. Only the renaming of the new files is the solution.

I am controlling blinds in a tri-state from an RM PRO so I have a up / stop / down for the blind. I would like to have dynamic icons showing blinds-0 for up, blinds-100 for down and blinds-50 for a stop command - I get I can make custom icons with the ON or OFF but how to manage the stop?

You cannot represent a stop command with an OH icon, only states.

If your Item has states 0-100, you could have icons with names myicon-0, myicon-1, myicon-100 for the effect you want. the -1 icon will show for any numbers 1-99. Don’t forget you must also provide a default myicon version.

of course! it doesnt really matter what these settings of the mapped states are as its is just comparing a value for a rule. ive set to 0, 50 and 100 and got it exactly how i want

Hi Rossko57!
I’d like to create custom icons representing wind direction with 36 svg files (one per 10-degree-step) called:
arrow.svg ,
arrow-0.svg … arrow-10.svg … up to arrow-360.svg.

/------/ My .item file:
Number wind_dir_deg1 “Direzione Vento [%d °]” { channel=“mqtt:topic:MY-MQTT:RTL_433:wind_dir_deg#Angle”}

/------/ My .sitemap file:
Text item=wind_dir_deg1 label=“Direzione Vento [%d °]” icon=“arrow”

It does only work with values from 0 to 100…
In fact if wind_dir_deg1 > 100 I got the default icon…

Any suggestion ??
Thanks,
Alessandro

That is correct.

What you might do is update your Number Item using an MQTT transform, so that what is passed to the Item state is degrees-divide-by-10 e.g. 0.0 to 36.0

Then that will work with your renamed icon-0 to icon-36

In the [ format ] part of your Item label you can use anther transform to multiply by ten, to get your original heading back for display.

Thanks Rossko57 for your help !

/--------/ My .item file is:
Number wind_dir_deg1 “Direzione Vento [%.3f °]” { channel=“mqtt:topic:MY-MQTT:RTL_433:wind_dir_deg0” [profile=“transform:JS”, function=“DivideByTen.js”] }

/---------/ It seems to work with this DivideByTen.js

(function(dividendo) {
var divisore = 10;

var diviso_dieci = (parseFloat(dividendo)/divisore);
// diviso_dieci = dividendo/divisore

var logger = Java.type(“org.slf4j.LoggerFactory”).getLogger(“myScript”);
logger.warn("Valore orig: " + dividendo + " -> diviso dieci: " + diviso_dieci);

// return diviso_dieci.toString();
return diviso_dieci;
//return 1
})(input)

/-------------/
In fact i have this in log:

2020-01-28 12:31:51.385 [WARN ] [myScript ] - Valore orig: 225.000000 -> diviso dieci: 22.5

/-------------/
But persistence and sitemap do not work:
Influxdb doesn’t update values in wind_dir_deg1
/----/ influxdb.persist
wind_dir_deg1 : strategy = EveryUpdate, restoreOnStartup

(previously strategy was “EveryMinute”):
/---------/ select * from wind_dir_deg1
2020-01-28T11:01:00.561Z 157.5
2020-01-28T11:02:00.564Z 157.5
2020-01-28T11:03:00.566Z 157.5
2020-01-28T11:04:00.57Z 157.5
2020-01-28T11:05:00.573Z 157.5
2020-01-28T11:06:00.576Z 157.5
2020-01-28T11:07:00.58Z 157.5
2020-01-28T11:08:00.583Z 157.5
2020-01-28T11:09:00.586Z 157.5

And my .sitemap shows these values from DB and not from MQTT/transform:

    Text item=wind_dir_deg1 label="Direzione Vento [%s °]"  icon="arrow"

Please help me !!!

What you haven’t shown is your events.log actually updating your Item to 22.5
So let’s guess it didn’t happen.

You’ve chosen to do your transform using a profile.
There is a non-obvious problem here … at present, transformation profiles only work with String type Items.
It isn’t going to work with your Number.

All is not lost, you can do as I suggested and do your transform in the MQTT topic settings (make it return a string), the binding channel can match up the transformed string to a Number Item.

So let’s guess it didn’t happen.
You’re right! :frowning:

Thanks for your help!
This is what I did!!

/--------/ My .things file:
Type number : wind_dir_deg0 [ stateTopic=“sensors/rtl_433/P119/C0/wind_dir_deg” , transformationPattern=“JS:DivideByTen.js”]

/--------/ My .items file:
Number wind_dir_deg1 "Direzione Vento [JS(MultiplyByTen.js):%s ] " { channel=“mqtt:topic:MY-MQTT:RTL_433:wind_dir_deg0” }

/--------/ DivideByTen.js
(function(dividendo) {
var divisore = 10;

var diviso_dieci = (parseFloat(dividendo)/divisore);
// diviso_dieci = dividendo/divisore

var logger = Java.type(“org.slf4j.LoggerFactory”).getLogger("######### DivideByTen");
logger.warn("Valore orig: " + dividendo + " -> diviso dieci: " + diviso_dieci);

// return diviso_dieci.toString();
return diviso_dieci;
//return 1
})(input)

/------------/ — MultiplyByTen.js is similar…

(make it return a string), the binding channel can match up the transformed string to a Number Item.

It seems to work now but I don’t know if this is what you meant… :wink:

Persistence instead still doesn’t work…
I tried adding another channel in .thing to get original data from MQTT without transformation but wind_dir_deg36 is also divided by 10…

Type number : wind_dir_deg36  [ stateTopic="sensors/rtl_433/P119/C0/wind_dir_deg" ]  

I can’t understand why…

If you have a persistence problem, start a new thread instead of using one about custom icons.
You cannot now change the old data stored from before you introduced the divide transform to your data.

Me neither. Have you linked an Item to that channel?
Note that some bindings are not very good at picking up small edits to xxx.things files. I would always recommend restarting the binding if you think it is ignoring Thing edits.