Homey Community Forum

Rest API call for setting asleep

#1

Hi,

I currently have presence and sleep detection setup using BL. But was looking into using the built in one instead. I am no programmer, so I’m just going on by trial and error. So far, only error. How can I do a rest call to set the value?

I can read all users by calling /api/manager/users/user/ or
a specific user by /api/manager/users/user//

But no matter how I format the body I cannot change the value. It just stays as:
“asleep”: false

Any help would be appreciated.

\ Andreas

#2

To find out…

Open a Browser to the API documentation,
https://developer.athom.com/docs/api/HomeyAPI.ManagerPresence.html
Open a Web Api Playground
https://developer.athom.com/tools/api-playground

Open Inspect (Ctr-Shift-I)

Get your ID

Homey.users.getUserMe();

Try…
Homey.users.updateUser({id:'43ba47df-4026-4a12-b3cc-90c44a025549',user:{asleep:true}})
Error: Parameter 'asleep' is read-only.

And don’t give up…

Homey.presence.setAsleep({id:'43ba47df-4026-4a12-b3cc-90c44a025549',value:true})
image

image

image

Happy Hacking :wink:

2 Likes
#3

Thank you so much! Worked perfect :slight_smile:

Funny thing, I’ve been using almost exactly that to get a new Bearer token last few days due to a bug in 2.1.1 expiring them once a day.

Have a great weekend!

#4

Hmm, guess I was a bit quick. Seems like I ran into another noob issue right away. It appears as it works as intended from the Web API Playground. But when trying in Postman or RESTask in Tasker it toggles the value every time I run a PUT. I was expecting it to change to or not change if already the same.

I’m probably not formatting the value {“asleep”:true} (and a few variants) in the body correctly. If I remove it completely, I still get the toggle behavior.

Again, any help would be appreciated.

#5

I read {value:true} above as request payload …

#6

I’m trying my best, but still cannot succeed. I found an old post describing how to use RESTask properly. https://forum.athom.com/discussion/996/tutorial-using-tasker-and-the-homey-api
So I did the same with the proper URL but it still only toggles every time I try to set it.


Maybe somethings have changed since 1.5 when it comes to the API? I also tried to set the value as header or parameter. Trying all variants of with or without curly brackets and dubble quotes. Still only toggles. Feel almost like the mad scientist here, trying everything without hitting the perfect combination :smiley:

#7

Maybe all this is for nothing since the Bearer tokens now expire after 24h. I thought it was a bug in 2.1.1 fixed in 2.1.2. But it seems not. If this is the case, then Homey just lost a point until I can figure out how to authenticate properly.