How to configure and enable 3rd party webhooks? (crosspost)

Hi,

I seek some assistance from a community member who is willing to assist me creating webhooks and PHP scripts in IPS.
I want to integrate LOQED in IPS using webhooks. I’ve successfully integrated LOQED with the IFTTT module in IPS, only passing on web request from IPS to IFTTT to LOQED and vice versa. I assume it must be possible to do exactly the same without IFTTT.

The LOQED webhook service supports three different actions; Open, Lock, and Unlock. These actions can be triggered by three different URLs (URLs have been sanatized):

Right now I’m using three different IFTTT instances in IPS, one for each action.
I was thinking about creating an integer variable with 3 possible values, Open, Lock, and Unlock. Each value would trigger the corresponding URL.

Status updates are POSTed by the LOQED webhook service. I suppose it must be possible to use a webhook in IPS. At the moment I have the following configured in IFTTT (and corresponding IFTTT instance in IPS):

https://999999.ipmagic.de/hook/IFTTT
POST
application/json
{"username":"user","password":"password","objectid":999999,"values":{"JsonPayload":"<<<{{JsonPayload}}>>>"}}

An update of the ‚JsonPayload‘ string variable triggers the following PHP script in IPS:

<?php
$json = GetValue(999999);
$json_arr = json_decode($json, true);
$value1 =  explode(',', $json_arr['value1']);
$value1_arr = array();
foreach($value1 as $v){
    $t = explode(":", $v);
    $value1_arr[trim($t[0])] = trim($t[1]);
}
//print_r($value1_arr);
$state = $value1_arr['State'];
SetValue(999999, $state);
?>

How can I configure webhooks and PHP scripts in IPS to integrate LOQED directly without using IFTTT?
I hope someone can put me in the right direction. Thanks!
(crosspost)
Cheers,
Dennis.

Call me stupid, but even with a similar question in another thread as an example I don’t know what to do (but I’m one step further :wink:):

HTTP-Aufruf aus einer Internetanwendung empfangen und verarbeiten - IP-Symcon 4.x/5.x/6.x / Skripte, PHP, SQL (Fragen) - IP-Symcon Community

Using the test script I get the following results:

WebHook GET | Array()
WebHook POST | Array()
WebHook IPS | Array([SENDER] => WebHook
[THREAD] => 99
[SELF] => 999999)
WebHook RAW | {"key_name_user": "null", "key_account_email": "null", "requested_state": "DAY_LOCK", "event_type": "STATE_CHANGED_LATCH", "value2": "null", "key_name_admin": "null", "value1": "LockID: 999999, KeyID: null, State: DAY_LOCK", "value3": "null", "key_account_name": "null", "key_local_id": "null", "lock_id": 999999}

The value of „WebHook RAW“ is the same as „JsonPayload“ in the 1st post.

I’ve managed to create a webhook PHP script that updates the status, with help from some community members:

<?php
// STATUS LOG
IPS_LogMessage("WebHook IPS", print_r($_IPS, true));
IPS_LogMessage("WebHook RAW", file_get_contents("php://input"));

// WebHook RAW
$LOQED_JSON_Data = file_get_contents("php://input");

// Parse JSON Data
$LOQED_JSON_Data_Array = json_decode($LOQED_JSON_Data, true);
$value1 = explode(',', $LOQED_JSON_Data_Array['value1']);
$value1_array = array();
foreach($value1 as $v){
    $t = explode(":", $v);
    $value1_array[trim($t[0])] = trim($t[1]);
    }
$state = $value1_array['State'];

// List $value1_array
//print_r($value1_array);

// Set LOQED Status
SetValue(999999,$state);
?>

So now I still need to find a way to create a variable with three possible values (open, lock, unlock) that HTTPS GET the URLs in the 1st post and make it available in WebFront.

Hi Dennis,

i’ll drop you this code, which will create the variable for you

function CreateVariableByIdent($id, $ident, $name, $type, $profile = "")
		{
			 $vid = @IPS_GetObjectIDByIdent($ident, $id);
			 if($vid === false) {
				 $vid = IPS_CreateVariable($type);
				 IPS_SetParent($vid, $id);
				 IPS_SetName($vid, $name);
				 IPS_SetIdent($vid, $ident);
				 if($profile != "")
					IPS_SetVariableCustomProfile($vid, $profile);
			 }
			 return $vid;
		}

Additionally you want to call those URLs using either cURL oder file_get_contents.

Did you have a look at those functions already?

paresy

Hi Paresy,

I did take a look at cURL briefly, but couldn’t find instructions (or php script I could use as an example). Another community member offered some help. (link)