# Flows scripting

**URL:** <https://community.homey.app/t/flows-scripting/9212>\
**Category:** Developers\
**Created:** [February 14, 2019, 10:01pm UTC](https://community.homey.app/t/flows-scripting/9212 "2019-02-14T22:01:29Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![unknown\_error](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/unknown_error/32/9109_2.png) [@unknown\_error](https://community.homey.app/u/unknown_error)\
**Post date:** [February 14, 2019, 10:01pm UTC](https://community.homey.app/t/flows-scripting/9212/1 "2019-02-14T22:01:29Z")

</div>

Does anybody have an example how to create flows programmatically?  
It would be nice to have something like:

1. Create flow with a trigger from an App (so I can specify the trigger and an App to use trigger from)
2. Add conditions (like states from other Apps / devices).
3. Add actions (change device state / set state for an App / execute an action for a chosen App).

So the goal is to script everything that flow editor allows you to do.

---

<div class="post-metadata">

**Author:** ![HarriedeGroot](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/harriedegroot/32/56160_2.png) [@HarriedeGroot](https://community.homey.app/u/HarriedeGroot)\
**Post date:** [February 14, 2019, 10:55pm UTC](https://community.homey.app/t/flows-scripting/9212/2 "2019-02-14T22:55:31Z")

</div>

Did you try [HomeyScript](https://homeyscript.athom.com)? With this [app](https://apps.athom.com/app/com.athom.homeyscript).  
Examples can be found [here](https://github.com/athombv/com.athom.homeyscript/wiki).

---

<div class="post-metadata">

**Author:** ![unknown\_error](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/unknown_error/32/9109_2.png) [@unknown\_error](https://community.homey.app/u/unknown_error)\
**Post date:** [February 14, 2019, 11:41pm UTC](https://community.homey.app/t/flows-scripting/9212/3 "2019-02-14T23:41:57Z")

</div>

I’ve seen HomeyScript, but I’m not sure if it provides a way to create flows with triggers etc without using the standard flow editor.  
Is that possible? I don’t see any examples like that.

---

<div class="post-metadata">

**Author:** ![Jamie](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/jamie/32/5274_2.png) [@Jamie](https://community.homey.app/u/Jamie)\
**Post date:** [February 15, 2019, 2:14am UTC](https://community.homey.app/t/flows-scripting/9212/4 "2019-02-15T02:14:35Z")

</div>

I dont know if that is the purpose, Homey script is to run scripts not trigger scripts.

If you don’t want to use the flow editor to trigger a script, then you could create a SDK app which uses the webAPI to piggy back upon a device capability event observers. Be warned that if you go that route your likely to have a Alice falling down the rabbit hole moment.

---

<div class="post-metadata">

**Author:** ![unknown\_error](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/unknown_error/32/9109_2.png) [@unknown\_error](https://community.homey.app/u/unknown_error)\
**Post date:** [February 15, 2019, 9:31am UTC](https://community.homey.app/t/flows-scripting/9212/5 "2019-02-15T09:31:49Z")

</div>

I’d like to find any examples how to create flows with API only.

---

<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:** [February 15, 2019, 9:37am UTC](https://community.homey.app/t/flows-scripting/9212/6 "2019-02-15T09:37:04Z")

</div>

I can’t think of any ☹ The documentation is woefully incomplete: [https://developer.athom.com/docs/api/HomeyAPI.ManagerFlow.html#createFlow](https://developer.athom.com/docs/api/HomeyAPI.ManagerFlow.html#createFlow)

---

<div class="post-metadata">

**Author:** ![anon8748058](https://avatars.discourse-cdn.com/v4/letter/a/ebca7d/32.png) [@anon8748058](https://community.homey.app/u/anon8748058)\
**Post date:** [February 15, 2019, 1:31pm UTC](https://community.homey.app/t/flows-scripting/9212/7 "2019-02-15T13:31:55Z")

</div>

Hi,

Not sure if remotely helpful but:

@Erik - Who is behind the ‘flow viewer’ also created a [flow editor](https://community.homey.app/t/how-to-view-your-homey-v2-flows-in-a-browser/7427/36) in the past for his private use use. (I think he suggests there, that he’s going to look into making a working public version of it? - If not then, I misunderstood)

At any rate. Maybe he can give you some pointed on how to address your question?

---

<div class="post-metadata">

**Author:** ![Jeroen\_Somhorst](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/jeroen_somhorst/32/184_2.png) [@Jeroen\_Somhorst](https://community.homey.app/u/Jeroen_Somhorst)\
**Post date:** [February 15, 2019, 2:36pm UTC](https://community.homey.app/t/flows-scripting/9212/8 "2019-02-15T14:36:32Z")

</div>

The question I have is … Why?

---

<div class="post-metadata">

**Author:** ![Rocodamelshekima](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/rocodamelshekima/32/8209_2.png) [@Rocodamelshekima](https://community.homey.app/u/Rocodamelshekima)\
**Post date:** [February 15, 2019, 2:43pm UTC](https://community.homey.app/t/flows-scripting/9212/9 "2019-02-15T14:43:21Z")

</div>

Only reason I can think of is making a flow editor?

---

<div class="post-metadata">

**Author:** ![Jeroen\_Somhorst](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/jeroen_somhorst/32/184_2.png) [@Jeroen\_Somhorst](https://community.homey.app/u/Jeroen_Somhorst)\
**Post date:** [February 15, 2019, 3:17pm UTC](https://community.homey.app/t/flows-scripting/9212/10 "2019-02-15T15:17:45Z")

</div>

Or make flows on the commandline when you are working in a linux shell? 😉

---

<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:** [February 15, 2019, 4:10pm UTC](https://community.homey.app/t/flows-scripting/9212/11 "2019-02-15T16:10:13Z")

</div>

Or make the promised Community Desktop App to replace the old one. Without proper documentation…

---

<div class="post-metadata">

**Author:** ![Rocodamelshekima](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/rocodamelshekima/32/8209_2.png) [@Rocodamelshekima](https://community.homey.app/u/Rocodamelshekima)\
**Post date:** [February 15, 2019, 4:11pm UTC](https://community.homey.app/t/flows-scripting/9212/12 "2019-02-15T16:11:50Z")

</div>

> [@robertklep](#):
>
> promised

Now who did that?

---

<div class="post-metadata">

**Author:** ![Erik](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/erik/32/9865_2.png) [@Erik](https://community.homey.app/u/Erik)\
**Post date:** [February 15, 2019, 4:42pm UTC](https://community.homey.app/t/flows-scripting/9212/13 "2019-02-15T16:42:14Z")

</div>

```
  $.ajax({
    url: `${setup.protocol}://${setup.ip}/api/manager/flow/flow/${flowId}`,
    type: 'POST',
    data: JSON.stringify(flowObject),
    success: function(data) {
      console.log('Hoera')
    }
  })

```

Where `flowObject` is comparable to what you GET with the getFlow commands.

---

<div class="post-metadata">

**Author:** ![unknown\_error](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/unknown_error/32/9109_2.png) [@unknown\_error](https://community.homey.app/u/unknown_error)\
**Post date:** [February 15, 2019, 6:18pm UTC](https://community.homey.app/t/flows-scripting/9212/14 "2019-02-15T18:18:03Z")

</div>

I don’t like visual interfaces to build any sort of logic and mobile UI doesn’t add any value to that.  
The goal is to create and maintain all the flows/logic using scripting only. Also this allows to use VCS to keep a history of changes.

---

<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:** [February 15, 2019, 7:06pm UTC](https://community.homey.app/t/flows-scripting/9212/15 "2019-02-15T19:06:36Z")

</div>

> [@unknown\_error](#):
>
> The goal is to create and maintain all the flows/logic using scripting only

I don’t see the point of creating flows then, it sounds like you want to use events to detect changes to device state and act on those. Or use the MQTT Gateway/Hub app to do the heavy lifting, and implement your logic based on MQTT events.

---

<div class="post-metadata">

**Author:** ![unknown\_error](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/unknown_error/32/9109_2.png) [@unknown\_error](https://community.homey.app/u/unknown_error)\
**Post date:** [February 15, 2019, 7:30pm UTC](https://community.homey.app/t/flows-scripting/9212/16 "2019-02-15T19:30:26Z")

</div>

That was my original intention.  
Homey provides other features using Apps, so it’s possible to use non-device events, actions and data using regular flows. It would be great to have an opportunity to use that. Also it’s still useful to have flows because they are a part of the whole system.  
Do you know how to use Apps without flow cards in a convenient way? Well, nothing is convenient btw, but I’d like to use Apps from my scripts.

---

<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:** [February 15, 2019, 7:35pm UTC](https://community.homey.app/t/flows-scripting/9212/17 "2019-02-15T19:35:09Z")

</div>

> [@unknown\_error](#):
>
> Do you know how to use Apps without flow cards in a convenient way? Well, nothing is convenient btw, but I’d like to use Apps from my scripts.

You have to be more specific: can you name an app and how you would want to use it?

---

<div class="post-metadata">

**Author:** ![unknown\_error](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/unknown_error/32/9109_2.png) [@unknown\_error](https://community.homey.app/u/unknown_error)\
**Post date:** [February 15, 2019, 8:26pm UTC](https://community.homey.app/t/flows-scripting/9212/18 "2019-02-15T20:26:43Z")

</div>

Examples:

1. Play music using Spotify.
2. Check if it’s raining outside using a weather app.
3. Check if it’s time to collect a trash using Trashcan Reminder.

Well, it’s still possible to create flows manually and run them through MQTT. Or I can send MQTT events if something happens using a few flows.  
Not sure if it makes sense to use MQTT in this case, it looks like it would be better to build my own app that does all these things.

---

<div class="post-metadata">

**Author:** ![Jeroen\_Somhorst](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/jeroen_somhorst/32/184_2.png) [@Jeroen\_Somhorst](https://community.homey.app/u/Jeroen_Somhorst)\
**Post date:** [February 15, 2019, 9:01pm UTC](https://community.homey.app/t/flows-scripting/9212/19 "2019-02-15T21:01:24Z")

</div>

I really fail to see why in the cases you mentioned you would need anything other then the normal flow editor. It sounds to me like over engineering

---

<div class="post-metadata">

**Author:** ![HarriedeGroot](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/harriedegroot/32/56160_2.png) [@HarriedeGroot](https://community.homey.app/u/HarriedeGroot)\
**Post date:** [February 15, 2019, 9:21pm UTC](https://community.homey.app/t/flows-scripting/9212/20 "2019-02-15T21:21:05Z")

</div>

This was/is exactly my thought for the MQTT Hub. I also want(ed) to integrate app triggers, conditions & actions into the hub, to fully control your Homey over mqtt. No need to create flows. Even had a long discussion about this a while ago on slack; the conclusion (from Emile): it’s simply not possible.

[Next page](https://community.homey.app/t/flows-scripting/9212.md?page=2)
