I’m trying to build a simple integration with link-tap. It has an open API as an example I can control the device through the following post.
How would I go about executing this on a switch on? I looked at the custom http momentary switch device, although POST is an available option, how would I configure the parameters?
Many Thanks,
D
curl -d "username=YourUsername&apiKey=YourApiKey&gatewayId=YourGatewayId&taplinkerId=YourTaplinkerId&action=true&duration=20&eco=true&ecoOn=1&ecoOff=2" -X POST https://www.link-tap.com/api/activateInstantMode
But that should only matter to the system sending the request, right? The URL is the same, whether it's a get a or post. Throw it into RM and try to send it as POST and see. I'm pretty sure that the post part just affects the requesting system not waiting for a response.
I’m not an expert and thus do not know how to properly format a POST request using this driver. I probably ported this from someone’s ST DTH. IIRC, I created this driver to work with the Harmony-API NodeJS server before I wrote the webSockets integration.
Wish I could be more help. You should be able to find some other groovy examples that issue POST commands and properly format the Headers and Body. You can then modify this driver to suit your needs.
I don’t have a LinkTap so no way to test but you should be able to create a virtual device and then create a RM 3.0 rule that triggers based on the state change of this switch. Here is an example:
From RM I don't believe that is possible. You would have to do that in the driver. If you look at the HTTP Get switch driver, you can see an example:
def on() {
if (logEnable) log.debug "Sending on GET request to [${settings.onURI}]"
try {
httpGet(settings.onURI) { resp ->
if (resp.success) {
sendEvent(name: "switch", value: "on", isStateChange: true)
}
if (logEnable)
if (resp.data) log.debug "${resp.data}"
if (autooff)
runIn(delay, off)
}
} catch (Exception e) {
log.warn "Call to on failed: ${e.message}"
}
}
the "catch exception" would be where the error occurred and the "resp.success" is it working. If the system is going to respond with some type of data, that would be in the resp.data field, which could then be parsed however you want.
Sorry for a newbie question. I have a similar problem as described in this thread, but can't figure out how I can install this virtual device? I.e, where can I find the code?
The above screenshot you posted is not from a device. It is actually from Rule Machine. That's why it is hard to find!
You can use a Virtual Switch device (simply add a virtual device and assign it the virtual switch driver, no new code required.) Then, in Rule Machine, create a Rule that is triggered by the Virtual Switch changing. Within the Actions of that rule, add a HTTP action for ON and and another for OFF.
Thank you! for the quick response. I'm getting closer
Question now is what kind of syntax I need in the 'Enter body for POST' box.
Tried some stuff but can't get it to work...
This is the curl command that works today:
curl -X POST http://192.168.1.2/api/light -H 'API-Key: hinotori' -H 'Content-Type: application/json' -d '{"brightness": 36, "state": "ON"}'
-H is header in curl (-H 'API-Key: hinotori'). -d is the data portion of the command and that is what you would put in the body for the post ('{"brightness": 36, "state": "ON"}'). However, AFAIK, you can't modify headers with RM so it probably wouldn't work anyhow.
The only way I can think of to get curl command to work is by either creating a custom app in Groovy (which is actually really simple to do) OR use something like NodeRed or NodeJS to craft and send the command using the event socket output from Hubitat.