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?
Uservariable Delete
Moderator: leecollings
-
- Posts: 12
- Joined: Tuesday 26 July 2016 13:31
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 3.4834
- Location: France
- Contact:
Uservariable Delete
José
Domoticz raspberry pi
Version 3.4834
Domoticz raspberry pi
Version 3.4834
- Egregius
- Posts: 2592
- Joined: Thursday 09 April 2015 12:19
- Target OS: Linux
- Domoticz version: v2024.7
- Location: Beitem, BE
- Contact:
Re: Uservariable Delete
json.htm?type=command¶m=getuservariables gives all variables
json.htm?type=command¶m=deleteuservariable&idx=1 deletes the first
So, grab all variables, run thru the array and find the idx.
json.htm?type=command¶m=deleteuservariable&idx=1 deletes the first
So, grab all variables, run thru the array and find the idx.
-
- Posts: 12
- Joined: Tuesday 26 July 2016 13:31
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 3.4834
- Location: France
- Contact:
Re: Uservariable Delete
Thanks for you help Egregius
But how to get the result of the json query, and how to grab it ?
But how to get the result of the json query, and how to grab it ?
José
Domoticz raspberry pi
Version 3.4834
Domoticz raspberry pi
Version 3.4834
- Egregius
- Posts: 2592
- Joined: Thursday 09 April 2015 12:19
- Target OS: Linux
- Domoticz version: v2024.7
- Location: Beitem, BE
- Contact:
Re: Uservariable Delete
Code: Select all
<?php
define('api',"http://127.0.0.1:8084/");
//Grab the variables
$variables = json_decode(curl(api."json.htm?type=command¶m=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¶m=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;}
-
- Posts: 12
- Joined: Tuesday 26 July 2016 13:31
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 3.4834
- Location: France
- Contact:
Re: Uservariable Delete
Hello, Thanks for your answer,
But, I do not work in PHP, I work in LUA.
Have you a grab example in LUA?
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
Domoticz raspberry pi
Version 3.4834
Who is online
Users browsing this forum: No registered users and 1 guest