[SOLVED] Dynamic Icons problem with rules

  • Platform information:
    • Hardware: Raspberry Pi 4 / 4GB RAM / 64GB SD card
    • OS:
cat /etc/os-release

PRETTY_NAME=“Raspbian GNU/Linux 10 (buster)”
NAME=“Raspbian GNU/Linux”
VERSION_ID=“10”
VERSION=“10 (buster)”
VERSION_CODENAME=buster
ID=raspbian
ID_LIKE=debian

  • Java Runtime Environment:
java -version
openjdk version "1.8.0_212"
OpenJDK Runtime Environment (build 1.8.0_212-8u212-b01-1+rpi1-b01)
OpenJDK Client VM (build 25.212-b01, mixed mode)
  • openHAB version:
dpkg --list | grep openhab
ii  openhab2                       2.5.5-1                             all          openhab2
ii  openhab2-addons                2.5.5-1                             all          openhab2-addons
  • Issue of the topic:
    Actually, I am trying to add dynamic icons in my project. I have built up the interface in HABPanel like the following picture:

However, I tried to make an alarm notification by adding the status on the right side of my current status.
Currently, I construct my system by building up the MQTT Broker and installed it on my Raspberry Pi.
I can confirm that it worked smoothly with actual signals (with MQTT.fx v1.7.1).


I can only make the string of the status to change in OnOffType, but I can not make my icon change in the status.
I am not sure how to change it by the rules. Could you please be kind to help me? Thank you in advance for any suggestion!

Following picture is the configuration of my dummy widgets setting:


(By the way, I had my dynamic icons in the classic file)
image

  • Please post configurations (if applicable):
    • Items configuration related to the issue
    Number Bed_1_analog "Bed Exit Detector [%d]" <analog>  {mqtt="<[mosquitto:Bed_1:state:default]"}

    Number Bed_1_percent "Bed Exit Detector [%.1f]" <percent>  {mqtt="<[mosquitto:Bed_1:state:default]"}

    Number Bed_1_analog_num "Analog" <analog>  {mqtt="<[mosquitto:Bed_1:state:default]"}

    Number Bed_1_percent_num "Percent" <percent>  {mqtt="<[mosquitto:Bed_1:state:default]"}

    String Bed_1_status "Status" <light>  {mqtt="<[mosquitto:Bed_1:state:default]"}
  • No Sitemap configuration
  • Rules code related to the issue
    First .rules file, I tried to apply in my project
rule "Bed Exit"
when
    Item Bed_1_status changed
then 
    logInfo("Rule", "start to manage the status!")
    val status_num = transform("status", "$.status", json)

    if(Bed_1_status.state == "ON")
    {
       Bed_1_status.postUpdate("red")
    }
    else
    {
       Bed_1_status.postUpdate("green")
    }
end

Second .rules I tried to apply in my project

rule "Wallplug_FF_LR_TV ON"
when
  Item Bed_1_status changed from OFF to ON
then
  Bed_1_status.postUpdate("red")
end

rule "Wallplug_FF_LR_TV OFF"
when
  Item Bed_1_status changed from ON to OFF
then
  Bed_1_status.postUpdate("red")
end
  • No Services configuration related to the issue

Following is my Things configuration

  • If logs where generated please post these here using code fences:

Currently, I am not sure how to fix up the warning but I think there is no problem with current system.

==> /var/log/openhab2/events.log <==
2020-05-31 08:43:54.164 [vent.ItemStateChangedEvent] - mqtt_topic_ba6a06c9_Bed_1_percent changed from 0.0 to 3.1
2020-05-31 08:43:54.179 [vent.ItemStateChangedEvent] - mqtt_topic_ba6a06c9_Bed_1_analog_num changed from 0 to 32
2020-05-31 08:43:54.193 [vent.ItemStateChangedEvent] - mqtt_topic_ba6a06c9_Bed_1_percent_num changed from 0.0 to 3.1
2020-05-31 08:43:54.206 [vent.ItemStateChangedEvent] - mqtt_topic_ba6a06c9_Bed_1_analog changed from 0 to 32

==> /var/log/openhab2/openhab.log <==
2020-05-31 08:43:54.642 [WARN ] [ab.binding.mqtt.generic.ChannelState] - Command '{"analog":290,"percent":28.30,"status":0}' not supported by type 'OnOffValue': No enum constant org.eclipse.smarthome.core.library.types.OnOffType.{"analog":290,"percent":28.30,"status":0}

==> /var/log/openhab2/events.log <==
2020-05-31 08:43:54.650 [vent.ItemStateChangedEvent] - mqtt_topic_736bf7e5_Bed_1_status changed from ON to OFF
2020-05-31 08:43:54.657 [vent.ItemStateChangedEvent] - mqtt_topic_ba6a06c9_Bed_1_percent changed from 3.1 to 28.3
2020-05-31 08:43:54.664 [vent.ItemStateChangedEvent] - mqtt_topic_ba6a06c9_Bed_1_analog_num changed from 32 to 290
2020-05-31 08:43:54.670 [vent.ItemStateChangedEvent] - mqtt_topic_ba6a06c9_Bed_1_percent_num changed from 3.1 to 28.3
2020-05-31 08:43:54.677 [vent.ItemStateChangedEvent] - mqtt_topic_ba6a06c9_Bed_1_analog changed from 32 to 290

