Hi! I’m making a series of widgets using Scriptable, from iOS. Today I have finished my first widget, to show 3 different temperatures.
The widget only needs to be configured with the username and password, to obtain the data. Obviously it can be edited to anyone’s whim, I hope this helps.
I configured the widget in such a way that I could get the data, via myopenhab.org to be able to use it anywhere.
In the next few days I will be uploading more widgets.
Hi @sebasanblas
Thank you for the widget.
Will try to set it up with my OH installation.
I was already wondering why there are no widgets for openhab available… but now this changes. Looking forward to test the ones you will release
Unfortunately my programming skills are nearly zero, so I am not able the build my own widgets.
Yes! absolutely yes it can! Honestly, I don’t have much knowledge either, but after a couple of attempts and other widgets, I have learned a few things.
Some useful things:
I have not managed to interact with OpenHAB items directly but I will keep trying
From my 3 temperature widget, delete everything related to item 2 and 3. Modify a single item (item 1) to your liking to see the changes little by little.
Use the images (icons) of SF Symbols (Here you can find the names to make changes → GitHub)
As I said, my knowledge is few but let’s stay in touch with any questions
Exactly! Please, check in Configuration → openHAB Cloud, if the Base URL is myopenhab.org as seen in my image. If not, edit the widget code with the url you use. Generally the port that openhab uses to communicate is 443.
Additionally, thanks to your capture, I discovered that I have not set to truncate decimals, among other things. Please check GitHub again for improvements. Thank you very much for helping me improve the widget!
What’s about the encoding? Do I need to encode only the @ in username or do I need to encode the password, too? And if yes which part of it? The complete password or only my special chars in it?
Another question, may you adapt the input match so that I am also able to receive the state of contact sensors and switches?
If I change the
…match(/[0-9.]+/g)[0];
to
…match(/[ON-OFF.]+/g)[0];
it shows me the state of a switch.
I bet changing the code like this isn‘t correct, so maybe you can do it the correct way
Yes, you need to encode all the username and password BUT… (Thanks again to you) I updated the widget so that you simply need to put your username and password normally and the code will encode for you, forget about character encoding and headache
Please, try with the new code and tell me! BTW first try to conect with the browser so we can rule out future problems.
If you want to test with the browser first, I create a script for you that will encode to get the URL you should use. Add a new script file in Scriptable and paste this
// Define your user and passwork normally
// ⬇️
var user = 'hi+dirk#dirk@openhab.com'
var password = 'super,?pass'
// ⬆️
// Magic..
var user_tobrowser = encodeURIComponent(user)
var pass_to_browser = encodeURIComponent(password)
console.log('User to use in browser: ' + user_tobrowser)
console.log('Password to use in browser: ' + pass_to_browser)
Once executed, in the scriptable log you will see your username and encrypted password that you will place in your browser
Yeah You guessed my next widget … honestly my idea was to use icons instead of text to know the status, for example: “light” → lamp icon, with colors. This weekend, I’ll move on with that
Another idea of mine … I developed a group of services and I would like to know its status on my iphone, there will also be a new widget with dynamic icons.
Although I think the idea is correct, I do not know if the code is correct but leave me a few days, maybe hours (I am impulsive) and we will solve it.
Well I think this is the longest answer in the community… I think I deserve a Simpsons episode! Regards
Ok… there is some success. This was the issue: I got a ! in my password, so I converted this to %21. But it looks like this was wrong. No need to encode the ! .
If I encode the user and password with your script the connection via browser works. BUT I need to log in. There is a pop up log in window. Looks like the credentials are not parsed to the site. Afer I logged in the REST works.
The idea about your upcoming widgets sounds great. I got a lot of items in openhab, so maybe you can help me some day to create a layot where all my items fit into different widgets. I would use the largest iOS widget size, so the layout would be total different.
Edit: based on this page URL ENCODING change unnecessary characters like letters and numbers and the url is still functional. I’m a bit confused. What happens when you put the credentials in the widget? Works?
Doesn’t work if I use the credentials in the Script.
I changed the myopenhab password so that there a no special chars in it and no encoding needed… still opens the pop up for login in Browser.
I used your code and changed it a litte bit to show my power consumption and generating. The icons and text color changes depending on the values. I like it.
Took a while because I am not a coder, but now it is working
Hopefully you will develop more widgets for openhab and Scriptable.