# Best way to trigger a flow from homeyscript

**URL:** <https://community.homey.app/t/best-way-to-trigger-a-flow-from-homeyscript/19790>\
**Category:** Developers\
**Tags:** homeyscript\
**Created:** [October 27, 2019, 8:05am UTC](https://community.homey.app/t/best-way-to-trigger-a-flow-from-homeyscript/19790 "2019-10-27T08:05:07Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![andreassolberg](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/andreassolberg/32/16983_2.png) [@andreassolberg](https://community.homey.app/u/andreassolberg)\
**Post date:** [October 27, 2019, 8:05am UTC](https://community.homey.app/t/best-way-to-trigger-a-flow-from-homeyscript/19790/1 "2019-10-27T08:05:07Z")

</div>

what is the best way to trigger a flow from inside homeyscript

---

<div class="post-metadata">

**Author:** ![robertklep](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/robertklep/32/160628_2.png) [@robertklep](https://community.homey.app/u/robertklep)\
**Post date:** [October 27, 2019, 8:13am UTC](https://community.homey.app/t/best-way-to-trigger-a-flow-from-homeyscript/19790/2 "2019-10-27T08:13:35Z")

</div>

Probably using [`Homey.flow.triggerFlow()`](https://developer.athom.com/docs/api/HomeyAPI.ManagerFlow.html#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).

---

<div class="post-metadata">

**Author:** ![andreassolberg](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/andreassolberg/32/16983_2.png) [@andreassolberg](https://community.homey.app/u/andreassolberg)\
**Post date:** [October 27, 2019, 8:56am UTC](https://community.homey.app/t/best-way-to-trigger-a-flow-from-homeyscript/19790/3 "2019-10-27T08:56:17Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![robertklep](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/robertklep/32/160628_2.png) [@robertklep](https://community.homey.app/u/robertklep)\
**Post date:** [October 27, 2019, 9:00am UTC](https://community.homey.app/t/best-way-to-trigger-a-flow-from-homeyscript/19790/4 "2019-10-27T09:00:45Z")

</div>

> [@andreassolberg](#):
>
> I discovered that I did not have permission to trigger flows directly.

I don’t understand myself why Athom has decided to limit Homeyscript like that ☹

> [@](#):
>
> 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.

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.

---

<div class="post-metadata">

**Author:** ![andreassolberg](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/andreassolberg/32/16983_2.png) [@andreassolberg](https://community.homey.app/u/andreassolberg)\
**Post date:** [October 27, 2019, 9:30am UTC](https://community.homey.app/t/best-way-to-trigger-a-flow-from-homeyscript/19790/5 "2019-10-27T09:30:59Z")

</div>

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:

> [@\[APP\]\[Pro\] HomeyScript](https://community.homey.app/t/homeyscript-app/854/17):
>
> nope, using await setTagValue("listalarm", {type: "text", title: "listalarm"}, sum); returns an error, without the await it just doesn’t set the value in the variable. cry

The specific error I get is:

```auto
Cannot set value, token is not registered

```

Have you been using `await setTagValue`, and have you had trouble with it?

---

<div class="post-metadata">

**Author:** ![andreassolberg](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/andreassolberg/32/16983_2.png) [@andreassolberg](https://community.homey.app/u/andreassolberg)\
**Post date:** [October 27, 2019, 9:48am UTC](https://community.homey.app/t/best-way-to-trigger-a-flow-from-homeyscript/19790/6 "2019-10-27T09:48:07Z")

</div>

I’m wondering if `setTagValue` is deprecated, and if there is a newer API…

---

<div class="post-metadata">

**Author:** ![robertklep](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/robertklep/32/160628_2.png) [@robertklep](https://community.homey.app/u/robertklep)\
**Post date:** [October 27, 2019, 9:51am UTC](https://community.homey.app/t/best-way-to-trigger-a-flow-from-homeyscript/19790/7 "2019-10-27T09:51:28Z")

</div>

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](https://slack.athom.com), specifically on the #developers channel.

---

<div class="post-metadata">

**Author:** ![Techniman](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/techniman/32/8654_2.png) [@Techniman](https://community.homey.app/u/Techniman)\
**Post date:** [November 1, 2019, 2:45pm UTC](https://community.homey.app/t/best-way-to-trigger-a-flow-from-homeyscript/19790/8 "2019-11-01T14:45:30Z")

</div>

> [@robertklep](#):
>
> k around on the Homey

Can’t you instead use a better logic variable, those don’t work with tokens i think ?

---

<div class="post-metadata">

**Author:** ![Satoer](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/satoer/32/38113_2.png) [@Satoer](https://community.homey.app/u/Satoer)\
**Post date:** [November 3, 2019, 6:43pm UTC](https://community.homey.app/t/best-way-to-trigger-a-flow-from-homeyscript/19790/9 "2019-11-03T18:43:04Z")

</div>

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");
```

---

<div class="post-metadata">

**Author:** ![khangwei](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/khangwei/32/9687_2.png) [@khangwei](https://community.homey.app/u/khangwei)\
**Post date:** [March 7, 2020, 3:42am UTC](https://community.homey.app/t/best-way-to-trigger-a-flow-from-homeyscript/19790/10 "2020-03-07T03:42:41Z")

</div>

hey guys. so is it still not possible to trigger a flow from homeyscript?

---

<div class="post-metadata">

**Author:** ![robertklep](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/robertklep/32/160628_2.png) [@robertklep](https://community.homey.app/u/robertklep)\
**Post date:** [March 7, 2020, 5:48am UTC](https://community.homey.app/t/best-way-to-trigger-a-flow-from-homeyscript/19790/11 "2020-03-07T05:48:07Z")

</div>

No, I don’t think anything has changed there ☹

---

<div class="post-metadata">

**Author:** ![ArnarS](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/arnars/32/33981_2.png) [@ArnarS](https://community.homey.app/u/ArnarS)\
**Post date:** [October 29, 2021, 4:39pm UTC](https://community.homey.app/t/best-way-to-trigger-a-flow-from-homeyscript/19790/12 "2021-10-29T16:39:59Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![JPe4619](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/jpe4619/32/9017_2.png) [@JPe4619](https://community.homey.app/u/JPe4619)\
**Post date:** [October 29, 2021, 5:24pm UTC](https://community.homey.app/t/best-way-to-trigger-a-flow-from-homeyscript/19790/13 "2021-10-29T17:24:47Z")

</div>

![Screenshot_20211029-192336_Chrome](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/8/3/83d5c2683b9df7e652122929f0053e785a06f79c.jpeg)

How far did you look?

---

<div class="post-metadata">

**Author:** ![ArnarS](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/arnars/32/33981_2.png) [@ArnarS](https://community.homey.app/u/ArnarS)\
**Post date:** [October 29, 2021, 5:40pm UTC](https://community.homey.app/t/best-way-to-trigger-a-flow-from-homeyscript/19790/14 "2021-10-29T17:40:02Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Peter\_Kawa](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/peter_kawa/32/173848_2.png) [@Peter\_Kawa](https://community.homey.app/u/Peter_Kawa)\
**Post date:** [December 27, 2021, 10:30pm UTC](https://community.homey.app/t/best-way-to-trigger-a-flow-from-homeyscript/19790/15 "2021-12-27T22:30:58Z")

</div>

Not quite, the script can run existing flow_cards_: 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

---

<div class="post-metadata">

**Author:** ![Lane\_Canada](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/lane_canada/32/92195_2.png) [@Lane\_Canada](https://community.homey.app/u/Lane_Canada)\
**Post date:** [October 3, 2024, 1:47am UTC](https://community.homey.app/t/best-way-to-trigger-a-flow-from-homeyscript/19790/16 "2024-10-03T01:47:47Z")

</div>

> [@khangwei](#):
>
> hey guys. so is it still not possible to trigger a flow from homeyscript?

Is this still true?