==> /var/log/openhab2/openhab.log <==
2020-05-31 08:43:55.149 [WARN ] [ab.binding.mqtt.generic.ChannelState] - Command '{"analog":0,"percent":0.00,"status":1}' not supported by type 'OnOffValue': No enum constant org.eclipse.smarthome.core.library.types.OnOffType.{"analog":0,"percent":0.00,"status":1}

==> /var/log/openhab2/events.log <==
2020-05-31 08:43:55.169 [vent.ItemStateChangedEvent] - mqtt_topic_736bf7e5_Bed_1_status changed from OFF to ON
2020-05-31 08:43:55.183 [vent.ItemStateChangedEvent] - mqtt_topic_ba6a06c9_Bed_1_percent changed from 28.3 to 0.0
2020-05-31 08:43:55.198 [vent.ItemStateChangedEvent] - mqtt_topic_ba6a06c9_Bed_1_analog_num changed from 290 to 0
2020-05-31 08:43:55.211 [vent.ItemStateChangedEvent] - mqtt_topic_ba6a06c9_Bed_1_percent_num changed from 28.3 to 0.0
2020-05-31 08:43:55.225 [vent.ItemStateChangedEvent] - mqtt_topic_ba6a06c9_Bed_1_analog changed from 290 to 0

==> /var/log/openhab2/openhab.log <==
2020-05-31 08:43:55.655 [WARN ] [ab.binding.mqtt.generic.ChannelState] - Command '{"analog":0,"percent":0.00,"status":1}' not supported by type 'OnOffValue': No enum constant org.eclipse.smarthome.core.library.types.OnOffType.{"analog":0,"percent":0.00,"status":1}
2020-05-31 08:43:56.163 [WARN ] [ab.binding.mqtt.generic.ChannelState] - Command '{"analog":0,"percent":0.00,"status":1}' not supported by type 'OnOffValue': No enum constant org.eclipse.smarthome.core.library.types.OnOffType.{"analog":0,"percent":0.00,"status":1}
2020-05-31 08:43:56.668 [WARN ] [ab.binding.mqtt.generic.ChannelState] - Command '{"analog":0,"percent":0.00,"status":1}' not supported by type 'OnOffValue': No enum constant org.eclipse.smarthome.core.library.types.OnOffType.{"analog":0,"percent":0.00,"status":1}
2020-05-31 08:43:24.231 [WARN ] [ab.binding.mqtt.generic.ChannelState] - Command '{"analog":0,"percent":0.00,"status":1}' not supported by type 'OnOffValue': No enum constant org.eclipse.smarthome.core.library.types.OnOffType.{"analog":0,"percent":0.00,"status":1}
2020-05-31 08:43:24.739 [WARN ] [ab.binding.mqtt.generic.ChannelState] - Command '{"analog":0,"percent":0.00,"status":1}' not supported by type 'OnOffValue': No enum constant org.eclipse.smarthome.core.library.types.OnOffType.{"analog":0,"percent":0.00,"status":1}
2020-05-31 08:43:25.244 [WARN ] [ab.binding.mqtt.generic.ChannelState] - Command '{"analog":0,"percent":0.00,"status":1}' not supported by type 'OnOffValue': No enum constant org.eclipse.smarthome.core.library.types.OnOffType.{"analog":0,"percent":0.00,"status":1}

Thank you for any suggestion again!!!

In addition, I have used Javascript Transformation and Map Transformation.
Here is my transformation .js files

(function(i) {
	try {
		data = JSON.parse(i);
		analog = Number(data.analog.toFixed(0), 10).toFixed(0);
		return analog;
	}
	catch (err) {
		return "-";
	}
})(input)

.map file:

1=ON
0=OFF

I have also checked the following articles but I have no idea what’s the problem at all.
Reference:

This Item is configured for use with MQTT binding version 1.

Anything you do with Things and channels with MQTT binding version 2 will not apply here. You’ve probably used old posts or tutorials.

when
    Item Bed_1_status changed
then 
...
    if(Bed_1_status.state == "ON")
    {
       Bed_1_status.postUpdate("red")
    }
    else
    {
       Bed_1_status.postUpdate("green")
    }

What are you expecting this rule to do exactly?
When your Item changes to anything, the rule will run and change it to “red” or “green”. The the rule will run again because of the change, and always set “green”. No matter what you do, the Item is always “green”.

Wait a moment. I expect Bed_1_status can change the icon on the panel from

image

to

image

(if Bed_1_status.state is always on. However, Bed_1_status.state should show the red one, since the Bed_1_status.state right now is 1 (ON).)

and when the status changed (from 0 to 1 or from OFF to ON)
Bed_1_status.state picture will be

image

