How update variable using API

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 :face_with_raised_eyebrow:

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

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 :wink:

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.

No, while this screenvid is made without premium.

While I was curious for a solution, I enabled a free month Premium, and could make this flow without blacked-out logics cards :blush:
But that flow idea doesn’t work.

this is the webhook card
webhookcard

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

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:


:confused:

I find some documentation here but still can’t figure out how to apply that;

tried sending this request with the make a request card

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

{
  "cloud": 4
}

after first doing register:

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:

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.

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

I don’t get it?

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.

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"

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):

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

    // 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:

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

works like a charm;-)

3 Likes

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

It’s a PHP script anyway.

1 Like

:smile:

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.

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 :laughing: