I have item that send command as a number 1-4 and I’m trying to set it in a widget,
I managed to set command 1-2.
My question is if it is possible to set it to send also 3 and more…
This is how it looks to me:
For me toggle is like fliping a coin. You only have two options, how (even without any constraints from openhab) would you like to toggle four options?
Maybe you want to iterate through your options? E.g. clicking the button once will change from 1 to 2, clicking it again will change the state from 2 to 3, etc?
In OH terms, you want to send the item a command, but the command you want to send is determined by the current state of the item.
To translate that to a widget, you want the command action, but you need an expression for the actionCommand that includes takes includes the item’s current state.
The items state is a number from 1 to 4. The expression ([0,2,3,4,1])[items[props.item_iterations].state] defines an array with 5 elements (because JS arrays are zero-indexed those elements are indexed 0 to 4) and then returns the element from this array that based on the current state of the item. We don’t care about the 0th element because the state of the item will never be 0, so we just set that to any old placeholder, in this case 0. But when the state of the item is 1 we want to return 2 as the command , so the element in the 1 position in the array is 2. Likewise for elements 2 and 3, but when the state of the item is 4 we want to wrap back around to 1.