Actually, I just want to test if the dynamic icons work at all.
So the status is published by the Arduino UNO R3 (the signal from analog input) (Sorry for forgetting to mention about it.), the condition is that the Arduino UNO R3 will send 0 if the analog value is smaller than 100. Otherwise, the Arduino UNO R3 will give 1 in the status part.

However, now the HABpanel looks like this:

I thought that it is because of the “undefined” status?

Thank you for your reply! Please help me to deal with this situation.

Also, could you please give me some advice to change the item file from 1.x version to 2.x version? Thank you very much!!!

(Sorry for confusing you by using so much it.)

Slow down. I have no idea what “it” you are talking about, and there seems to be a lot of confusion about “it” being 0/1, on/off, or red/green, or undefined ?

Forget icons for now. That is the last thing you set up. First get Items doing what you want. Can’t help much with that, as don’t know what you want.

If you’ve set up Things and channels, you will want to link your Items to channels.

Well, actually I think they have worked as what I expected except the icons( :cry: :sob: :scream:).

Okay, I have set up the Things and channels like the following pictures:

MQTT Broker

Bed_1

Channels in Bed_1

Analog_num channel configuration

Since I sent the json format from my Arduino UNO Rev3 (with ESP8266) from WIFI to my MQTT Broker (Raspberry Pi 4), I need to do Javascript Transformation by the script.

(function(i) {
	try {
		data = JSON.parse(i);
		analog = Number(data.analog.toFixed(0), 10).toFixed(0);
		return analog;
	}
	catch (err) {
		return "-";
	}
})(input)

Percent_num part is just the same. The only difference is that I originally designed different transformation in my Arduino UNO Rev3.

My json message is this:
{“analog”:50,“percent”:5.0,“status”:1}
or
{“analog”:512,“percent”:50.0,“status”:0}

I think it work perfectly:
(when I ground the analog input)

(connected to the air)

The problem is the status (which I decide to make it specific for my dynamic icons)
Things:

Channels:

Configuration of channels:

Thank you for your fast reply!!!

Okay.
So far as I can see, you have created a switch type channel, called mqtt:topic:736b17e5:Bed_1_status
This channel is not linked to any Item that I can see.
This channel will listen out for the topic Bed_1
If it gets a message on that topic, it first applies a JS transform to the payload.
So far as I can make out, that will return a number from the payload analog field, such as 50 ?
That transformation is chained to another transformation, a MAP.
Your map has lookup entries for 0 and 1 only, no default.
I would expect looking up a value like 50 to fail.
When a transformation fails, the whole payload string is returned instead.
Next, because this is a switch type channel, that string is given to the on/off parser.
Because your on/off channel parameters have been left default, I would expect 0/1 or ON/OFF to pass through to channel state.
But because your transformation failed, it is trying to handle the complete payload JSON which does not fit either 0/1 or ON/OFF.
You just get the warning message logged

2020-05-31 08:43:54.642 [WARN ] [ab.binding.mqtt.generic.ChannelState] - Command '{"analog":290,"percent":28.30,"status":0}' not supported by type 'OnOffValue': No enum constant org.eclipse.smarthome.core.library.types.OnOffType.{"analog":290,"percent":28.30,"status":0}

Actually, the switch type channel you mentioned

mqtt:topic:736b17e5:Bed_1_status

is the status one which performs well in the HabPanel.
I am not sure if it is linked to this item (though I think it should):

String Bed_1_status "Status" <light>  {mqtt="<[mosquitto:Bed_1:state:default]"}

It can get the message from the topic

Bed_1

and it will perfectly transform itself into the value I expect (1/0) and transform the result into ON/OFF by the MAP service(?).
Javascript Transformation file (.js):

(function(i) {
	try {
		data = JSON.parse(i);
		status = Number(data.status.toFixed(0)).toFixed(0);
        return status;
	}
	catch (err) {
		return "-";
	}
})(input)

Actually, if I drop the MAP down. I will get two warning messages from the log.

As the following log (if I delete the transformation part ∩MAP:light.map):

2020-05-31 12:39:57.344 [WARN ] [ab.binding.mqtt.generic.ChannelState] - Command '{"analog":0,"percent":0.00,"status":1}' not supported by type 'OnOffValue': No enum constant org.eclipse.smarthome.core.library.types.OnOffType.{"analog":0,"percent":0.00,"status":1}
2020-05-31 12:39:57.406 [WARN ] [ab.binding.mqtt.generic.ChannelState] - Command '1' not supported by type 'OnOffValue': No enum constant org.eclipse.smarthome.core.library.types.OnOffType.1

So I am not sure which one gives out the first warning:

2020-05-31 12:39:57.344 [WARN ] [ab.binding.mqtt.generic.ChannelState] - Command '{"analog":0,"percent":0.00,"status":1}' not supported by type 'OnOffValue': No enum constant org.eclipse.smarthome.core.library.types.OnOffType.{"analog":0,"percent":0.00,"status":1}

Here is the complete transformation JS file:

