Button not linked to any item

Hello,

I’,m using a python script to monitor all my devices state via the REST api. I would like to know if it’s possible to add a (multiple) button(s) for instance in a sitemap to allow me to get the status of this button (software, not hardware) allowing me to question the rest api and do some actions in my python script depending of the state of the button. The button is not linked to any item, it’s only a “software” button…

I don’t know if I was clear enough, but if so, how can I do that ? Do I have to create an item in the “item” folder ?

Thanks in advance for your help :slight_smile:

Yes
A “Button” is basically a Switch that sends a predefined command when pressed.

Example Item:

Switch	Robo500		"Robo 500"	<siren>	(gESP)	[ "Lighting" ]	{mqtt=">[HomeR:openhab/out/Robo500/command:command:ON:default]", autoupdate="false"}

Example Sitemap:

Switch item=Robo500 mappings=[ON="GO!"]

Result:
image

1 Like

But will I be able to get the status of this button via the REST API ? because I don’t want to do any action in OH2, just to update this state and get it from the REST API. Do you have any documentation to know how to write the example you gave ? (what goes where )

The Item that you will define will have a State (ON or OFF for a Switch Item type)
You will be able to obtain that state from the REST API.
Keep in mind that if you use the example above, the Switch Item will always have the State: ON (since when you press it on your sitemap, it will send only the ON command to the Switch.
This item does not have to be bound to any binding. It can be a software only “button” in OH2 without any connection to any external system.

To read more on Items and their configurations, see: http://docs.openhab.org/configuration/items.html

1 Like

Thank you very much for your amazing example and answer. That was fast and perfect :slight_smile: will test that and give a feedback here if it’s working .

Thanks again

1 Like

A simpler example (for a Switch without any binding used) is:

Example Item:

Switch Robo500 "Robo 500"

Example Sitemap:

Switch item=Robo500 mappings=[ON="GO!"]

The Sitemap entry will make the Switch appear as a “Button” :slight_smile:
Keep in mind that it’s basically a Switch with a state (there is no “Button” Item Type in OH2)

1 Like

Even better for the usage I want :slight_smile:

1 Like

It’s working like a charm, thank you :stuck_out_tongue:

1 Like

Since you provided a premium support, I need your help for something similar : is it possible to have a SetPoint not linked to an item. I would like to have one to use it in my python script to set a level threshold to send me a push notification on my mobile if the temperature on one of my devices drop below a certain amount…

I tried to set an Item like this : Setpoint TempAlert “Temperature Threshold”

Then in the sitemap, lilke this : Setpoint label=“Temperature threshold [%.1f °C]” item=Temp minValue=4.5 maxValue=30 step=0.5

The problem is that since it’s not linked to an item, I don’t get any value saved in the variable read by %.1f… Is there a workaround this ?

Thanks in advance :slight_smile:

Edit : I tried to find info in the documentation but I was not able to find anything helpful

You cannot have ANYTHING on your sitemap not mapped to an Item except for a Frame. You have to create an Item to receive the value. As with the above, you don’t have to have this Item bound to anything.

I created an Item, but how does OH2 store the value into the item ?

It keeps the Item State internally in some OSGi tables (or something similar :slight_smile: I don’t remember now)

Additional note: The State does not survive a restart of the OH2 service. To bring back the State after a OH2 service restart, you need to use a Persistence Service with a restoreOnStartup strategy. Read more on Persistence here: http://docs.openhab.org/configuration/persistence.html

There is no Setpoint Item type. You can use a Number type for your Item.
Then, in your Sitemap you will display it as a Setpoint.
When you will change the value of the Setpoint, openHAB2 will store the new value as the State of the Number Item.
(http://docs.openhab.org/configuration/items.html#type & http://docs.openhab.org/configuration/sitemaps.html#element-type-setpoint)

1 Like

Ouch thanks I was completely off again :slight_smile: you’re the man Dim

1 Like

If you need your items to retain its value even through a reboot, you will a persistance engine.
http://docs.openhab.org/configuration/persistence.html

Here is guide to setup mysql persistance (which I personally recomend)

Edit: sorry didnt see this was already answered.