Is it possible to associate more than two commands to a switch item?

I’m trying to send several udp commands to operate an air conditioner, using a switch item with more than two commands

Commands are defined in the item files
Switch ACZN “ACZN” <air_conditioner> (Appliance) {
I also defined the transformations for OFF,T1,T2 in file

Finally I add to my sitemap the
Switch item=ACZN icon=“air_conditioner” mappings=[“OFF”=“OFF”,“T1”=“T1”,“T2”=“T2”]

At start time, the udp binding cannot parse the OFF,T1 and T2 commands.
But in the wiki page it appears that the binding accept more than two commands. Does this mean that the udp binding for a switch only accepts the ON, OFF commands?

Thank you for your attention

Yes, a Switch can only be set to ON or OFF. If you want multiple states, define the item to be a Number in items file and a Switch in sitemap. Never used the UDP binding so not sure how it works, but sending the same command in all cases does not make sense (MAP is usually just used to map values for display, not for commands. I may be mistaken but I don’t think it has an effect the way you’re using it).

1 Like

You could even use a String Item for multiple states. In fact, If using strings in the mapping at the sitemap, you have to use a string item, if using a number item, you have to use numbers in the mapping. the latter can be used to display dynamic icons - no wait, there is no dynamic ventilation icon yet :frowning: but at least, you could, if… so it would be

Number ACZN "ACZN"   (Appliance) { udp=">[*:'MAP('] }


Switch item=ACZN icon="air_conditioner"  mappings=[0="OFF",1="T1",2="T2"]

and a with the commands…

1 Like

Thank you for your prompt responses!
@mstormi The Map in the udp binding is used to define the character string associated with a given command.
I’ve defined the item as suggested but I get the error

org.openhab.model.item.binding.BindingConfigParseException: couldn’t create Command from ‘*’

I’m using OpenHAB 1.8.1 is this important?

Sorry, please try

Number ACZN "ACZN"   (Appliance) { udp=">['MAP('] }


1 Like

Thank you. This one worked flawlessly.

I have another small problen though. When the device receives the UDP packet it gives back another one and the binding tries to map it through the same map file of the commands and it gives an error.
I would simply need a status OK if some answer is received.
If tried to add to the binding
but it gives a lot of errors (no channel available )
How is the return packet treated by the binding?
Thank you

EDIT: Apparently the udp:updatewithresponse=false configuration option does not work: the system always try to update the status with the received packet, no matter what the configuration is.

Regarding to the wiki, it should be

Number ACZN "ACZN"   (Appliance) { udp=">['MAP('], <['MAP(']" }

but I did not try this yet, so… good luck! :wink:

Thank you,
I tried but the response packet still go through the first map, then it goes through the receiving map. I think there may be an issue with the binding. I will try to delve into the sources, even though I’m not a java programmer. I’m wondering if it is worth looking at JS transforms.