what is the best way to trigger a flow from inside homeyscript
Probably using Homey.flow.triggerFlow()
, although I’m not sure if Homeyscript has the correct permissions to do that. If not, you have to use workarounds (like using a Homeyscript as a condition which will either allow or prevent a “Start a Flow” action, or using Homeyscript to call a webhook).
Thanks for the tip. I discovered that I did not have permission to trigger flows directly.
What I did instead is to run the homeyscript as an and condition, and add a then Logic to set a textual variable based upon a tag from the script. Then I changed the flows to trigger when the text variable changed to specific items. Im very happy with this way to solve it for my specific use case at least.
I don’t understand myself why Athom has decided to limit Homeyscript like that
Yeah, that’s a good solution alternatively, you can make your condition script either return a true
or a false
and trigger the “THEN” (when “true”) or “ELSE” (when “false”) card.
True false, also a good tip, but in my use case Id like to run one of 8 different “scene” flows for a room.
My attempt did work well the first time, but then I suddenly was not able to set a tag anymore. I did a restart. And now I run into the same problem described here:
The specific error I get is:
Cannot set value, token is not registered
Have you been using await setTagValue
, and have you had trouble with it?
I’m wondering if setTagValue
is deprecated, and if there is a newer API…
AFAIK there isn’t a newer API, but I’ve seen this issue before. I think it has to do with tags/tokens not being persistent, so after a reboot they don’t exist anymore. However, I would expect them to get created when you use setTagValue
for the first time, but apparently they don’t
Perhaps you could ask around on the Homey Slack channel, specifically on the #developers channel.
Can’t you instead use a better logic variable, those don’t work with tokens i think ?
I haven’t found a way to store Homey variables. But I did managed to set Better Logic variables to store data:
let BLApp = await Homey.apps.getApp({id:"net.i-dev.betterlogic" });
BLApp.apiPut("VariableName/value");
hey guys. so is it still not possible to trigger a flow from homeyscript?
No, I don’t think anything has changed there
Hi.
This is an old thread, so I have to ask, has something changed since March 2020?
I am starting to look at Homeyscript, and I was able to toggle my lights on/off, purely through hscript.
well, yes, this runs a flow card defined within the script. But this thread is about running existing flow (created in the h.app) from script. Therefore, I dared to ask.
Not quite, the script can run existing flowcards: the AND and THEN cards.
It however can’t trigger a complete flow (with the IF “This flow is started” card).
The example-flowcard-list
outputs all of your AND and THEN cards, so you can search for the right id and stuff
Is this still true?