Channel with type "Button"

Is there a way to create channel with type Button? I’m not interested with Switch, because it has a state that I don’t need.

My use case is: User press button and my ThingHandler sends stateless message to REST server. There is no way for channel to have ON/OFF state like in Switch.

channel of type String with “command states”. Those are rendered as buttons

Hi @magx2!

You can also have a look at the DynamicCommandDescriptionProvider implemented a few months ago: https://github.com/openhab/openhab-core/pull/540

Although, as David has told you, you still have to model the channel as a stateful channel :wink:

Create a switch with the expire binding

Switch Button “Button” { expire=“1s, state=OFF” }

I’ve tried to declare channel like this:

<channel-type id="toggle-gate-channel">
	<item-type>String</item-type>
	<label>Open/Close Gate</label>
	<state>
		<options>
			<option value="PRESSED">PRESSED</option>
		</options>
	</state>
</channel-type>

but I just got drop down list

You need:

		<command>
			<options>
				<option value="NONE">None</option>
				<option value="SELECT">Alert</option>
				<option value="LSELECT">Long Alert</option>
			</options>
		</command>

Thanks! I can to find this in documentation. Is this some kind of secret feature?

This feature was added in February, after eclipse smarthome was reintegrated into openHAB.
No company is backing core development anymore which results in new features being not documented :confused:

I started to rewrite the documentation, but also did not yet had time add this detail.
There were so many other features not yet documented (like ThingActions, Thing specific discovery, and many more).

Hallo @magx2,
I’m very interested, can you better explain how to use it in java?

        <command>
			<options>
				<option value="NONE">None</option>
				<option value="SELECT">Alert</option>
				<option value="LSELECT">Long Alert</option>
			</options>
		</command>

Hi, David,
I’m interested in this implementation.
Is it only for the OH 2.5 version?
I can’t find any binding that uses it.
Where can I find documentation?

The command options feature was introduced with OH 2.4. No binding has picked it up, because it was not documented. It should be now (roughly) in the binding developer doc.