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

Hi
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) {
udp=">[OFF:192.168.27.34:80:‘MAP(my.map)’],
>[T1:192.168.27.34:80:‘MAP(my.map)’],
>[T2:192.168.27.34:80:‘MAP(my.map)’]"}
I also defined the transformations for OFF,T1,T2 in my.map 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
LionHe

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=">[*:192.168.27.34:80:'MAP(my.map)'] }

and

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

and a my.map 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.
LionHe
EDIT
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=">[192.168.27.34:80:'MAP(my.map)'] }

instead

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
udp="<[192.168.27.34:*:‘REGEX(.*)’]
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=">[192.168.27.34:80:'MAP(my.map)'], <[192.168.27.34:80:'MAP(myresponse.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.