(function(i) {
	try {
		data = JSON.parse(i);
		analog = Number(data.analog.toFixed(0), 10).toFixed(0);
		return analog;
	}
	catch (err) {
		return "-";
	}
})(input)
(function(i) {
	try {
		data = JSON.parse(i);
        percent = Number(data.percent.toFixed(1));
        return percent;
	}
	catch (err) {
		return "-";
	}
})(input)
(function(i) {
	try {
		data = JSON.parse(i);
		status = Number(data.status.toFixed(0)).toFixed(0);
        return status;
	}
	catch (err) {
		return "-";
	}
})(input)

I tried to isolate the status from other Things. Or should I put it into the Things Bed_1 with Analog_num and Percent_num?

(The reason why there is Analog_num and Analog is that I thought the value type was String but it seems that it is Number.)

Thus, in the original transformation JS file, I was using Number() to force the type of val to be a Number type value. That is the only difference.

Thank you for your patience!!

That’s a channel.
You can not use channels in HABpanel.
You link channels with Items.
Items and channels are two different kinds of object.
Items can be used in HABpanel.
You configured your HABpanel, so you know which Item is in use.

Have you got Simple Mode turned on, automatically creating Items that have names similar to channels they are automatically linked to?

The configuration for that Item is a version 1 MQTT binding and has absolutely nothing to do with your Things and channels (the mqtt= part)…
Unless you have MQTT binding version 1 installed, it does nothing.

That does not mean the Item has not been linked to something else using PaperUI, but that is something you would have to find out.

Yes, it’s a shame the message doesn’t say which channel(s), but clearly you have at least one that is broken.

Perhaps you can show us your events.log entries showing that happening to your Item?

Okay, no problem! Well, then it seems to be hard to say which channel is borken…( :sob:)

2020-05-31 14:15:08.181 [WARN ] [ab.binding.mqtt.generic.ChannelState] - Command '{"analog":131,"percent":12.80,"status":0}' not supported by type 'OnOffValue': No enum constant org.eclipse.smarthome.core.library.types.OnOffType.{"analog":131,"percent":12.80,"status":0}

==> /var/log/openhab2/events.log <==
2020-05-31 14:15:08.191 [vent.ItemStateChangedEvent] - mqtt_topic_ba6a06c9_Bed_1_percent changed from 0.0 to 12.8
2020-05-31 14:15:08.196 [vent.ItemStateChangedEvent] - mqtt_topic_ba6a06c9_Bed_1_analog_num changed from 0 to 131
2020-05-31 14:15:08.205 [vent.ItemStateChangedEvent] - mqtt_topic_ba6a06c9_Bed_1_percent_num changed from 0.0 to 12.8
2020-05-31 14:15:08.210 [vent.ItemStateChangedEvent] - mqtt_topic_ba6a06c9_Bed_1_analog changed from 0 to 131
2020-05-31 14:15:08.217 [vent.ItemStateChangedEvent] - mqtt_topic_736bf7e5_Bed_1_status changed from ON to OFF

==> /var/log/openhab2/openhab.log <==
2020-05-31 14:15:08.691 [WARN ] [ab.binding.mqtt.generic.ChannelState] - Command '{"analog":301,"percent":29.40,"status":0}' not supported by type 'OnOffValue': No enum constant org.eclipse.smarthome.core.library.types.OnOffType.{"analog":301,"percent":29.40,"status":0}

==> /var/log/openhab2/events.log <==
2020-05-31 14:15:08.710 [vent.ItemStateChangedEvent] - mqtt_topic_ba6a06c9_Bed_1_percent changed from 12.8 to 29.4
2020-05-31 14:15:08.728 [vent.ItemStateChangedEvent] - mqtt_topic_ba6a06c9_Bed_1_analog_num changed from 131 to 301
2020-05-31 14:15:08.740 [vent.ItemStateChangedEvent] - mqtt_topic_ba6a06c9_Bed_1_percent_num changed from 12.8 to 29.4
2020-05-31 14:15:08.754 [vent.ItemStateChangedEvent] - mqtt_topic_ba6a06c9_Bed_1_analog changed from 131 to 301

==> /var/log/openhab2/openhab.log <==
2020-05-31 14:15:09.196 [WARN ] [ab.binding.mqtt.generic.ChannelState] - Command '{"analog":150,"percent":14.60,"status":0}' not supported by type 'OnOffValue': No enum constant org.eclipse.smarthome.core.library.types.OnOffType.{"analog":150,"percent":14.60,"status":0}

==> /var/log/openhab2/events.log <==
2020-05-31 14:15:09.204 [vent.ItemStateChangedEvent] - mqtt_topic_ba6a06c9_Bed_1_percent changed from 29.4 to 14.6
2020-05-31 14:15:09.211 [vent.ItemStateChangedEvent] - mqtt_topic_ba6a06c9_Bed_1_analog_num changed from 301 to 150
2020-05-31 14:15:09.219 [vent.ItemStateChangedEvent] - mqtt_topic_ba6a06c9_Bed_1_percent_num changed from 29.4 to 14.6
2020-05-31 14:15:09.228 [vent.ItemStateChangedEvent] - mqtt_topic_ba6a06c9_Bed_1_analog changed from 301 to 150

