Convert results form String to Switch item

Hi All,

I am currently migrating from Openhab 1.8 to 2.0b5. In my 1.8 setup, I had a script that was executed using the exec binding. The script returned either ON or OFF. Thus, I assigned a Switch item-type for the item.

In Openhab 2, I can only assign a (managed) String item to the output of the exec binding. However, this is not very helpful. If I adding a switch item using an .items-file, the Switch will not change neither to On nor to Off.

String is set to On or Off:
String Andre_BT "Andre Handy BT" (Anwesenheit) { channel="exec:command:d08c85f0:output" }

but not using:
Switch Andre_BT "Andre Handy BT" (Anwesenheit) { channel="exec:command:d08c85f0:output" }

Has anyone an idea how I could handle this issue (preferably without using a rule)?

Kind regards

There’s a long related discussion here:

You can use a String item and associate it with a Switch item in your site map. The “ON” and “OFF” string states will update the visual Switch state (at least in the Basic UI).

Steve, do you have an opinion as to how the Exec 2.0 binding could become as functional as the Exec 1.9 binding without requiring String items, proxy items or rules? I was told that there are no binding API problems preventing this, so WDYT is the root cause of the usability issues? Thanks!

In the other topic, we’ve been able to simplify Exec switch support to a single item bound to two channels. However, the item must be a String item that is included in the sitemap as a Switch widget. I’m not an expert on OH2, but apparently the String item constraint is specified in the Exec input channel type’s declaration in thing-types.xml. Ideally, any item type could be supported and the item command’s string represention would be used to format the external command string. If I understood correctly what @kgoderis tells me, OH2 only allows a single channel item type (no sets or wildcards). That seems to be the root cause of the String item requirement. Otherwise, the binding would need to define a channel for each item type.

Thank you, Steve, for your detailed reply. At least one can continue using the 1.x bindings until usability is improved. Much appreciated.

Thank you for your quick answers!

I think I get it managed if only the sitemap uses a switch widget. However, it would be great if Switch type would be natively supported by the binding.

I would also appreciate if different types could be used in the future!!