3 Temperatures Widget - Scriptable - iOS

Hi! I’m making a series of widgets using Scriptable, from iOS. Today I have finished my first widget, to show 3 different temperatures.

screenshot

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.

I hope someone finds it useful :slight_smile:

Greetings.

5 Likes

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 :slight_smile:
Unfortunately my programming skills are nearly zero, so I am not able the build my own widgets.

BR
Dirk

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:

  1. I have not managed to interact with OpenHAB items directly but I will keep trying :slight_smile:
  2. 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.
  3. Use the images (icons) of SF Symbols (Here you can find the names to make changes → GitHub)
  4. As I said, my knowledge is few but let’s stay in touch with any questions :wink:

Cheers!

OH 3 ios widgets are a very neat idea! Looking forward to see more

Doesn’t work for me… scriptable shows this error:

2021-04-20 23:57:07: Error: Die Daten konnten nicht gelesen werden, da sie nicht das korrekte Format haben.

In browser it shows this result for item „Ankleide_temp“ :

{“link”:“http://192.168.178.27:8080/rest/items/Ankleide_temp",“state”:"21.019607843137255 °C”,“stateDescription”:{“pattern”:“%.2f %unit%”,“readOnly”:true,“options”:},“editable”:true,“type”:“Number:Temperature”,“name”:“Ankleide_temp”,“label”:“Ankleide”,“category”:“Temperature”,“tags”:[“”,“Temperature”,“Point”,“TemperatureSensor”],“groupNames”:[“Garderobe”]}

Any idea how to fix this?

Edit:

When I change the principal_link to my local IP address, it works. So the problem must be the remote access via myopenhab.

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.

Knowing this, try from your browser to connect to

https://{user of myopenhab.org}:{password of myopenhab.org}@{Base URL}:443/rest/items/Ankleide_temp

Do you see the informatión like with the Local IP?

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!

Connect via browser to the url also doesn’t work.

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 :smile:

Okay, so the problem may be an authentication.

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 :wink:
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 :wink:
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.

Regards Dirk

I think the problem is that the credentials are not correct for the site, so it asks for them again.

If I enter my correct credentials in a private tab …
correct

If I enter my credentials wrong…


I need to enter the credentials again.

So yes, I think it is a problem with the encoding of the username or password.

Look: Encode URL in JavaScript - Stack Overflow

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. :triumph:

1 Like

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 :slight_smile:

Hopefully you will develop more widgets for openhab and Scriptable.

1 Like

Hallo,

It doesn’t work, scriptable shows this error:

2023-08-23 12:16:53: Error on line 111:60: TypeError: undefined is not an object (evaluating ‘(await info_state(input_1)).match’)

Can someone help me please