==> /var/log/openhab2/openhab.log <==
2020-05-31 14:15:09.705 [WARN ] [ab.binding.mqtt.generic.ChannelState] - Command '{"analog":0,"percent":0.00,"status":1}' not supported by type 'OnOffValue': No enum constant org.eclipse.smarthome.core.library.types.OnOffType.{"analog":0,"percent":0.00,"status":1}

==> /var/log/openhab2/events.log <==
2020-05-31 14:15:09.729 [vent.ItemStateChangedEvent] - mqtt_topic_ba6a06c9_Bed_1_percent changed from 14.6 to 0.0
2020-05-31 14:15:09.749 [vent.ItemStateChangedEvent] - mqtt_topic_ba6a06c9_Bed_1_analog_num changed from 150 to 0
2020-05-31 14:15:09.770 [vent.ItemStateChangedEvent] - mqtt_topic_ba6a06c9_Bed_1_percent_num changed from 14.6 to 0.0
2020-05-31 14:15:09.789 [vent.ItemStateChangedEvent] - mqtt_topic_ba6a06c9_Bed_1_analog changed from 150 to 0
2020-05-31 14:15:09.804 [vent.ItemStateChangedEvent] - mqtt_topic_736bf7e5_Bed_1_status changed from OFF to ON

==> /var/log/openhab2/openhab.log <==
2020-05-31 14:15:10.210 [WARN ] [ab.binding.mqtt.generic.ChannelState] - Command '{"analog":0,"percent":0.00,"status":1}' not supported by type 'OnOffValue': No enum constant org.eclipse.smarthome.core.library.types.OnOffType.{"analog":0,"percent":0.00,"status":1}
2020-05-31 14:15:10.718 [WARN ] [ab.binding.mqtt.generic.ChannelState] - Command '{"analog":0,"percent":0.00,"status":1}' not supported by type 'OnOffValue': No enum constant org.eclipse.smarthome.core.library.types.OnOffType.{"analog":0,"percent":0.00,"status":1}

I have opened the simple mode in the PaperUI (Though I am not sure if the package setting will affect the setting or not since I need to set it to standard to get Add-ons for Transformation part.)

PaperUI configuration:

services/addons.cfg:

How could I test if the channel is broken or not?
I tried to unlink the channels but no one affects the warning.

(Additionally, do you mean that I do not need to add the .items files since I am under the simple mode?I can understand that this is the old version. However, I do not know how to build up a new one at all.)

By the way, I think I used the latest version of MQTT Binding addons offered by OpenHab

I don’t know what that means.
I strongly advise you to have Simple Mode OFF.
People seem to get in to all sorts of trouble with duplicate Items with it on.

That’s your Item. We can guess it is probably linked to channel mqtt:topic:736bf7e5:Bed_1_status , but you could confirm that in PaperUI

The Item Bed_1_status in your items file is unconnected to that Item in any way.

The next step is to find out what Item you are looking at in your HABpanel, so we know which one you are having trouble with.
Guessing that it is Item mqtt_topic_736bf7e5_Bed_1_status , what have you got the icon set to on that Item?

Actually, I don’t even know how to set the icon for the Item.
I just put the icon name in the blank of custom icon (for the ) in HABPanel.

Maybe that is the reason?!?!

(Sorry for the Chinese English. I mean I turn on the Simple Mode.)
If I turn off the Simple Mode, I need to setup the item by myself right?

I turned off the Simple Mode and the following picture is my item list:

I think this is the problem one item?
mqtt_topic_736bf7e5_Bed_1_status

Then, what should I typed in if I need to create one which is linked to my specific channel?

I don’t know HABpanel, no idea how you use it.
In any other UI, you specify the icon in the Item or can override in the sitemap.

I do think you are going to get into trouble with that icon name.
The default icon set includes a family of icons light, light-on, etc.
I do not think you are going to get any custom icons working by using the same name light as a default set.
I would give any custom icons a custom name - mylight , mycustomicon, whatever.

So, does it mean that if I change the name of my icon and it will work?
Then, that me change it first.
If there is any good news, I will let you know.
Thanks a lot!

Current result:

Um, nothing happened at all.

I have tried to use the extension in VS code:

//String Bed_1_status "Status" <mylight>  {mqtt="<[mosquitto:Bed_1:state:default]"}
Switch Bed1Status "Dynamic icon" {channel="mqtt:topic:736bf7e5:Bed_1_status"}

Maybe I should add the label for the icon?

Switch Bed1Status "Dynamic icon" <mylight>{channel="mqtt:topic:736bf7e5:Bed_1_status"}

Um, nothing worked at all.

By the way, how to manage the items in the PaperUI or other advanced methods? Since there are lots of tutorials out there, they seems cannot catch up the update of OpenHab. :sob: :sob: :sob: :sob:

This is the result:

Same as always… :sob: :sob: :sob: :sob:

Start by seeing if your new Item is getting updated. That’s what your events.log is for. Once you know that your Item is updating and what it is getting updated to, you can look at dynamic icons

