Full dimmer channel

Tags: #<Tag:0x00007f617fcc48f8>

Hello community!

By definition the DimmerItem accepts the following data types and commands:
acceptedDataTypes.add(OnOffType.class);
acceptedDataTypes.add(PercentType.class);
acceptedDataTypes.add(UnDefType.class);

acceptedCommandTypes.add(OnOffType.class);
acceptedCommandTypes.add(IncreaseDecreaseType.class);
acceptedCommandTypes.add(PercentType.class);

How is it possible to define a dimmer channel that supports all these commands ??? The channel that I have defined so far, only supports PercentType

Thanks for the help!!

BR,
Randy

Are you writing a binding?

Hi @rossko57,
Yes, we are currently creating an openHAB binding. We have a Dimmer device, and we want to create a channel that supports all types of commands

You can just check for the type of the incoming command, and handle it as appropriate. Here is a simplified example:

    @Override
    public void handleCommand(ChannelUID channelUID, Command command) {
        if (channelUID.getId().equals(CHANNEL_LIGHTLEVEL)) {
            if (command instanceof Number) {
                int level = ((Number) command).intValue();
                // Send the percent level to your dimmer
            } else if (command.equals(OnOffType.ON)) {
                // Send on command to your dimmer
            } else if (command.equals(OnOffType.OFF)) {
                // Send off command to your dimmer
            }
        }
    }

For a full example check out the DimmerHandler class in the Lutron binding:

1 Like