Switch with values other than on off

Is it possible to have an item with two values that I set? It I have a stereo that can be set to either a tuner or CD setting, so want a simple either.or option presented to the user.

How can I achieve this?

You can use a String item in your .items file, and then use a Switch widget in your sitemap with mappings, so the user can click on buttons which results in commands sent to the String item.

// item
String StereoMode

// sitemap
Switch item=StereoMode mappings=[CD=CD, Tuner=Tuner]

// rule (optional)
rule SetStereoMode
  Item StereoMode received command
  logInfo("StereoMode", receivedCommand.toString)

Ahh, nice. Think I found a selector item. But it translated to values. With yours I assume the Cd and Tuner could be passed to the sendHttpPost command?

Is that possible to put SendHttpPost(“http://URL/command” + received variable)

Yes! See the Actions wiki page. Something like:

rule SetStereoMode
  Item StereoMode received command
  logInfo("StereoMode", "Setting mode " + receivedCommand)
  sendHttpPostRequest("http://my.stereo/setMode?mode=" + receivedCommand)

Make sure the URL target expects HTTP POST vs. GET vs. PUT, etc.

Looks much cleaner. I think with this I could use possibly get down to one rule with the received command if there was a way of exposing the item making the call?

AFAIK, there is no good way to determine which item received the command in a rule such as

rule MultipleItems
  Item A received command or
  Item B received command or
  Item C received command
  // we have a receivedCommand variable, but no "clean" way to
  // determine if it was item A, B or C that received it

I could be wrong, though. I think having separate rules is the way to go.

OK. At least the rules would be pretty small/simple. Thanks for all the help.

Very cool to be able to turn on and off my stereo which is in another room via my phone. I should look at a audio sensor so I can get its state, as if it’s turned off from the radio, the app doesn’t know what state it’s in.

You could use the HTTP binding instead of a rule to achieve the same thing as the rule with sendHttpGetRequest(...).

Is there an HTTP call you can make that returns its current mode? If so, you could add the HTTP binding to the item with:


and if you can extract/transform to a string in your mappings, then it will update the state of the item to be the string at some refresh interval in milliseconds.

No it’s a totally non smart Yamaha Receiver (rx-v540). I have a raspberry pi connected to it via the line in for streaming - and htis has a usb-uirt IR blaster for sending a IR code to the receiver to control it.

I just had a look at it if there was something that a raspberry pi could attach to to detect a signal. Seems there an AC port on the back that would be 240v, or potentially a spare line out point for detecting an audio signal. Unless the aeril connections coul dbe used somehow…but I’d imagine they’d lose power when it’s switched from tuner to CD

If you put a power metering device on its AC supply, you could tell whether it’s drawing differing Watt levels when it’s amplifying vs. when it isn’t (if you use Z-Wave, this device for example). A rule could be triggered on different wattages, and set the state of a Switch or String item accordingly.