Now that you’ve given your Item an <icon>, you should see at least the default mylight.svg image, even if the dynamic part is messed up.
If you don’t, then there is something wrong with your HABpanel setup.

You’l get there, there are just a lot of different things to get correct.

(Sorry for the late reply, it was about 12:53 am, and I was asleep.)
Well, I tried 3 different ways to apply my icon on item:

  1. write original item (it was created by the simple mode) back in the .items file and add the icon <mylight> which is according to the .svg file name.

Switch mqtt_topic_736bf7e5_Bed_1_status "dynamic icon" <mylight> {channel="mqtt:topic:736bf7e5:Bed_1_status"}
  1. add item from extension in VS code into the .items file with the icon <mylight>.

Switch Bed1Status "Dynamic icon" <mylight> {channel="mqtt:topic:736bf7e5:Bed_1_status"}
  1. add the item from the PaperUI (only the weird thing is that I have changed the name of item but it still use the same name from the simple mode creation with a character lost in nowhere.)

I added them in the .items file and tried every item but there is no difference between them actually.

Switch Bed1Status "Dynamic icon" <mylight> {channel="mqtt:topic:736bf7e5:Bed_1_status"}  //added by the extension in VS code
Switch mqtt_topic_736bf7e5_Bed_1_status "dynamic icon" <mylight> {channel="mqtt:topic:736bf7e5:Bed_1_status"}  //added from the original simple mode created item
Switch mqtt_topic_736bf7e_Bed_1_status "mylight" <mylight> {channel="mqtt:topic:736bf7e5:Bed_1_status"}  //manually added item

Additionally, there is another weird error in the VS code.
I definitely have defined the .rules file and why the VS code said that VS code cannot find the existing one??? (I have marked the save all button to check that I have definitely “save” the file!!!)

You never said if you get the display of your default icon image.

I can’t keep up with what Item you are doing what to anymore. Whatever Item it is you are using, is it a Switch type?
I keep pointing you to look in your events.log and see what states your Item is getting set to.
When you do, you’ll probably find that it is getting set to ON and OFF, as it is a Switch type Item and that is the states that Switch type Items accept.

Now consider your icon image files family. Dynamic icons use the state of the Item. If the Item get sets to ON and OFF, then you would probably want to use icon images with filenames like someIcon-on.svg and someIcon-off.svg.
Statres ON and OFF will never ever match for a filename like someIcon-red.svg

Ooops, sorry for not displaying the icon image for you.

Default (mylight.svg)

image

Green (mylight-green.svg) (off)

image

Red (mylight-red.svg) (on)

image

I think they have changed the status from ON to OFF and OFF to ON.

Actually, the default image is displayed by the custom icon setting?
Since it is always there, I didn’t mention the presentation of default image at all.

Also, I have changed the icon image name now but the condition looks like the same.

==> /var/log/openhab2/events.log <==
2020-06-01 00:54:03.713 [vent.ItemStateChangedEvent] - mqtt_topic_ba6a06c9_Bed_1_percent changed from 3.8 to 28.1
2020-06-01 00:54:03.719 [vent.ItemStateChangedEvent] - mqtt_topic_ba6a06c9_Bed_1_analog_num changed from 39 to 288
2020-06-01 00:54:03.726 [vent.ItemStateChangedEvent] - mqtt_topic_ba6a06c9_Bed_1_percent_num changed from 3.8 to 28.1
2020-06-01 00:54:03.733 [vent.ItemStateChangedEvent] - mqtt_topic_ba6a06c9_Bed_1_analog changed from 39 to 288
2020-06-01 00:54:03.742 [vent.ItemStateChangedEvent] - mqtt_topic_736bf7e5_Bed_1_status changed from ON to OFF

==> /var/log/openhab2/openhab.log <==
2020-06-01 00:54:03.742 [INFO ] [.eclipse.smarthome.model.script.Rule] - start to manage the status!

==> /var/log/openhab2/events.log <==
2020-06-01 00:54:03.745 [vent.ItemStateChangedEvent] - mqtt_topic_736bf7e_Bed_1_status changed from ON to OFF
2020-06-01 00:54:03.746 [vent.ItemStateChangedEvent] - Bed1Status changed from ON to OFF

==> /var/log/openhab2/openhab.log <==
2020-06-01 00:54:03.749 [WARN ] [rthome.model.script.actions.BusEvent] - Cannot convert 'green' to a state type which item 'Bed1Status' accepts: [OnOffType, UnDefType].
2020-06-01 00:54:04.215 [WARN ] [ab.binding.mqtt.generic.ChannelState] - Command '{"analog":0,"percent":0.00,"status":1}' not supported by type 'OnOffValue': No enum constant org.eclipse.smarthome.core.library.types.OnOffType.{"analog":0,"percent":0.00,"status":1}

