Is there already an openhab cli for users? It should allow you to toggle items in openhab and get their state:
$ ohcli get lights
> OFF
$ ohcli set lights ON
> `lights` set to `OFF`
So I am not talking about the karaf console, I am aware of that one, but it is too overpowered for my usecase and way too slow. I am thinking of something lightweight that is only for power end users.
Interesting idea. Have a look at the api explorer first. It helps you compose http request. With tools like curl you can send these requests from the command line.
Usecase is mainly for developers. I spend a lot of time in the terminal and it’s the fastest way to toggle an item. Currently if I want to turn on the lights I either use my phone with openHAB App or I need to go to openhab IP Adress, go to basic ui (I don’t like main UI because it is buggy and too static) and find the item.
For a CLI I would also see if I can implement a auto complete feature that allows you to tab through items.
What’s wrong with Karaf console then ? It cannot be “overpowered” for this task as that clearly requires a lot of flexibility so any proper implementation of yours will likely end up to be pretty similar to that. Please do not reinvent the wheel.
That now is plain wrong. You can setup individual web pages to have right the items you need for your current test case in at most minutes, even elaborated use cases. See those various threads on widgets and start playing with that, you’re gonna need this anyway soon.
And buggy it isn’t (well of course there probably are some bugs but “buggy” would be way different).
you are right. I meant the pregenerated thing with locations and all that, I have played around with custom pages a bit, but I do not really use them so they are not up to date most of the time. Why am I going to need that anytime soon? Also, are there plans to support it on mobile in a more performant way than webview like with sitemaps?
If so you have a problem with your setup but that’s not the same as a buggy UI. It’s usually instantaneous. Auth goes via token and is a one time thing so clearly nothing that will brake you.
Autocompletion is nonsense in GUI context. You could also use the items menu which has a search function if that is what you’re after.
Building another UI (CLI) is really XY problem type “solution”.
10 secs definitely isn’t normal, I’m not even seeing this on my mobile with a mobile (laggy) connect. Focus on finding the reason why MainUI behaves like that on your system, reinstall if needed.
Which you will not need if you have the GUI working.
well thats the whole point . I want a CLI tool to easily control my openhab items, not a GUI. (not like I don’t need a GUI but only on mobile and I find basicUI a lot more convenient to use there.)
Please note that he asked for a non-webview implementation … which isn’t present and probably never will be, because with the main UI widgets there’s no intermediäre UI description like with sitemaps.
Here’s a simple Bash script that I use to get and send commands to the API:
#!/bin/bash
API="https://openhab.example.com/rest/items"
METHOD=$1
ITEM=$2
STATE=$3
if [ $METHOD == "PUT" ]; then
echo -n $STATE | http PUT $API/$ITEM/state Content-Type:text/plain
elif [ $METHOD == "POST" ]; then
echo -n $STATE | http POST $API/$ITEM Content-Type:text/plain
elif [ $METHOD == "GET" ]; then
http -b GET $API/$ITEM/state Content-Type:text/plain
elif [ $METHOD == "TOGGLE" ]; then
CURRENT=`curl $API/$ITEM/state 2>/dev/null`
if [ "$CURRENT" == "Off" ]; then
$0 POST $ITEM $STATE
elif [ "$CURRENT" == "OFF" ]; then
$0 POST $ITEM ON
elif [ "$CURRENT" == "Cool" ]; then
$0 POST $ITEM Off
elif [ "$CURRENT" == "Heat" ]; then
$0 POST $ITEM Off
elif [ "$CURRENT" == "0" ]; then
$0 POST $ITEM 100
else
$0 POST $ITEM OFF
fi
fi
It uses httpie and curl at the moment. Modifying it to use curl exclusively should be pretty straightforward.
The GET, POST, and PUT methods are simple shortcuts to the REST API. The TOGGLE method gets the current state and guesses the opposite state, with a default state if the current state is Off.
Example calls:
# Set the master bedroom ceiling light to 25%
openhab POST MBR_CeilingLight 25
# Toggle an air filter
openhab TOGGLE LIV_AirFilter
# Show when my phone last checked in
openhab GET LOC_Steve_Phone_LastSeen
# Toggle a mini-split unit in winter (default to Heat)
openhab TOGGLE MBR_HVAC_Mode Heat
thanks, that is almost what I was looking for. I will use this for now but maybe build a cli in go or something with more advanced features like autocomplete, aliases and search