Preset dim level buttons to sitemap

I would like to have buttons as well as a slider in my sitemap to control my dimmers. For example I almost always go either 10%, 25%, 50%, 90% or full bright. Is there an “Easy” way do this?

I thought of adding this to my sitemap:
Switch item=LivingRoomLampLevels mappings=[10="10%", 25="25%", 50="50%", 90="90%", 100="Full"]
and visually that kinda works.

I add this to my items file:
Switch LivingRoomLampLevels "Levels"

and then I guess I need custom rules to accept the button push evens and make these into commands. I found the documentation to be very lacking in this area. So my question(s) are:

  1. is this the best way to do this?
  2. What would a rule look like to accept events of LivingRoomLampLevels
  3. Can I make a custom UI element to do this instead, that perhaps I can reuse? I want this functionality with all my dimmers.

Thanks in advance!

I did kind of get this working like this:
rule "Living Room Lamp Level" when Item LivingRoomLampLevels received command then logDebug("delmar.rules","Got command:" + receivedCommand as DecimalType) sendCommand(LivingRoomLamp, receivedCommand as DecimalType) end

but it feels like a dirty hack, and I would have to repeat this several times. Is there a better way?

Hi Kevin!

It’s even easier than that! Have a look at this sitemap element definition:

Switch item=LivingRoomLamp mappings=[10=“10%”, 25=“25%”, 50=“50%”, 90=“90%”, 100=“Full”]

That’s all you need!

You can use a Switch sitemap element with a mapping configuration linked to a Dimmer item, as long as the command that is sent through the Switch element is accepted by the Dimmer item. In this case, the commands sent to the item are 10, 25, 50, 90 and 100, integer values between 0 and 100, so your LivingRoomLamp item will be able to process them easily.

You are also allowed to add an extra mapping definition like OFF=“OFF” to be able to turn the lamp off using the same sitemap element!

If you have any question don’t hesitate to ask :wink:

Best regards,

Aitor

1 Like

Thanks @riturrioz I’ll try that.

1 Like

Just to correct this input from Aitor for the archival purpose; obviously the wrong quotes were used here, and should be:

mappings=[10=“10%”, 25=“25%”, 50=“50%”, 90=“90%”, 100=“Full”]

Not necessarily the wrong quotes - just didn’t use code fences so when copy/pasting it produces weird results!