Can i use my raspberry pi and python to change my basic UI

This might sound stupid but i am pretty bad with openhab and their documents are after 2 days of search not helpfull at all.

the only things i have are:
for items:

Switch LED “LED” { gpio=“pin:20” }
Switch LED2 “LED2” { gpio=“pin:21” }

for sitemap:

sitemap demo label=“test” {

    Switch item=LED icon="light"
	Switch item=LED2 icon="light"

and yes it works, i can turn those leds on/off with openhab basicUI, but that is not what i really need

i need to figure out how to turn them on with python through openhab AND be able to see the changes in the basicUI on my browser. I have searched for about 2 full days and can’t find it at all. I am working at uni for a project and we only have 2 weeks left, please help.

For this you should use the REST API of openHAB:

From Python you will probably want to use one of the commonly used HTTP libraries, e.g. requests, urllib3, etc.

The Basic UI (or one of the other UI’s) are updated with the state of items, regardless of where they are set from (e.g. a UI, a rule, the REST API, etc.) so this part should “just happen”.

although i do understand that the code you find when you open the link is probably what i need, i do not understand what is happening in the code or what part has what purpose. therefore i have no idea what to change so it is fitting with my coding so to speak.

Hmm… I think you may need to read up a bit on HTTP and REST API’s in general (a search on Google should give you loads of sources on this).

Reagrding the “code”, this is really not code in the sense of “a piece of code in some programming language” but rather examples on how to access the REST API using the ‘curl’ command line tool (a pretty standard tool in the Linux OS, but I think it is also availble for the Windows platform).

If you want to know more about this tool, then you can find documentation here:

I think you are right about needing to read up on http and REST API’s. I gues I know what to do this weekend. Thank you for the help :slight_smile:

There is in fact a Python -openhab library that allows you to read items and set them. (via the REST API)
You will find the library here.
Supposedly it is only for openhab 1,but I just tried some stuff with openhab 2 and that works too.
Keep in mind that you after you set an Item with a python command, you also have to send a command to update the state in your openhab UI.
Suppose you have an item called ‘Spotlight’ that you want to turn on from within Python.
then you need to issue the commands:


if you want to query the state, do that like:

‘sl’ is avariable that you have read the specific item into

Also, it is possible to work with the REST api without the before mentioned library.
Suppose your openhab ip=
and you want to switch the item ‘Spotlight’ and or read the item ‘Spotlight’
You can do that as follows:

import requests
requests.put('', 'ON')

g = requests.get('')
data = g.content
print('Spotlight = '+data)
1 Like