Man/Auto mode switch

The sitemap widgets for a Switch are the basic switch icon and toggle on/off slider.

How do I make , on my sitemap displayed on a mobile via the OH android app, the nice little switch block colour on/off boxes. Or perhaps a pushbutton label that toggles between Auto and Manual changing the colour of the infill to green of Auto and Red for Manual? There’s a lot of options here I guess so I’m looking for some good advice on design pattern for this solution, I’ll work out the code but I really need help with the design decision.



Here is an example for one I use to control the time period of a chart that is shown.

Switch item=ChartVisibility mappings=[h=Hour,d=Day,w=Week,M=Month,y=Year]


That’s a little more challenging. I do this using the visibility tag.

		Switch item=aGarageOpener1 icon="garagedoorclosed" mappings=[ON=Open]  visibility=[vGarageOpener1 == CLOSED, vGarageOpener1 == UNDEF ]
		Switch item=aGarageOpener1 icon="garagedooropen"   mappings=[ON=Close] visibility=[vGarageOpener1 == OPEN]
		Switch item=aGarageOpener2 icon="garagedoorclosed" mappings=[ON=Open]  visibility=[vGarageOpener2 == CLOSED, vGarageOpener2 == UNDEF ]
		Switch item=aGarageOpener2 icon="garagedooropen"   mappings=[ON=Close] visibility=[vGarageOpener2 == OPEN]

Note that the color of the button is determined by the state of the Item. All are gray and the one that corresponds with the Item’s state will be highlighted. The color of the highlight depends on the theme you are using in BasicUI/Android/iOS apps.

But the above will go to the garage door open icon and change the name of the button to CLOSE when the door is OPEN and back when the door is CLOSED.

you’ve done it again ritch

is there ANYTHING this guy doesn’t know :+1::+1::+1::laughing:

@rlkoshak how do I set a default / initial value in the sitemap or item, cannot see that in the docs?
I have a Switch item linked to a Binary Switch class channel (On/OFF) what happens if the swtich mappings include On,Off and AUTO - sending AUTO to a binary switch channel? How do i map the sitemap Switch (On, Off, Auto) to the Switch item (ON,OFF)? I use Auto in a rule to send On or Off to the item .


Switch      item=i_HVAC_CH_Switch               label="Central heating On/Off"  mappings=[default=OFF,ON=ON,AUTO=AUTO]


Switch	i_HVAC_CH_Switch "CH On/Off" <switch>	(g_HVAC, g_HVAC_Switch)	{channel = "zwave:4849599d:t_Zcontroller:node3:swtich_binary2"} 

I think I may need a proxy String type item for the mapping to the sitemap Switch ? But how to set default to “OFF”?

I’m not sure that it’s possible to define a default value with in a sitemap. You could create a rule to update the value when your system starts. Do you have any persistence configured?

Example first-use rule.

// Initialize
rule "Light timings init"
    System started
          // only need populating before first use
          // usually get restore-on-startup
    if (vnm_Tperim.state == NULL) { vnm_Tperim.postUpdate(15) }

If you later choose to persist and restore this Item, it should get restored before the rule runs and not get initialized.

You can’t.

Yes. Or a Number (it’s easy to map 0, 1, 2 etc. to text for display)

1 Like

sorted it , thanks , used a proxy item to hold the 3 way state and a rule to check for changes to the proxy state.


I have a heating icon on the sitemap setpoint when 3 way switch in ON, the range of values from 10 to 25C , but the heating icon requires 0-100 probably, so can I scale the setpoint in the sitemap but leave its inherent value unscaled so that my rules dont need chaning.?

Sorted, I will use visibility attribute on the sitemap widget and map these to the same item but different icons.

It’s a lot easier to make a custom icon set.

1 Like

yep, done, thanks

For more detail on rossko57’s answer, there’s a DP for that: Design Pattern: Encoding and Accessing Values in Rules, Approach 2.

I’ve also some approaches that work only with Scripted Automation, not Rules DSL. You can put a default value into the Item metadata and have a system started Rule that reads that metadata and updates the Item with it’s value. My Ephemeris Time of Day implementation uses this approach to initialize some Items to define static start times.

The heating icon uses ON and OFF only. Not a range. There is no representation in the icon for “AUTO”.

@rlkoshak is there any way to use the classic iconset , so that the fire icon is “on” if the sitemap proxy item switch widget (ON, OFF, AUTO) = ON or AUTO.
The fire icon correctly “turns on” when switch = ON, and off when switch = OFF, as per your assertion above, but can I refer to the classic icon in my sitemap mapping , because it seems they are enclosed in .jar files under the /var/lib/openhab2 tree, and you know how much I dislike anything with jar in :slight_smile: :slight_smile:

EDIT: Sorry, the sitemap widget:

Switch 		item=i_HVAC_CH_Switch_Proxy			label="Central heating mode" 			icon="fire"		mappings=[ON="ON",OFF="OFF",AUTO="AUTO"] 

There are no icons under my $OPENHAB_CONF/icons/classic/ , guess they are embedded somewhere?

The icon chosen is based on the state of the Item. Period. If you need to control the icon based on any other states you need to create your own set of dynamic icons that work with the states of your Items. You cannot base the icon on the label or any other transformation of the Item’s state.

Jar files are just zip files and can be opened and manipulated using any zip program. So you can extract them using gunzip or your zip tool of choice, or download them from or from your actual sitemap (right click and save image as) or find your own icons on the web to use. There are some great icon sets freely available for non-commercial use.

1 Like

purfect , as always , thanks @rlkoshak … jeez, if you were only paid for supporting this platform eh :roll_eyes: :grinning:)

well @rlkoshak it’s a bit tricky this one in the sitemap , maybe it’s not possible…

i have the switch widget mapped to ON, OFF, AUTO using a proxy item moding a heating boiler Swich Item (on / off) Left to the widget is the :fire: icon.
I want fire on if switch is ON and off if switch OFF , okay easy.

So if i use custom icon solution, and when switch is in AUTO mode, how do i set fire icon on only if the boiler switch is On.

Reason: the icon shows off a demand for water is set, it can be on or off in AUTO because a rule is comparing room stat with desired temp and toggling the boiler on/off accordingly in AUTO.


Switch item=i_HVAC_CH_Switch_Proxy label="Central heating mode" icon="fire-on" mappings=[ON="ON",OFF="OFF",AUTO="AUTO"] visibility=BoilerItem==ON]

Switch item=i_HVAC_CH_Switch_Proxy label="Central heating mode" icon="fire-off" mappings=[ON="ON",OFF="OFF",AUTO="AUTO"] visibility=BoilerItem==OFF]

1 Like

For another example of Hans-Jörg’s example see my post above for the Garage Door openers. But note that I had to create my own copies of the icons. I never was able to get it to work with the built icons. I’ve also not looked at it in years, maybe it works better now.

1 Like

I am using it for displaying different battery icons using standard icon-set, working fine.

always a clever sod thinking out of the box lol :+1::grin:

I’m not convinced that works in all of the different sitemap based UIs, since it “breaks the rules” by specifying a hyphen in the target icon name. That part is supposed to be worked out by the icon picker service, and if it goes wrong it would be looking for fire-on-on.svg or something. Maybe when that failed it fall back to a default fire-on.svg and appear to work after all.
I don’t know, Im sure this used to be trouble.

The example given with fire-on/fire-off icon is exactly what I use for displaying my boiler state and it is working absolutely fine with basic and classic UI.