I’ve a setpint that manages when the heater should start and stop. That is working well.
Now I would like to map the Icon based on the min-max values.
The Sitemap contains:
Well, that should work, I know, but isn’t there a better way?
I mean, if I have new min-max items I should recreate new icons every time.
Something that would create a percent based on min-max and that would be used to call the icon would be better.
I’ve tested this with no luck:
It means it gets the right icon, BUT the “state=24&format=png” doesn’t allow the icon to be shown and it overrides the heating-80 transfoming it in heating-24 (->heating-20).
Maybe @sondi , the creator, has an Idea? The @rtvb suggestion is something I haven’t understood…
In your example, the ‘Heating_WaterTemperaturePercent’ gets updated with the value in percent based on the item Heating_WaterTemperature as soon it receives an update. Until here ok.
In my example the node30_sw1_setpoint would be your Heating_WaterTemperature.
Well, my item is used as setpoint. How can I change the icon of my setpoint based on the Heating_WaterTemperaturePercent value? I’m missing the .sitemap part, maybe.
The value of my node30_sw1_setpoint is used then to check it against the temperature in the room to turn the heater on or off, so node30_sw1_setpoint should not alterated. I only need to know how associate the icon of node30_sw1_setpoint based on your rule, also based on the Heating_WaterTemperaturePercent.
because I am lately working with HABPanel my sitemaps are not up to date anymore, so it took me a while to test everything. You are totally right, that my old post isn’t working anymore in OH2. This is beacuse of the dynamically built svg icons.
After a little testing I’ve found an little “dirty” hack to get what you need/want
I’ve called the heating-icons within the browser and saved them locally as svg-files. So the svg-files itself contain the correct state and colors. Just change the state-value in the URL (0,20,40,60,80,100) to get the different states. http://<my_OH2_IP:8080/icon/heating?state=0&format=svg
I’ve saved the icons as setpoint0.svg, setpoint20.svg, and so on
Put these files in the icons/classic folder of you openHAB2 installation
Create an additional Number Item for the icon (the other Item is your Setpoint)
Number LivingroomSetpoint "Livingroom [%.1f °C]" {channel="homematic:HM-CC-RT-DN:ccu:MEQxxxxxxx:4#SET_TEMPERATURE" }
Number LivingroomIconSetpoint "Icon Setpoint LivingRoom"
Create a rule, that changes the state of your Icon-Item depending on the Setpoint Value
rule "ChangeLivingRoomSetpointIcon"
when
Item LivingroomSetpoint received update
then
if (LivingroomSetpoint.state >= 10 && LivingroomSetpoint.state <=12) {postUpdate(LivingroomIconSetpoint, 0) }
if (LivingroomSetpoint.state > 12 && LivingroomSetpoint.state <= 16) {postUpdate(LivingroomIconSetpoint, 20) }
if (LivingroomSetpoint.state > 16 && LivingroomSetpoint.state <= 22) {postUpdate(LivingroomIconSetpoint, 40) }
if (LivingroomSetpoint.state > 22 && LivingroomSetpoint.state <= 25) {postUpdate(LivingroomIconSetpoint, 60) }
if (LivingroomSetpoint.state > 25 && LivingroomSetpoint.state < 35) {postUpdate(LivingroomIconSetpoint, 80) }
if (LivingroomSetpoint.state > 35 && LivingroomSetpoint.state < 50) {postUpdate(LivingroomIconSetpoint, 100) }
end
5 Change the sitemap depending on the Icon-Item. Important is, that you use your new icons setpointx.svg and not the default openHAB Icon heating, because this is dynamically created depending on the item-state.
Text item=LivingroomSetpoint label="Setpoint [%d °C]" icon="setpoint0" visibility=[LivingroomIconSetpoint==0]
Text item=LivingroomSetpoint label="Setpoint [%d °C]" icon="setpoint20" visibility=[LivingroomIconSetpoint==20]
Text item=LivingroomSetpoint label="Setpoint [%d °C]" icon="setpoint40" visibility=[LivingroomIconSetpoint==40]
Text item=LivingroomSetpoint label="Setpoint [%d °C]" icon="setpoint60" visibility=[LivingroomIconSetpoint==60]
Text item=LivingroomSetpoint label="Setpoint [%d °C]" icon="setpoint80" visibility=[LivingroomIconSetpoint==80]
Text item=LivingroomSetpoint label="Setpoint [%d °C]" icon="setpoint100" visibility=[LivingroomIconSetpoint==100]
Using the Setpoint item shows the correct value, while using you’re custom icons shows the correct depending icon
Thanks @sondi but i got an error.
The rules are working (corrected some variables) but the icon doesn’t change, this because the “state” overrides the icon.
if I have the Icon (in your example ‘LivingroomIconSetpoint’) at 60% the icon url gets:
it worked here with my setup also with png. What I just saw is the difference in the filenames. Could you try to use names without ‘-’ like ‘setpoint40’ like I did. I think the minus could be a sort of indicator so the svg or png is created dynamically from openhab.
Hello @sondi ,
The “-” was the problem on the svg. Now I cannot test more, because I’m having strange issues. I’ve always edited the files manually. Now it seems the edit is not taken and it’s happened one time that my last changes were lost after a process restart. Is that possible??
Even editing a single string in the sitemap (/etc/openhab/configurations/sitemaps) and restarting the process, the modification is not taken :-/
Hey, bring that man (@sondi) one beer!!
I’ve got it, it works!
What was the problem? Uhm… well, I was editing the openhab1 config files the last two hours!!! :’(
Well it’s monday!!!
Thanks a lot!
More to the subject!
I have a tank volume - max 1200 litre and want to how the content with an icon “humidity”. As the humidity icon varies from 0 to 100, I will see 100% from 100 litre to 1200 litre - this is not the purpose.
The suffix of the icon (humidity_0, humidity_10,…humidity_100) can be calulated as
suffix = (value/1200*10)*10
Can this be used to select the correct icon based on the value?
Hey everyone and thanks for your efforts on this issue. But I think the solutions are all in fact only workarounds leading to really cluttered and messy configuration code.
For the specific issue, which I am also facing:
If I have somthing like Setpoint item=Thermostat_Temp_EG_WZ_Alle minValue=4 maxValue=30 step=0.5 label="Heizung [%.1f °C]" in my sitemap, would it not be the best to automatically map the current value to a percentage between minValue and maxValue in any case?
And in general:
I think there are many other cases where the state of the icon does not correspond to the actual item value. So maybe some general method of mapping the value to the item state would be useful, without having to define wrapper items and rules for it or even new icons. I guess that this is a rather big deal and maybe too complicated to be implemented at all…
I really would like to know that as well as the hell of a work from the above “rules version” isnt worth the effort (i got like 10 Valves…)…and i would really like to know the code for this…