==> /var/log/openhab2/events.log <==
2020-06-01 00:54:04.230 [vent.ItemStateChangedEvent] - mqtt_topic_ba6a06c9_Bed_1_percent changed from 28.1 to 0.0
2020-06-01 00:54:04.246 [vent.ItemStateChangedEvent] - mqtt_topic_ba6a06c9_Bed_1_analog_num changed from 288 to 0
2020-06-01 00:54:04.262 [vent.ItemStateChangedEvent] - mqtt_topic_ba6a06c9_Bed_1_percent_num changed from 28.1 to 0.0
2020-06-01 00:54:04.276 [vent.ItemStateChangedEvent] - mqtt_topic_ba6a06c9_Bed_1_analog changed from 288 to 0
2020-06-01 00:54:04.287 [vent.ItemStateChangedEvent] - mqtt_topic_736bf7e5_Bed_1_status changed from OFF to ON
2020-06-01 00:54:04.290 [vent.ItemStateChangedEvent] - mqtt_topic_736bf7e_Bed_1_status changed from OFF to ON

==> /var/log/openhab2/openhab.log <==
2020-06-01 00:54:04.290 [INFO ] [.eclipse.smarthome.model.script.Rule] - start to manage the status!

==> /var/log/openhab2/events.log <==
2020-06-01 00:54:04.293 [vent.ItemStateChangedEvent] - Bed1Status changed from OFF to ON

==> /var/log/openhab2/openhab.log <==
2020-06-01 00:54:04.299 [WARN ] [rthome.model.script.actions.BusEvent] - Cannot convert 'green' to a state type which item 'Bed1Status' accepts: [OnOffType, UnDefType].
2020-06-01 00:54:04.720 [WARN ] [ab.binding.mqtt.generic.ChannelState] - Command '{"analog":0,"percent":0.00,"status":1}' not supported by type 'OnOffValue': No enum constant org.eclipse.smarthome.core.library.types.OnOffType.{"analog":0,"percent":0.00,"status":1}
2020-06-01 00:54:05.228 [WARN ] [ab.binding.mqtt.generic.ChannelState] - Command '{"analog":0,"percent":0.00,"status":1}' not supported by type 'OnOffValue': No enum constant org.eclipse.smarthome.core.library.types.OnOffType.{"analog":0,"percent":0.00,"status":1}

I noticed that there is a warning about the postUpdate (for the “green” part and “red” part). So I changed the .rules file into this.
Also, I noticed the log of INFO.

2020-06-01 01:04:46.464 [INFO ] [.eclipse.smarthome.model.script.Rule] - start to manage the status!

This is the .rules file:

rule "Bed Exit"
when
    Item Bed1Status changed
then 
    logInfo("Rule", "start to manage the status!")
    if(Bed1Status.state == "ON")
    {
       Bed1Status.postUpdate("ON")
    }
    else if (Bed1Status.state == "OFF")
    {
       Bed1Status.postUpdate("OFF")
    }
end

This is the figure I want to illustrate that the icon is as static as always.

This is the pure log after changing the postUpdate


==> /var/log/openhab2/events.log <==
2020-06-01 01:04:46.395 [vent.ItemStateChangedEvent] - mqtt_topic_ba6a06c9_Bed_1_percent changed from 0.0 to 29.7
2020-06-01 01:04:46.408 [vent.ItemStateChangedEvent] - mqtt_topic_ba6a06c9_Bed_1_analog_num changed from 0 to 304
2020-06-01 01:04:46.422 [vent.ItemStateChangedEvent] - mqtt_topic_ba6a06c9_Bed_1_percent_num changed from 0.0 to 29.7
2020-06-01 01:04:46.432 [vent.ItemStateChangedEvent] - mqtt_topic_ba6a06c9_Bed_1_analog changed from 0 to 304
2020-06-01 01:04:46.448 [vent.ItemStateChangedEvent] - mqtt_topic_736bf7e5_Bed_1_status changed from ON to OFF
2020-06-01 01:04:46.452 [vent.ItemStateChangedEvent] - mqtt_topic_736bf7e_Bed_1_status changed from ON to OFF
2020-06-01 01:04:46.460 [vent.ItemStateChangedEvent] - Bed1Status changed from ON to OFF

==> /var/log/openhab2/openhab.log <==
2020-06-01 01:04:46.464 [INFO ] [.eclipse.smarthome.model.script.Rule] - start to manage the status!
2020-06-01 01:04:46.883 [WARN ] [ab.binding.mqtt.generic.ChannelState] - Command '{"analog":180,"percent":17.50,"status":0}' not supported by type 'OnOffValue': No enum constant org.eclipse.smarthome.core.library.types.OnOffType.{"analog":180,"percent":17.50,"status":0}

==> /var/log/openhab2/events.log <==
2020-06-01 01:04:46.891 [vent.ItemStateChangedEvent] - mqtt_topic_ba6a06c9_Bed_1_percent changed from 29.7 to 17.5
2020-06-01 01:04:46.897 [vent.ItemStateChangedEvent] - mqtt_topic_ba6a06c9_Bed_1_analog_num changed from 304 to 180
2020-06-01 01:04:46.906 [vent.ItemStateChangedEvent] - mqtt_topic_ba6a06c9_Bed_1_percent_num changed from 29.7 to 17.5
2020-06-01 01:04:46.912 [vent.ItemStateChangedEvent] - mqtt_topic_ba6a06c9_Bed_1_analog changed from 304 to 180

==> /var/log/openhab2/openhab.log <==
2020-06-01 01:04:47.392 [WARN ] [ab.binding.mqtt.generic.ChannelState] - Command '{"analog":448,"percent":43.70,"status":0}' not supported by type 'OnOffValue': No enum constant org.eclipse.smarthome.core.library.types.OnOffType.{"analog":448,"percent":43.70,"status":0}

==> /var/log/openhab2/events.log <==
2020-06-01 01:04:47.408 [vent.ItemStateChangedEvent] - mqtt_topic_ba6a06c9_Bed_1_percent changed from 17.5 to 43.7
2020-06-01 01:04:47.421 [vent.ItemStateChangedEvent] - mqtt_topic_ba6a06c9_Bed_1_analog_num changed from 180 to 448
2020-06-01 01:04:47.433 [vent.ItemStateChangedEvent] - mqtt_topic_ba6a06c9_Bed_1_percent_num changed from 17.5 to 43.7
2020-06-01 01:04:47.445 [vent.ItemStateChangedEvent] - mqtt_topic_ba6a06c9_Bed_1_analog changed from 180 to 448

==> /var/log/openhab2/openhab.log <==
2020-06-01 01:04:47.898 [WARN ] [ab.binding.mqtt.generic.ChannelState] - Command '{"analog":87,"percent":8.50,"status":1}' not supported by type 'OnOffValue': No enum constant org.eclipse.smarthome.core.library.types.OnOffType.{"analog":87,"percent":8.50,"status":1}

==> /var/log/openhab2/events.log <==
2020-06-01 01:04:47.904 [vent.ItemStateChangedEvent] - mqtt_topic_ba6a06c9_Bed_1_percent changed from 43.7 to 8.5
2020-06-01 01:04:47.911 [vent.ItemStateChangedEvent] - mqtt_topic_ba6a06c9_Bed_1_analog_num changed from 448 to 87
2020-06-01 01:04:47.917 [vent.ItemStateChangedEvent] - mqtt_topic_ba6a06c9_Bed_1_percent_num changed from 43.7 to 8.5
2020-06-01 01:04:47.924 [vent.ItemStateChangedEvent] - mqtt_topic_ba6a06c9_Bed_1_analog changed from 448 to 87
2020-06-01 01:04:47.931 [vent.ItemStateChangedEvent] - mqtt_topic_736bf7e5_Bed_1_status changed from OFF to ON
2020-06-01 01:04:47.932 [vent.ItemStateChangedEvent] - mqtt_topic_736bf7e_Bed_1_status changed from OFF to ON
2020-06-01 01:04:47.934 [vent.ItemStateChangedEvent] - Bed1Status changed from OFF to ON

==> /var/log/openhab2/openhab.log <==
2020-06-01 01:04:47.938 [INFO ] [.eclipse.smarthome.model.script.Rule] - start to manage the status!

Last but not least, all switch work fine in the log except the dynamic icon.

This is the original item.

2020-06-01 01:04:47.931 [vent.ItemStateChangedEvent] - mqtt_topic_736bf7e5_Bed_1_status changed from OFF to ON

This is the manually created in PaperUI.

2020-06-01 01:04:47.932 [vent.ItemStateChangedEvent] - mqtt_topic_736bf7e_Bed_1_status changed from OFF to ON

The is the extension one from VS code.

2020-06-01 01:04:47.934 [vent.ItemStateChangedEvent] - Bed1Status changed from OFF to ON

Thanks a lot for your effort!! I am really appreciate that.

It’s a nonsense.
Your Item Bed1Status is a Switch type Item still, isn’t it?

if(Bed1Status.state == "ON")

This will never be true. A Switch type Item might have an OnOffType state ON
A Switch type Item will never have a sytring type state "ON"

Next, if you fixed that -

if(Bed1Status.state == ON)
    {
       Bed1Status.postUpdate("ON")

what possible purpose is this for? The Item is already ON and you set it ON.

Um, actually, then it means that I don’t need any .rules file?
I am not sure where can I set the dynamic icon for my item.
Could you please give me an example?
Or it will automatically catch the dynamic icon mylight.svg, myloght-on.svg, mylight-off.svg.

Thanks a lot!! :hugs: :hugs: :hugs: :hugs: :hugs:

I really do not know which of your three Items you are now displaying in your HABpanel.

Your file based Item will have its icon root filename set in <brackets>

Switch Bed1Status "Dynamic icon" <mylight> {channel="...

You don’t do anything special to make it dynamic icon, just provide a complete image set. You must have the default mylight.svg and will want also mylight-on.svg and mylight-off.svg, these must all go in /icons/classic/ folder.

For PaperUI created Icons, you edit the root filename into box labelled category

This establishes a default icon set to use for the Item.
I do not know how you make HABpanel use the default icon in whatever widget you are using. Perhaps by not specifying a custom icon.
.