HomeyScript scopes / authorization

I’m having a lot of fun with HomeyScript. Reading through several topics on this forum taught me a lot. Although now I’m running into a problem that is not yet answered.

(I focussed this on updating a variable, but this also applies to i.e. triggering flows)

When I want to update a logic variable, I should do as followed:

Homey.logic.updateVariable({id: <String>, variable: <Variable object>});

Confusion #1: id? What ID? For now I’m going to use my own ID.

let me = await Homey.users.getUserMe();
let variable = await Homey.logic.getVariable({id: 'variable-id'});
Homey.logic.updateVariable({id: me.id, variable: variable});

This will return:

Script Error:
Je hebt geen toegang om dit te doen. (translation: You have no permission to do this)

Confusion #2: Why can’t I update variables when I can change things on a device with setCapabilityValue()?

When I check my permissions:

let session = await Homey.sessions.getSessionMe();
log(session);

I see indeed that I have almost only readonly permissions:

t {
  __athom_api_type: 'HomeyAPI.ManagerSessions.Session',
  id: ...',
  type: 'APP',
  agent: 'com.athom.homeyscript',
  scopes: 
   [ 'resource',
     'homey.alarm',
     'homey.system.readonly',
     'homey.updates.readonly',
     'homey.geolocation.readonly',
     'homey.zone.readonly',
     'homey.device.readonly',
     'homey.device.control',
     'homey.flow.readonly',
     'homey.user.readonly',
     'homey.user.self',
     'homey.app.readonly',
     'homey.app.control',
     'homey.presence.readonly',
     'homey.insights.readonly',
     'homey.logic.readonly',
     'homey.speech' ],

Confusion #3: When I check my session, why is 'com.athom.homeyscript' my agent?
Confusion #4: When I check out the me-object, my user role is role: 'owner', I should be able to do everything I want, because I really own Homey.

Question:
How can I update my variables? How can I trigger my flows?
Is it:

Homey version: 3.1.0
HomeyScript version: 1.1.1

Yet somehow, Athom has decided that Homeyscript should have limited permissions.

1 Like

You can change variables (tag) in HomeyScript only when they are created in HomeyScript and that variables are gone after a restart of Homey.

await setTagValue(“bas”, {type: “string”, title: “bas”}, b);

HomeySript states that the setTagValue is used to “Create, edit, remove a flow tag.”

What I have is a loop in a script that executes every x-minutes. In this loop I’d like to use variables that can be changed by other flows. I haven’t tried yet, but I doubt that the flow-tags are editable by separate triggered flows :frowning:

They are! Even a better advise is “Try before you doubt”

2 Likes

i doubt if that is really true. can you explain how this happend? and… how to get rid of them? trust me, my homey has been rebooted multiple times since then.

“Delete a Flow Token by providing null as value.”

that indeed works… i have a lot to do :frowning:

thanks!

but… somehow it is possible then…

That was nov. 2019, now they are kept after restart.
In the new examples it is shown how te create, edit and delete the tags.