New to Indigo Domotics... Question about the GET and POST

Posted on
Mon Jun 15, 2020 5:56 pm
ppespepe offline
Posts: 49
Joined: May 27, 2020

New to Indigo Domotics... Question about the GET and POST

Hello everyone!

Hope you are having a great one. I'm wondering if there is a way I can trigger a POST or GET from an action of a virtual switch?

Is that feasible with Indigo? If an apple script is needed for this, can you guys point me to an example on how to trigger said script and use the reply to populate some variables inside the system?

Kindest Regards!

PP

Posted on
Mon Jun 15, 2020 6:34 pm
FlyingDiver offline
User avatar
Posts: 7189
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: New to Indigo Domotics... Question about the GET and POS

ppespepe wrote:
Hello everyone!

Hope you are having a great one. I'm wondering if there is a way I can trigger a POST or GET from an action of a virtual switch?

Is that feasible with Indigo? If an apple script is needed for this, can you guys point me to an example on how to trigger said script and use the reply to populate some variables inside the system?

Kindest Regards!

PP


Super simple Python script. Just put this in an Action group and use that as the action of the virtual switch.

Code: Select all
import requests
r = requests.get('https://api.github.com/events')
r = requests.post('https://httpbin.org/post', data = {'key':'value'})


Obviously, you only need line (2) or (3), not both. How to interpret the response depends on the format of the data.

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Mon Jul 06, 2020 2:01 pm
ppespepe offline
Posts: 49
Joined: May 27, 2020

Re: New to Indigo Domotics... Question about the GET and POS

Thank you so much FlyingDiver!!!

That worked great!

Just another silly newbie question... If I were to send a Get or Put request, How can I parse the response mostly in jSON format and how can I use said information?

As an example, I did this on another HA software I play with:

'Toilet Light OFF
Dim http,URL
URL = "http://192.168.1.71/relay/0?turn=off"
Set http = CreateObject("Msxml2.XMLHTTP")
http.open "GET",URL,False
http.send
strJson = http.responseText

Set j = ParseJson(strJson)
ison = j.ison
SetVariable "Toilet-light-ON", ison

'Wscript.echo Result
'--------------------------------------------------------
Function ParseJson(strJson)
Set html = CreateObject("htmlfile")
Set window = html.parentWindow
window.execScript "var json = " & strJson, "JScript"
Set ParseJson = window.json
End Function
'----------------------------------------------------

There I can send some of the variables inside the jSON to the HA software for me to be able to update Status and things... How can I achieve something similar here with Indigo?

Thanks!

PP

Posted on
Mon Jul 06, 2020 2:21 pm
FlyingDiver offline
User avatar
Posts: 7189
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: New to Indigo Domotics... Question about the GET and POS

Here's a sample from a different thread:

Code: Select all
import requests

result = requests.get("http://192.168.1.71/relay/0?turn=off")
response = result.json()
indigo.variable.updateValue("Toilet-light-ON", response)

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Mon Jul 06, 2020 2:28 pm
DaveL17 offline
User avatar
Posts: 6743
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: New to Indigo Domotics... Question about the GET and POS

You might also consider taking a look at the GhostXML plugin--which handles both XML and JSON. Here's a couple links:

GhostXML Plugin via the Indigo Plugin Store
GhostXML Plugin Wiki

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Mon Jul 06, 2020 6:58 pm
ppespepe offline
Posts: 49
Joined: May 27, 2020

Re: New to Indigo Domotics... Question about the GET and POS

Wow thank you!

I will definitely give it a look. And thanks for the examples! :)

Posted on
Sun Jul 12, 2020 8:05 pm
ppespepe offline
Posts: 49
Joined: May 27, 2020

Re: New to Indigo Domotics... Question about the GET and POS

Tested the Ghost XML and it works beautiful... trouble is, now I don't know how to use the info it collects.

For instance, I'm using Ghost to do a GET request to a Hubitat Elevation Hub's Samsung zigbee arrival/presence tag. Now I need to create a virtual device to monitor presence with a payload of present and not present and perhaps a small icon just like a motion sensor but I can't find how to... Just On/Off virtual devices... Do you know how to create a device?

BTW, I could do a schedule with the following script:

First I create a variable on python console: indigo.variable.create("PepePresence", "not present")

Screen Shot 2020-07-12 at 20.52.57.png
Screen Shot 2020-07-12 at 20.52.57.png (335.88 KiB) Viewed 2579 times


The script:

import requests
r = requests.get('http://192.168.X.XX/apps/api/193/devices/1?access_token=123c1234-da12-12f6-1f0a-123da7e1f123')
response = r.json()
indigo.server.log(response['attributes'][1]['currentValue'])
indigo.variable.updateValue(586491695,response['attributes'][1]['currentValue'])

Screen Shot 2020-07-12 at 20.54.21.png
Screen Shot 2020-07-12 at 20.54.21.png (158.34 KiB) Viewed 2579 times


And it works beautiful but same problem... how can I create a device to show the status?

Thanks!!

PP

Posted on
Sun Jul 12, 2020 8:31 pm
DaveL17 offline
User avatar
Posts: 6743
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: New to Indigo Domotics... Question about the GET and POS

There's no need to create a device to track the value--you've already got one. The data from the payload are parsed into device states for the device doing the downloading. Below the device details panel in indigo is the Custom States panel. There you will see all the data from the API you're querying. The state from your example should be something on the order of 'attributes_1_currentValue' or something like that.

You should be able to use those states for Triggers, Control Pages and the like.

Screen Shot 2020-07-12 at 9.30.16 PM.png
Screen Shot 2020-07-12 at 9.30.16 PM.png (27.69 KiB) Viewed 2576 times

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 8 guests