Switch with multi mappings

Hi all,
is there a way in HABPanel to implement a switch that has multiple mappings, like 4 or 5 states ? i can see that in the new update of the button you can switch between 2 alternatives but what if i have more ?

the only solution i can find is to create multiple buttons linked to same item and configure each to send only one state, the problem is it takes a large space of the dashboard and it is not dynamic, which means whenever i add other states to the switch item i will have to go and modify all my dashboards
i hope there is a better solution here :slight_smile:

If I understand what you want, I would suggest a template widget, and use ng-if to display a single switch based on the state. I just posted an example in another thread, but I’ll repeat it here:

<div ng-if="itemValue('Back_Porch_Light')=='OFF'">
  <button class="btn btn-lg" style="color: black" ng-click="sendCmd('Back_Porch_Light', 'ON')">
    <i class="glyphicon glyphicon-menu-down"></i>
  </button>
</div>

<div ng-if="itemValue('Back_Porch_Light')=='ON'">
  <button class="btn btn-lg" ng-click="sendCmd('Back_Porch_Light', 'OFF')">
    <i class="glyphicon glyphicon-menu-up"></i>
  </button>
</div>

This example will show a single button, based on 2 states for a switch. In this example, the switch is either ‘ON’ or ‘OFF’. When you click the button that is shown, it will send the opposite command. (If it is OFF, clicking will send ‘ON’, and the widget will get re-drawn with just a single button that can send ‘OFF’)

Each button can only send 1 command, but lets say you had a HIGH, MEDIUM, LOW, and OFF list of choices. You could do something where if the state if off, clicking would set it to ‘HIGH’, if it is high, clicking would change to MEDIUM, etc.

Another choice is to use a dropdown, if you want to select from a list. Take a look at the template widget tutorial thread; There is an example there of how to create a dropdown list of choices and tie that to a button.

2 Likes

@Signal11 thank you so much for the hep :slight_smile: much appreciated

It seems this code doesn’t work for me, I just simply copied and pasted into my template widget but all I got was a blank, black-color template, pls help

That example is based on my system. You will have to change it to use the name of an item in your item.

I have an item called “Back_Porch_Light”, that is a WeMO switch used to control a light. If you do not have an item called “Back_Porch_Light”, that code will never display anything. (The itemValue() function will return NULL if the specified item does not exist.)

For more information, and examples, check the template widget thread here.