Uservariable Delete

Moderator: leecollings

Post Reply
jjdom
Posts: 12
Joined: Tuesday 26 July 2016 13:31
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.4834
Location: France
Contact:

Uservariable Delete

Post by jjdom »

Hello everyone

I want to delete a UserVariable
So I'll use the appropriate Json query.

But this query needs the Idx of UserVariable.

This variable was created with a lua script. So if another script wants to delete it, does not know its id. He only knows his name.

How can I get this Idx with his name?
José
Domoticz raspberry pi
Version 3.4834
User avatar
Egregius
Posts: 2592
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Uservariable Delete

Post by Egregius »

json.htm?type=command&param=getuservariables gives all variables
json.htm?type=command&param=deleteuservariable&idx=1 deletes the first

So, grab all variables, run thru the array and find the idx.
jjdom
Posts: 12
Joined: Tuesday 26 July 2016 13:31
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.4834
Location: France
Contact:

Re: Uservariable Delete

Post by jjdom »

Thanks for you help Egregius

But how to get the result of the json query, and how to grab it ?
José
Domoticz raspberry pi
Version 3.4834
User avatar
Egregius
Posts: 2592
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Uservariable Delete

Post by Egregius »

Code: Select all

<?php
define('api',"http://127.0.0.1:8084/");
//Grab the variables
$variables = json_decode(curl(api."json.htm?type=command&param=getuservariables"),true);
//Check if the result isn't empty
if(!empty($variables['result'])){
    //loop thru all variables
    foreach($variables['result'] as $variable){
        //if variable value equals ... remove it.
        if($variable['Value']=="first") curl(api."json.htm?type=command&param=deleteuservariable&idx=".$variable['idx']);
    }
}
function curl($url){$headers=array('Content-Type: application/json',);$ch=curl_init();curl_setopt($ch,CURLOPT_URL,$url);curl_setopt($ch,CURLOPT_HTTPHEADER,$headers);curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);curl_setopt($ch, CURLOPT_FRESH_CONNECT, TRUE);$data=curl_exec($ch);curl_close($ch);return $data;}
jjdom
Posts: 12
Joined: Tuesday 26 July 2016 13:31
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.4834
Location: France
Contact:

Re: Uservariable Delete

Post by jjdom »

Hello, Thanks for your answer,

But, I do not work in PHP, I work in LUA.
Have you a grab example in LUA?
José
Domoticz raspberry pi
Version 3.4834
User avatar
Egregius
Posts: 2592
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Uservariable Delete

Post by Egregius »

Nope :P
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest