Homey Community Forum

Simple HTTP Connector For Flows

Hi @volodeev, welcome on the forum!
Do you know how long the sid is valid?
With my app its not possible to do two calls stepping through a login/authentication within one flow. At least it’s not done yet.
But… what if we do the login call, put the response sid in a Better Logic variable and reuse that (via a token) in the second request. Is that worth trying?

Hi. Yes, I know that it’s not easy. I am not a JavaScript programmer. Therefore, I can not use HomeyScript. Help me please.

I am thinking of breaking this task down into 3 stages:

  1. post request with authorization to receive SID
  2. GET request https://lk.saures.ru/api/company/flats?sid=ea533f69-7880-4938-9fdf-522d2a929ee5
  3. GET request https://lk.saures.ru/api/meter/meters?sid=ea533f69-7880-4938-9fdf-522d2a929ee5&flat_id=4731

Hi @Erik!
The SID through Postman does not change unless cookies are deleted. With a new authorization, the SID changes, but the old SID also continues to operate.

I like your idea of ​​putting the SID in a Better Logic variable and reusing it. But … I can’t extract the SID, because I don’t know how to send an authorization request correctly. Help me please.

I am thinking of breaking this task down into 3 stages:

  1. post request with authorization to receive SID
    001
  2. GET request https://lk.saures.ru/api/company/flats?sid=ea533f69-7880-4938-9fdf-522d2a929ee5
    002
  3. GET request https://lk.saures.ru/api/meter/meters?sid=ea533f69-7880-4938-9fdf-522d2a929ee5&flat_id=4731

Hi, I’m new to this app.
It looks promissing in the description - but I seem to lack some examples.
I have just tried to do some simple http commands, and the Homey just responds with “Ok”, but no actions are performed, neither on devices nor on flows. A small toturial or examples would be nice.
Thanks
Casper

Hi @CasperD! There are a lot examples posted on the forums. Have you checked the full app store description? (also available here: https://github.com/irritanterik/homey-http-request-actions/blob/master/README.md).
What do you want to achieve with the flow you created?

Is it possible to get through a http request your actual coördinates. For example https://www.gps-coordinaten.nl/waar-ben-ik or google maps. Would be very interesting. For me it would be a way to update rain information when i am bycicling on a different place as where Homey stays. And yes I don’t always carry Homey with me😛
I have no clue how to do this

Hi @Erik
The README, got me to where I am now, but the examples are not complete, the documentation discusses an event, but what is that in Homey environment, Homey has: Devices, Flows, Triggers.

Assuming that I have a device ‘Lamp’,
I make a http request :
http:///api/app/com.internet/Lamp
http:///api/app/com.internet/Lamp/on
Or any deviation, all responds with “Ok”, no action performed on the ‘Lamp’
Assuming that I made a flow ‘X’ (Trigger is ‘This flow started’)
http:///api/app/com.internet/X
Responds “Ok” but flow is not executed

And u also made the flow to receive the GET request like this?

I’m trying to use the Evaluate JSON condition card (C22) but I need to specify headers with the request. I dont seem to be able to get it right. I have tried the following in the query parameters field:

  • {“Authorization”:“Bearer somerandomstring”}
  • {‘Authorization’:‘Bearer somerandomstring’}
  • {Authorization:‘Bearer somerandomstring’}
  • {headers:{‘Authorization’:‘Bearer somerandomstring’}}
  • {headers:{Authorization:‘Bearer somerandomstring’}}

All to no avail, the app even crashes with some of these attempts. @Erik, could you explain me what I’m doing wrong and should I submit a bug due to the app crashing?

[EDIT]
I got it to work using the node http options in the URL field but only when putting some bogus json in the query parameter field. Leaving this empty causes the app to crash.

Can anyone help me how I can send a GET command with two cookies?

It is something like “https://…{Cookie=xxx=yyy; xxx =yyy}” with the cookie in the header brackets but don’t know if the default GET card will accept this syntax.

I want to send out this GET command to a server to get a reply with a JSON file which I want to store some variables in Better Logic. Without the cookies I don’t get replied with a JSON file.

Done & figured it out:
I used the advanced options and used the ’ GET JSONpath Better Logic ( A22 )’ card and made a Better Logic variable.

in the url box I added in the sample code from the above link and modified the headers box:

“headers”:{“Cookie”:“xxx=yyy; xxx=yyy”}

1 Like

Just discovered the websocket send - just what I needed to switch my Daikin heatpump on and off. Superb work. Now the question - is there any way to read the response from the send?

Thanks
Phil

Hi Phil, at this point I did not implemented a response reader or trigger based on the response.
If you could provide me with a stubbed nodejs server which mocks your heatpump responses then I will be able to add reading the ws response to the app.

I read responses via Homescript and parse the output into logic tags like this:

// read values from Sonnen battery
var url = " http://192.168.1.10/api/v1/status";
(async () => {
     const rawResponse = await fetch(url, {
        method: 'GET',
        headers: {
          'Accept': 'application/json',
          'Content-Type': 'application/json'
      },
  });
  const content = await rawResponse.json();
  //console.log(content);

  
  if (content.BatteryCharging != null) {
    await setTagValue("hstBatterieLaedt", {type: "boolean", title: "hst_Batterie_laedt"}, content.BatteryCharging);
  }

  if (content.BatteryDischarging != null) {
    await setTagValue("hstBatterieEntlaedt", {type: "boolean", title: "hst_Batterie_entlaedt"}, content.BatteryDischarging);
  }

  if (content.Consumption_W != null) {
    await setTagValue("hstConsumption_W", {type: "number", title: "hst_Hausverbrauch"}, content.Consumption_W);
    //console.log("hstConsumption_W",content.Consumption_W);
  }

  if (content.Production_W != null) {
    await setTagValue("hstProduction_W", {type: "number", title: "hst_Solarerzeugung"}, content.Production_W);
  }

if (content.RSOC != null) {
    await setTagValue("hstRSOC", {type: "number", title: "hst_Ladezustand"}, content.RSOC);
    //console.log("Ladezustand",content.RSOC);

  }

if (content.Ubat != null) {
    await setTagValue("hstUbat", {type: "number", title: "hst_Batteriespannung"}, content.Ubat);
  }

if (content.Pac_total_W != null) {
    await setTagValue("hstPac_total_W", {type: "number", title: "hst_Reglerspannung"}, content.Pac_total_W);
  }

  //var currentTemp = content.currentTemp/100;
    //var setTemp = content.currentSetpoint/100;
    //var states = Array("Comfort", "Thuis", "Slapen", "Weg");
    //var state = states[content.activeState];
    //if (content.activeState == -1) {
    //  state = "Not Set";
    //}    

})();
return true;

Thanks, but that is a regular GET request, not a websocket, is this for the same heatpump as Phil?

Hi Erick, thanks for the quick response. It may take me a little while to stub a server together, nodejs is not my speciality! However below is request and response to a number of request types. Hope this helps.
Thanks, Phil

Programming the Daikin Heatpump

Using websockets (test using chrome websocket client)

Connect to endpoint: ws://192.168.86.40/mca

To get room temperature - send:

{“m2m:rqp”:{“op”:2,“to”:"/[0]/MNAE/1/Sensor/IndoorTemperature/la",“fr”:"/TarmoTest",“rqi”:“yssyq”}}

Response looks like:

{“m2m:rsp”:{“rsc”:2000,“rqi”:“yssyq”,“to”:"/TarmoTest",“fr”:"/[0]/MNAE/1/Sensor/IndoorTemperature/la",“pc”:{“m2m:cin”:{“rn”:“0000001e”,“ri”:“0007_0000001e”,“pi”:“0007”,“ty”:4,“ct”:“20191226T152000Z”,“lt”:“20191226T152000Z”,“st”:30,“con”:22.0000000000000000}}}}

(note the “con”:22.000000000 which is the room temperature)

To find power state:

{“m2m:rqp”:{“op”:2,“to”:"/[0]/MNAE/1/Operation/Power/la",“fr”:"/TarmoTest",“rqi”:“yssyq”}}

Response:

{“m2m:rsp”:{“rsc”:2000,“rqi”:“yssyq”,“to”:"/TarmoTest",“fr”:"/[0]/MNAE/1/Operation/Power/la",“pc”:{“m2m:cin”:{“rn”:“0000001a”,“ri”:“000d_0000001a”,“pi”:“000d”,“ty”:4,“ct”:“20191226T125102Z”,“lt”:“20191226T125102Z”,“st”:26,“con”:“standby”}}}}

Or:

{“m2m:rsp”:{“rsc”:2000,“rqi”:“yssyq”,“to”:"/TarmoTest",“fr”:"/[0]/MNAE/1/Operation/Power/la",“pc”:{“m2m:cin”:{“rn”:“0000001e”,“ri”:“000d_0000001e”,“pi”:“000d”,“ty”:4,“ct”:“20191226T181546Z”,“lt”:“20191226T181546Z”,“st”:30,“con”:“on”}}}}

To find target temperature:

{“m2m:rqp”:{“op”:2,“to”:"/[0]/MNAE/1/Operation/TargetTemperature/la",“fr”:"/TarmoTest",“rqi”:“yssyq”}}

Response:

{“m2m:rsp”:{“rsc”:2000,“rqi”:“yssyq”,“to”:"/TarmoTest",“fr”:"/[0]/MNAE/1/Operation/TargetTemperature/la",“pc”:{“m2m:cin”:{“rn”:“0000004c”,“ri”:“000f_0000004c”,“pi”:“000f”,“ty”:4,“ct”:“20191226T060002Z”,“lt”:“20191226T060002Z”,“st”:76,“con”:30.0000000000000000}}}}

Outdoor temperature:

{“m2m:rqp”:{“op”:2,“to”:"/[0]/MNAE/1/Sensor/OutdoorTemperature/la",“fr”:"/TarmoTest",“rqi”:“yssyq”}}

Response:

{“m2m:rsp”:{“rsc”:2000,“rqi”:“yssyq”,“to”:"/TarmoTest",“fr”:"/[0]/MNAE/1/Sensor/OutdoorTemperature/la",“pc”:{“m2m:cin”:{“rn”:“00002086”,“ri”:“0008_00002086”,“pi”:“0008”,“ty”:4,“ct”:“20191226T175944Z”,“lt”:“20191226T175944Z”,“st”:8326,“con”:9.0000000000000000}}}}

Turning unit on, off, and standby. First on:

{“m2m:rqp”:{“op”:1,“to”:"/[0]/MNAE/1/Operation/Power",“fr”:"/S",“rqi”:“qwxxl”,“ty”:4,“pc”:{“m2m:cin”:{“con”:“on”,“cnf”:“text/plain:0”}}}}

{“m2m:rsp”:{“rsc”:2001,“rqi”:“qwxxl”,“to”:"/S",“fr”:"/[0]/MNAE/1/Operation/Power"}}

Now off: (not sure this is a good idea!)

{“m2m:rqp”:{“op”:1,“to”:"/[0]/MNAE/1/Operation/Power",“fr”:"/S",“rqi”:“qwxxl”,“ty”:4,“pc”:{“m2m:cin”:{“con”:“off”,“cnf”:“text/plain:0”}}}}

{“m2m:rsp”:{“rsc”:4005,“rqi”:“qwxxl”,“to”:"/S",“fr”:"/[0]/MNAE/1/Operation/Power"}}

And standby:

{“m2m:rqp”:{“op”:1,“to”:"/[0]/MNAE/1/Operation/Power",“fr”:"/S",“rqi”:“qwxxl”,“ty”:4,“pc”:{“m2m:cin”:{“con”:“standby”,“cnf”:“text/plain:0”}}}}

{“m2m:rsp”:{“rsc”:2001,“rqi”:“qwxxl”,“to”:"/S",“fr”:"/[0]/MNAE/1/Operation/Power"}}

Setting the target temperature:

{“m2m:rqp”:{“op”:1,“to”:"/[0]/MNAE/1/Operation/TargetTemperature",“fr”:"/S",“rqi”:“qwxxl”,“ty”:4,“pc”:{“m2m:cin”:{“con”:27,“cnf”:“text/plain:0”}}}}

{“m2m:rsp”:{“rsc”:2001,“rqi”:“qwxxl”,“to”:"/S",“fr”:"/[0]/MNAE/1/Operation/TargetTemperature"}}

See:

https://community.athom.com/t/daikin-ai/158/109

https://community.openhab.org/t/how-to-integrate-daikin-altherma-lt-heat-pump/16488/16

https://community.openenergymonitor.org/t/hack-my-heat-pump-and-publish-data-onto-emoncms/2551/35

That’s not the same as mine. Some Daikin kit (mainly air conditioners) use standard GET/POST. The low-temperature heat-pumps use a different LAN controller that is only accessible via websocket.

Thanks

Phil

I think I’m trying to do something simple, but I’m also pretty simple since I can’t get it to work.

I have a pihole in my network and I want to temporarily disable it via a http request:
http://pi.hole/admin/api.php?disable=<#seconds>&auth=

Am I at least looking in the right direction?

Nevermind … got it working. Just a simple get was sufficient. Tried this yesterday and it didn’t work, tried it now and it did?

I have a brain melt down. Am trying to set a better logic value out of a json. Have done several similar flows, but for this it never gets through. What should the JSONpath be if I want to set a logic value out of the ‘description’-string in this json? Think I have tried all possible alternatives.

I would expect $.messages[0].description