Basic switch questions, clarification about returned value

My first sitemap is to get simple switches that toggle my power management system relays via snmp. I have gotten the item, and sitemap functional to toggle the relays, but have trouble with some minor details.

Example items:

Switch Strip1_plug2 “Strip 1 Outlet 2 [%s] " { snmp=”<[] >[ON:] >[OFF:]"}
Switch Strip1_plug1 “Strip 1 Outlet 1 " { snmp=”>[ON:] >[OFF:]"}

Example sitemap:
sitemap default label=“My first sitemap”
Frame label=“Power Management” {
Text item=“Strip_1” label=“Strip 1” {
Switch item=Strip1_plug1 mappings=[OFF=“0”, ON=“1”]
Switch item=Strip1_plug2 mappings=[OFF=“0”, ON=“1”]

I have two issues, first is can a switch even return a value or state? I have seen multiple example documents were a switch item receives a value and displays it, as my first item (Strip1_plug2) is configured; however, it never works. I can get the value if I use a separate item with the type as Text, or Number, but not as Switch (perhaps this is value cannot be displayed but is used to toggle the icon state?) My second issue, is I must used mappings=[OFF=“0”, ON=“1”] in order for this to work, and when I do it the sitemap (habmin) replaces the nice switch icon with an ugly drop down 0 or 1 value. How can i use the switch and still get functionality?

First, even with short code snippets, it is sooo much easier to read if you use code fences:

code goes here

A switch can only have an ON or OFF or NULL as its state (NULL is a special state to indicate the Item is uninitialized).

I’d have to look at those examples but they are likely either using String Items or Number Items placed on the sitemap as a Switch with mappings, or they are using a MAP transform to convert the ON/OFF to something more human readable. They also might be using the visibility element to only show certain rows under certain conditions.

The icon displayed is based on the state of the Item. See

Don’t use mappings and instead use a transform or a Rule with Proxy Items.

I’m unfamiliar with the SNMP binding and it isn’t exactly clear exactly what you are trying to accomplish. Perhaps if you posted a screen shot showing what you are seeing and an explanation or screenshot of what you want it will be easier to help.

Thank you for the information, after some troubleshooting I have found several small issues that were causing me lots of grief. It looks like ONLY habmin UI was not working without the sitemap mappings (mapping ON to 1, and OFF to 0). Once i removed the mappings I got the switch icon back, and was fully functional in Classic UI and basic UI (very odd), habmin still not working. Also snmp bindings are very picky about white space, one space before the " caused it not to function. I can now snmpget values (which determines switch state) and initializes correctly and able to toggle the relays with this syntax. I used String/Text to return the name of the outlet as well.

Also for some reason openhab doesn’t like my long item-names (or perhaps two underscores), I changed them from Strip1_plug1 to just plug1; I’m not exactly sure what the issue was here, as soon as I made the changes I started getting values correctly. I noticed this when one mapping change affected multiple outlets.


String  plug1_name      "[%s]"          {snmp="<[]"}
Switch plug1   "Strip 1 Outlet 1"     {snmp="<[IP_address:public:OID_VALUE:60:MAP(] >[ON:IP_address:private:OID_VALUE:1] >[OFF:IP_address:private:OID_VALUE:0]"}


sitemap default label="My first sitemap"
Frame label="Power Management" {
    Text item="strip_1" label="strip 1" {
            Switch item=plug1
            Text   item=plug1_name
             <multiple switches>

In my previous example I used a String with the name “plug1_name” to return the value of the String attached for that specific plug. Is there anyway I can dynamically update the switch name with this returned value? So i don’t have to relay on a static name like “Strip 1 Outlet 1” ,but pull the value for plug1_name ?

On the sitemap you can put all your Switches in a Group and just put the Group on your sitemap with the Group element. However, this means that your Switches will only use their default settings and you have no control over their order or customizations (e.g. many times one wants to put a Switch on their sitemap as a Text so it can’t be edited, which is impossible to do if you use Group in this way.

In Rules see:

And realize that the postUpdate and sendCommand actions will take a name of an Item as the first argument so if you can construct the name of the Item programatically in your rule you can send it commands or post updates to it.


Thank you very much for even giving me the time of day Rich, I see you are a major guru here. I’m very new to this and looked at your examples they are excellent! I see in your first example you update individual items status via group status by looping over them, very cool. Unfortunately then I realized I asked the wrong questions. I’m still getting comfortable with the terms (i haven’t even created a single rule yet!). It’s the description I need to dynamically update… for example:

String  plug1_name      "[%s]"          {snmp="<[]"}
Switch plug1   "Strip 1 Outlet 1"     {snmp="<[IP_address:public:OID_VALUE:60:MAP(] >[ON:IP_address:private:OID_VALUE:1] >[OFF:IP_address:private:OID_VALUE:0]"}

Instead of “Strip 1 Outlet 1”, I want this description to be updated from the string value received by item plug1_name which is item-type string (I’m sorry for the confusion). This would be great, because I was able to configure Alexa to turn on and off these switches by voice command via plugin, which uses the string value for identification. Saying “Alexa turn on ECM Storage array” is better than “Strip 1 Outlet X”. I could manually set them, but but would be neat this way.

Unfortunately, you will have to manually set the labels. There is no way to set the label from a Rule like you are asking.

Thanks for much for the info, it’s not too terrible to update, I thought thought it would be neat if the Amazon Alexa would learn the names dynamically from snmp. Unfortunately another issue has come up, I recently updated ubuntu and now my sitemap will not load, giving the errors below. I don’t think the configurations or sitemap has changed, i think perhaps only the packages, odd, any ideas anyone? Did the path’s or anything change?

openHAB 2.1.0 - release build -
Linux mega-server 3.13.0-24-generic #47-Ubuntu SMP Fri May 2 23:30:00 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux

java -version
openjdk version "1.8.0_131"
OpenJDK Runtime Environment (build 1.8.0_131-8u131-b11-0ubuntu1.16.10.2-b11)
OpenJDK 64-Bit Server VM (build 25.131-b11, mixed mode)


Problem accessing /classicui/app. Reason:

    Server Error

Caused by:

javax.servlet.ServletException: Sitemap 'default' could not be found
	at org.eclipse.smarthome.ui.classic.internal.servlet.WebAppServlet.service(
	at org.eclipse.jetty.servlet.ServletHolder.handle(
	at org.eclipse.jetty.servlet.ServletHandler.doHandle(
	at org.ops4j.pax.web.service.jetty.internal.HttpServiceServletHandler.doHandle(
	at org.eclipse.jetty.server.handler.ScopedHandler.handle(
	at org.eclipse.jetty.server.session.SessionHandler.doHandle(
	at org.eclipse.jetty.server.handler.ContextHandler.doHandle(
	at org.ops4j.pax.web.service.jetty.internal.HttpServiceContext.doHandle(
	at org.eclipse.jetty.servlet.ServletHandler.doScope(
	at org.eclipse.jetty.server.session.SessionHandler.doScope(
	at org.eclipse.jetty.server.handler.ContextHandler.doScope(
	at org.eclipse.jetty.server.handler.ScopedHandler.handle(
	at org.ops4j.pax.web.service.jetty.internal.JettyServerHandlerCollection.handle(
	at org.eclipse.jetty.server.handler.HandlerWrapper.handle(
	at org.eclipse.jetty.server.Server.handle(
	at org.eclipse.jetty.server.HttpChannel.handle(
	at org.eclipse.jetty.server.HttpConnection.onFillable(
	at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(
	at org.eclipse.jetty.util.thread.QueuedThreadPool$
Caused by: org.eclipse.smarthome.ui.classic.render.RenderException: Sitemap 'default' could not be found
	at org.eclipse.smarthome.ui.classic.internal.servlet.WebAppServlet.service(
	... 21 more

Stop openHAB.

Run the script (maybe it is in the openHAB runtime folder (I think it is in /usr/local/openhab2/bin but I could be wildly wrong, I run in Docker so don’t have this script).

Alternatively, you can just delete the contents of /var/lib/openhab2/cache and /var/lib/openhab2/tmp and then restart.

See if that changes anything.

Also, check the file permissions on everything in your /etc/openhab2 folder and make sure the openhab user can read them.


After some troubleshooting looks like the issue was with the sitemap. I had the syntax:
Text item=“strip_1” label=“strip 1” {

and this was causing it to break. If I remove the " " around the item name it works fine. Not sure at what point they even got there, but for anyone else who comes to this error it’s definitely worth trying a simple syntax sitemap for QC. I was thinking it was a java or package issue. Thank you very much rlkoshak! you’re seriously awesome!