Selection Mapping w/ a Scale

I have an issue where my ceiling fans sometimes get set to zero when I open the openhab app on android. I posted about it here. I finally figured out what exactly was causing it, but I am not sure how to remedy it in my sitemap.

I have the following sitemap entry:

Frame label="Master Bedroom" {
  Selection item=MasterBedroomFanLoadLevelStatus label="Fan [SCALE(ceilingFan.scale):%s]" icon="fan_ceiling" mappings=[0=Off, 33=Low, 66=Medium, 100=High]

In my scale file I have this:


The problem is that sometimes, but not often, the value can get set to something outside the range… For example, through a manual method the fan might get set to 20 (which is still low). However, when you load the sitemap and look at it because 20 doesn’t match a known mapping it seems to default to ‘Off’ and then update it into the off position.

Is there a way to properly handle this in the sitemap or do I need to write some rules that force the fan into certain exact values if they are in a range? Or other ideas?

I have been able to fix this by ‘snapping’ to a value in the rules file. Not sure its the best way, but it does solve my problem.

A Rule is one approach and probably the only one to use the mappings like you have.

You could also use a Switch with mappings:

Switch item=MasterBedroomFanLoadLevelStatus label="Fan [SCALE(ceilingFan.scale):%s]" icon="fan_ceiling" mappings=[0=Off, 33=Low, 66=Medium, 100=High]

or a Slider

Slider item=MasterBedroomFanLoadLevelStatus label="Fan [SCALE(ceilingFan.scale):%s]" icon="fan_ceiling" 

or a Setpoint

Setpoint item=MasterBedroomFanLoadLevelStatus label="Fan [SCALE(ceilingFan.scale):%s]" icon="fan_ceiling" minValue=0 maxValue=100 step=33

Does that not mean that a start value of e.g. 20 will get treated as 0, i.e. Off ? And a value of 99 be treated as 66 Medium.

How does this work?
mappings=[0=Off, 5=Low, 45=Medium, 75=High]

Hi Brian,

In another idea for you :

item file :
Dimmer MasterBedroomFanLoadLevelStatus " Fan status [%d]"
String FanStatus

site map file :
Frame label=“Master Bedroom” {
Selection item=FanStatus label=“Fan Status %s” icon=“fan_ceiling” mappings=[OFF=“Off”,LOW=“Low”,MEDIUM=“Medium”, HIGH=“High”]

rule file :
rule "Fan status"
Item FanStatus changed
if (FanStatus.state==OFF) {
if (FanStatus.state==LOW) {
if (FanStatus.state==MEDIUM) {
if (FanStatus.state==HIGH) {

Try it and good luck :slight_smile:

It doesn’t seem to be closest value related. For example, I have seen the fan be set to 55 and it drops to zero when the user interface is loaded.

To close the loop here. I used the following rule to resolve this situation:

rule 'Snap Master Bedroom Fan to preset percentages'
when Item MasterBedroomFanLoadLevelStatus changed
  logInfo("Fan", "Master Bedroom Fan State changed to {}.", MasterBedroomFanLoadLevelStatus.state)
  switch MasterBedroomFanLoadLevelStatus {
  	case MasterBedroomFanLoadLevelStatus.state >0 && MasterBedroomFanLoadLevelStatus.state< 33 : {
  		logInfo("Fan", "Snapping to 33%")
  		sendCommand(MasterBedroomFanLoadLevelStatus, 33)
  	case MasterBedroomFanLoadLevelStatus.state > 33 && MasterBedroomFanLoadLevelStatus.state < 66 : {
  		logInfo("Fan", "Snapping to 66%")
  		sendCommand(MasterBedroomFanLoadLevelStatus, 66)
  	case MasterBedroomFanLoadLevelStatus.state > 66 && MasterBedroomFanLoadLevelStatus.state < 100 : {
  		logInfo("Fan", "Snapping to 100%")
  		sendCommand(MasterBedroomFanLoadLevelStatus, 100)