I have a slider that shows the numbers from 0 to 254. Instead, I want the slider to display 0-100%
I tried to use javascript transform, but that has no effect on the number format on this slider. In know the transform works, because if I use a “Default” item instead of a Slider item it works.
Sorry, but I can really not seem to figure out how to define a Dimmer item. I have been looking through Items | openHAB and the forum, but it is hard to find a code example.
So I have tried the following things definition.
Thing mqtt:topic:robbDimmer_ff_masterbedroom_center2WL "Switch FF Master Bedroom Main" (mqtt:broker:MosquittoMqttBroker) {
Channels:
Type switch : state "State" [ stateTopic = "zigbee2mqtt/robbDimmer_ff_masterbedroom_center2WL/state", commandTopic = "zigbee2mqtt/robbDimmer_ff_masterbedroom_center2WL/set", formatBeforePublish="{ \"state\": \"%s\" }", on="ON", off="OFF" ]
Type number : brightness "Brightness" [ stateTopic = "zigbee2mqtt/robbDimmer_ff_masterbedroom_center2WL/brightness", commandTopic = "zigbee2mqtt/robbDimmer_ff_masterbedroom_center2WL/set", formatBeforePublish="{ \"brightness\": %s }", min=0, max=254 ]
Type number : linkquality "Link Quality" [ stateTopic = "zigbee2mqtt/robbDimmer_ff_masterbedroom_center2WL/linkquality" ]
}
So, I get the following error. And how do I link the Dimmer item to both the the switch and the brightness channel?
2023-09-05 12:16:00.674 [ERROR] [nal.common.AbstractInvocationHandler] - An error occurred while calling method 'QueryablePersistenceService.query()' on 'org.openhab.persistence.rrd4j.internal.RRD4jPersistenceService@1fe595c0': Value must be between 0 and 100
And plenty of warnings like:
2023-09-05 12:24:47.148 [WARN ] [transport.mqtt.internal.Subscription] - A subscriber of type 'class org.openhab.binding.mqtt.generic.ChannelState' failed to process message '38' to topic 'zigbee2mqtt/robbDimmer_ff_masterbedroom_center2WL/brightness'.
At least, I got it partly solved → you should use Type dimmer in the Things definition.
The slider works now really nice (and it is easier than the transformation)
Linking the dimmer item to a switch item in the sitemap does not work correctly. It shows the state and the percentage. But as soon as you make a change with the slider, the state shows OFF (which it is not) → so I keep the original switch item.