iOS Widget for Home Assistant via Scriptable

Hey there,
Does anyone knows a way to set a server in the widget.url = „homeassistant://navigate/…..“ with URI? Or does anyone know a way to interact with homeassistant by clicking on the widget?

Im trying to get to an overview page for my fuel prices out of the widget:

Greetings to all of you:)

Wow, great script! Is there a way to keep the values updating every few seconds?

While in theory possible, see this link, it would drain your battery and is not recommended by the author of the Scriptable app.

Scriptable API Doc:

const nextRefresh = Date.now() + (1000 * 30); // add 30 second to now
widget.refreshAfterDate = new Date(nextRefresh);

Before you refresh the Widget too often, double check that Home Assistant’s /api/states also updates it’s values fast enough.

Im having trouble getting this to work. Im getting a “error data couldn’t be read in the correct format”.

I tried the troubleshooting steps above and I have the token as well as the “401 unauthorized” error even pasting in my URL.

I tried the short script to get a list of my entities and it’s giving me the error “Syntax Error: unexpected identifier ‘insecure’”

curl --insecure -H 'Authorization: Bearer *--{xxxtokenxxx}--*' -H 'content-type: application/json' https://*--{MY.SERVER}--*/api/states

Any help would be appreciated!

Looks like you tried to enter the cURL command into Scriptable app? This cannot work. cURL is a command line utility, that you type into your macOS/Linux/Windows terminal. I’m pretty sure there is also cURL for Windows 10, but it will require some special steps before you can use it. There is no such thing for iOS/iPadOS and your screenshots look like you are trying to do this on your iPhone/iPad?

If all this command line foobar is nothing for you. You can also use a REST client, for example for Google Chrome and debug your requests there.

Thanks - I misread the post and was trying in scriptable via macOS and iOS.

I can try in terminal later and try to keep tinkering to get the main API to run.

Is this still a valid method or is there any easier method existing nowadays?

This is still the only method I’m aware of. With iOS16 there is a new lock screen widget (and Scriptable supports it too yay) but it is super tiny, haven’t found a good use case for it yet.

More on the lock screen widget here:

Thanks @m33x.

When trying, I get an error from within scriptable saying:
Exception Occurred.
Error: The URL is invalid.

I’m quite sure my URL is valid. I have tested it with the Bearer key from postman and it gives me the expected sensors. Any idea of what’s wrong.

This solution is just too good to just be left, without really trying

Before doing anything with Scriptable, it is a good idea to check your setup first. Install a REST extension in your browser, authenticate to HASS, query the sensors.

other frequent mistakes:

If your HA instance url is correct, then you didn’t scroll down and change the address in the location of the icons toward the bottom of the script.

Thank you so much !
Amazing !
Got to adapt to my needs so easily !

1 Like

hello @m33x

i would like to make this map of your temperature but i can’t get it done run into errors on line 17 you have to create that token in ha under access tokens with long life, right? wall I would like to make it? can you help me ?

On the bottom left in Home Assistant, click on your username (mine is „Max“) then scroll down to „Long-Lived Access Tokens“ then click on „Create Token“.


hello i tried this error message so i don’t understand what i did wrong?

2023-06-12 23:06:24: Error on line 17: SyntaxError: Unexpected EOF
let req = new Request("https://192.168.0.184/api/states")
    req.headers = { "Authorization": "my token 
         at https://192.168.0.184/profile", "content-type": "application/json" }
    let json = await req.loadJSON();
  1. Don’t post your access token here (it can be abused)
  2. For me the request looks like this (maybe you can try adding the word “Bearer“)
req.headers = { "Authorization": "Bearer eyX … 9wY", "content-type": "application/json" }
  1. Debug the request outside of Scriptable first, as previously discussed and explained for example here: iOS Widget for Home Assistant via Scriptable - #43 by m33x

Good luck :+1:

1 Like

hey merci I have removed the token here and Bearer for it does not help I now get the error message error: the url is invalid ? & I have http://my ip ha :8123/api/states ? is this correct and test via that chrome thing won’t lauch on my chrome browser?

Test this on api app on my iPhone

This not working

Tis erro

An SSL error has occurred and a secure connection to the server cannot be made.

Okay, this problem is unrelated to the Widget. You first need to setup your Home Assistant properly, using some DynDNS provider and Let’s Encrypt. For example following this guide.