# How update variable using API

**URL:** <https://community.homey.app/t/how-update-variable-using-api/76496>\
**Category:** Flows\
**Tags:** app, flow, homey-bridge\
**Created:** [February 15, 2023, 11:50am UTC](https://community.homey.app/t/how-update-variable-using-api/76496 "2023-02-15T11:50:48Z")\
**Posts on this page:** 16\
**Page:** 2

<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:** [February 15, 2023, 10:56pm UTC](https://community.homey.app/t/how-update-variable-using-api/76496/21 "2023-02-15T22:56:24Z")

</div>

That’s odd, there’s only 1 kind of Homey cloud as far as I know, and we should have the same set of cards (not to point a finger, I just wonder why I have more cards… ).  
But, it doesn’t work anyways, while there’s no output of the Http GET card 🤨

---

<div class="post-metadata">

**Author:** ![Marcel\_Ubels](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/marcel_ubels/32/18860_2.png) [@Marcel\_Ubels](https://community.homey.app/u/Marcel_Ubels)\
**Post date:** [February 16, 2023, 6:59am UTC](https://community.homey.app/t/how-update-variable-using-api/76496/22 "2023-02-16T06:59:38Z")

</div>

Can it be that you have the premium subscription and Ruud not?

---

<div class="post-metadata">

**Author:** ![Arie\_J\_Godschalk](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/arie_j_godschalk/32/63027_2.png) [@Arie\_J\_Godschalk](https://community.homey.app/u/Arie_J_Godschalk)\
**Post date:** [February 16, 2023, 7:13am UTC](https://community.homey.app/t/how-update-variable-using-api/76496/23 "2023-02-16T07:13:13Z")

</div>

> [@Ruud\_Naastepad](#):
>
> However I do have the possibility to receive a webhook, just don’t know how to use it to receive a value.

First: Can you show me that card?  
Because i am not sure which on it is, since we oviously don’t have the same cards 😉

Secondly, i don’t think a webhook is gonna be a solution.  
Because that means you will need to give the weather-api a command to send a signal back over a certain URL to recieve that Webhook.  
And i don’t see that documenten anywhere about the weather api.

---

<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:** [February 16, 2023, 4:34pm UTC](https://community.homey.app/t/how-update-variable-using-api/76496/24 "2023-02-16T16:34:11Z")

</div>

> [@Marcel\_Ubels](#):
>
> Can it be that you have the premium subscription and Ruud not?

No, while [this screenvid](https://community.homey.app/t/how-update-variable-using-api/76496/18) is made without premium.

While I was curious for a solution, I enabled a free month Premium, and could make [this flow](https://community.homey.app/t/how-update-variable-using-api/76496/19) without blacked-out logics cards 😊  
But that flow idea doesn’t work.

---

<div class="post-metadata">

**Author:** ![Ruud\_Naastepad](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/ruud_naastepad/32/67675_2.png) [@Ruud\_Naastepad](https://community.homey.app/u/Ruud_Naastepad)\
**Post date:** [February 16, 2023, 4:39pm UTC](https://community.homey.app/t/how-update-variable-using-api/76496/25 "2023-02-16T16:39:14Z")

</div>

this is the webhook card  
 ![webhookcard](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/a/c/ac6bbe5835a76e4f7ca9fbe5891f185286065bed.jpeg)

---

<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:** [February 16, 2023, 4:49pm UTC](https://community.homey.app/t/how-update-variable-using-api/76496/26 "2023-02-16T16:49:45Z")

</div>

Ruud and Arie,  
When you add that card to a flow, you’ll see it only responds to a specific URL with your CloudID and `<my_event>` as identifier

> ![Screenshot_20230216-174643_Homey](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/0/3/0321c70921af77cb8f6064e7d970f925a739153b.jpeg)

---

<div class="post-metadata">

**Author:** ![Ruud\_Naastepad](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/ruud_naastepad/32/67675_2.png) [@Ruud\_Naastepad](https://community.homey.app/u/Ruud_Naastepad)\
**Post date:** [February 16, 2023, 4:58pm UTC](https://community.homey.app/t/how-update-variable-using-api/76496/27 "2023-02-16T16:58:02Z")

</div>

mm I saw that at some point but when i add that card to a flow now i don’t see the option to edit anymore:

 ![webhookevent](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/e/0/e08c211b6365409542412aa33cc4b871d4b304e4.jpeg)  
😕

---

<div class="post-metadata">

**Author:** ![Ruud\_Naastepad](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/ruud_naastepad/32/67675_2.png) [@Ruud\_Naastepad](https://community.homey.app/u/Ruud_Naastepad)\
**Post date:** [February 16, 2023, 8:26pm UTC](https://community.homey.app/t/how-update-variable-using-api/76496/28 "2023-02-16T20:26:00Z")

</div>

I find some documentation [here](https://apps.developer.homey.app/cloud/webhooks) but still can’t figure out how to apply that;

tried sending this request with the make a request card

```auto
POST /webhook/63ecc33550810... HTTP/1.1
Host: webhooks.athom.com
Content-Type: application/json; charset=utf-8

{
  "cloud": 4
}

```

 ![sendpost](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/b/c/bc8b597d9d39b620e061e0fde3c187cda43d28dd.jpeg)

after first doing register:

```auto
const Homey = require('homey');

class App extends Homey.App {
  async onInit() {
    const id = Homey.env.WEBHOOK_ID; // "63ecc33550810..."
    const secret = Homey.env.WEBHOOK_SECRET; // "2uhf83h83h4gg34..."
    const data = {
      // Provide unique properties for this Homey here
      cloud: 5,
    };

    const myWebhook = await this.homey.cloud.createWebhook(id, secret, data);

    myWebhook.on('message', args => {
      this.log('Got a webhook message!');
      this.log('headers:', args.headers);
      this.log('query:', args.query);
      this.log('body:', args.body);
    });
  }
}

module.exports = App;

```

and setup header:

```auto
const Homey = require('homey');

class App extends Homey.App {
  async onInit() {
    const id = Homey.env.WEBHOOK_ID; // "63ecc33550810..."
    const secret = Homey.env.WEBHOOK_SECRET; // "2uhf83h83h4gg34..."
    const data = {
      // Provide unique properties for this Homey here
      $keys: ["aaa", "bbb"],
    };

    const myWebhook = await this.homey.cloud.createWebhook(id, secret, data);

    myWebhook.on('message', args => {
      this.log('Got a webhook message!');
      this.log('headers:', args.headers);
      this.log('query:', args.query);
      this.log('body:', args.body);
    });
  }
}

module.exports = App;

```

but don’t know what to fill in for $key there and generally don’t know what all of this really does and if this can work.

---

<div class="post-metadata">

**Author:** ![Arie\_J\_Godschalk](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/arie_j_godschalk/32/63027_2.png) [@Arie\_J\_Godschalk](https://community.homey.app/u/Arie_J_Godschalk)\
**Post date:** [February 16, 2023, 8:42pm UTC](https://community.homey.app/t/how-update-variable-using-api/76496/29 "2023-02-16T20:42:12Z")

</div>

What is this? Or you creating a App for it?  
If so, you have a Homey Pro?

I don’t get it?

---

<div class="post-metadata">

**Author:** ![Ruud\_Naastepad](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/ruud_naastepad/32/67675_2.png) [@Ruud\_Naastepad](https://community.homey.app/u/Ruud_Naastepad)\
**Post date:** [February 16, 2023, 8:50pm UTC](https://community.homey.app/t/how-update-variable-using-api/76496/30 "2023-02-16T20:50:38Z")

</div>

No homey pro, just bridge.

Asked another weather api provider, meteomatics, about the possibility of dealing with webhooks and they replied

Unfortunately, we currently don’t have a web hook service where you can subscribe to get notified for a particular event.

While the support to implement an external service is out of our scope, there seems to be Web API for this product.

If this is something you can use to control Homey’s behaviour, you might be able to do:

1. Build your own program that queries our REST API endpoint periodically.

2. Process the data to check if a certain condition of your choice is satisfied.

3. Send a request to Homey web API.

First and second step seems doable but I still can’t figure out how to do 3.

---

<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 17, 2023, 5:55am UTC](https://community.homey.app/t/how-update-variable-using-api/76496/31 "2023-02-17T05:55:31Z")

</div>

You’re not adding ` HTTP/1.0` to the end of the URL, are you? If so: don’t.

Also, your body doesn’t contain valid JSON, it has a trailing comma after `"5"`

---

<div class="post-metadata">

**Author:** ![Ruud\_Naastepad](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/ruud_naastepad/32/67675_2.png) [@Ruud\_Naastepad](https://community.homey.app/u/Ruud_Naastepad)\
**Post date:** [February 17, 2023, 3:33pm UTC](https://community.homey.app/t/how-update-variable-using-api/76496/32 "2023-02-17T15:33:45Z")

</div>

Well, finally got it working…

One card to run a script on any server that will trigger a call to the weatherapi (one for every time you want an update, e.g. every hour or every half hour, or alternatively use some sort of loop for this):

 ![triggerweerupdate](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/e/7/e712cd3b7a808aa1cc9e1486b0cf5934d216a19d.jpeg)

script would be something like this for a call to Meteomatics API:

```auto
    // ask for the weather:
    $url = 'https://api.meteomatics.com/2023-02-16T13:15:00.000+01:00/weather_symbol_1h:idx/51.9813422,6.8047751/json?model=mix ';
    $curl_handle=curl_init();
    curl_setopt($curl_handle, CURLOPT_URL, $url);
    $response = curl_exec($curl_handle);
    curl_close($curl_handle);

    // send request to webhookserver:
    $obj = json_decode($response);
    $cloud = $obj->data[0]->coordinates[0]->dates[0]->value;

    // code 1 (clear sky) of 2 (light clouds)
    $curlHandle = curl_init();

    if ($cloud == 1 or $cloud == 2) {
        curl_setopt($curlHandle, CURLOPT_URL, 'https://webhook.homey.app/63c2b40013a8.../weerupdate?tag=zon');
    } else {
        curl_setopt($curlHandle, CURLOPT_URL, 'https://webhook.homey.app/63c2b40013a8.../weerupdate?tag=geenzon');
    }
    $content = curl_exec($curlHandle);

```

and receive webhook with one card for clear and one for not clear weather, like:

 ![eventweerupdatezon](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/c/8/c82ca47bcb441daeda8e4ef891932c45f0c82fa6.jpeg)

…where you can do whatever you wish to do if the sun shines (or not).

works like a charm;-)

---

<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:** [February 17, 2023, 5:42pm UTC](https://community.homey.app/t/how-update-variable-using-api/76496/33 "2023-02-17T17:42:15Z")

</div>

I still can’t figure out how you run the script with Homey cloud. It hasn’t homeyscript available?

---

<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 17, 2023, 5:45pm UTC](https://community.homey.app/t/how-update-variable-using-api/76496/34 "2023-02-17T17:45:22Z")

</div>

It’s a PHP script anyway.

---

<div class="post-metadata">

**Author:** ![Ruud\_Naastepad](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/ruud_naastepad/32/67675_2.png) [@Ruud\_Naastepad](https://community.homey.app/u/Ruud_Naastepad)\
**Post date:** [February 17, 2023, 6:25pm UTC](https://community.homey.app/t/how-update-variable-using-api/76496/35 "2023-02-17T18:25:03Z")

</div>

😄

If someone would be interested in the actual full and neatified PHP code including errorhandling just let me know.

This post was just about figuring out if an external API can be used to pass info to Homey bridge (not Pro), as far as I’m concerned. The provided PHP code was just to show that two things need to be done in a script: query an API and pass response in some form to Homey webhook server.

---

<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:** [February 18, 2023, 4:44am UTC](https://community.homey.app/t/how-update-variable-using-api/76496/36 "2023-02-18T04:44:41Z")

</div>

All cool, but I was under the impression you wanted to accomplish this all on Homey cloud/bridge… I don’t know your skills and other equipment/servers, and you kept it a mystery until the last bit 😆

[Previous page](https://community.homey.app/t/how-update-variable-using-api/76496.md?page=1)
