[LIVE][API][PHP] Found noname devices with x10

Moderator: Telldus

Post Reply
Manticus2
Posts: 108
Joined: Fri Mar 17, 2023 9:45 am
Location: France - Bordeaux
Contact:

[LIVE][API][PHP] Found noname devices with x10

Post by Manticus2 »

[French]

Bonjour,
J'ai cherché un moyen de savoir si mes prises télécommandées sans marque sont compatible avec mon TellStick NET

Ne pouvant pas utiliser "Protocol analyzer" avec ce modèle réseau, j'ai créé tous les interrupteurs possible avec le protocole x10 (soit 256 possibilités)

J'ai pour cela créé une class PHP : TELLDUS_LIVE
qui utilise les commandes API et qui retourne la réponse sous forme de tableau PHP
Pour faire de même, vous avez besoin de télécharger telldus-live-api.tar.gz et de remplacer le contenu du fichier index.php par celui là



[English]

Hi,
I've searched to know if my "no-name" devices are usable with my TellStick NET

We can't use "Protocol analyzer" with the network client so I've create all devices with x10 protocol (256 possibility)

I've created a PHP class : TELLDUS_LIVE
who use API telldus and return a PHP Array
To do the same, you need to download telldus-live-api.tar.gz and replace the content of index.php file by this





The class TELLDUS_LIVE

Code: Select all

CLASS TELLDUS_LIVE
{

  private $consumer;
  
  public function __construct()
  {
    $this->consumer = new HTTP_OAuth_Consumer(constant('KEY'), constant('SECRET'), $_SESSION['accessToken'], $_SESSION['accessTokenSecret']);  
  } 
  
  public function getDevices()
  {
  	$params = array('supportedMethods' => constant('TELLSTICK_TURNON') | constant('TELLSTICK_TURNOFF'));
  	return json_decode($this->consumer->sendRequest(constant('REQUEST_URI').'/devices/list', $params, 'GET')->getBody());
  }
  
  public function addDevice($idClient, $name, $protocol, $model)
  {
  	$params = array(
      'clientId'=>$idClient, 
      'name'=>$name, 
      'protocol'=>$protocol, 
      'model'=>$model
      );
  	return json_decode($this->consumer->sendRequest(constant('REQUEST_URI').'/device/add', $params, 'GET')->getBody());
  }
  
  public function removeDevice($id)
  {
  	$params = array('id'=>$id);
  	return json_decode($this->consumer->sendRequest(constant('REQUEST_URI').'/device/remove', $params, 'GET')->getBody());
  }
  
  public function turnOnDevice($id)
  {
  	$params = array('id'=>$id);
  	return json_decode($this->consumer->sendRequest(constant('REQUEST_URI').'/device/turnOn', $params, 'GET')->getBody());
  }
  
  public function turnOffDevice($id)
  {
  	$params = array('id'=>$id);
  	return json_decode($this->consumer->sendRequest(constant('REQUEST_URI').'/device/turnOff', $params, 'GET')->getBody());
  }
  
  public function upDevice($id)
  {
  	$params = array('id'=>$id);
  	return json_decode($this->consumer->sendRequest(constant('REQUEST_URI').'/device/up', $params, 'GET')->getBody());
  }
  
  public function downDevice($id)
  {
  	$params = array('id'=>$id);
  	return json_decode($this->consumer->sendRequest(constant('REQUEST_URI').'/device/down', $params, 'GET')->getBody());
  }
  
  public function stopDevice($id)
  {
  	$params = array('id'=>$id);
  	return json_decode($this->consumer->sendRequest(constant('REQUEST_URI').'/device/stop', $params, 'GET')->getBody());
  }
  
  public function setParameterDevice($id, $parameter, $value)
  {
  	$params = array(      
      'id'=>$id,
      'parameter'=>$parameter,
      'value'=>$value
      );
  	return json_decode($this->consumer->sendRequest(constant('REQUEST_URI').'/device/setParameter', $params, 'GET')->getBody());
  }
  
  public function renameDevice($id, $name)
  {
  	$params = array(      
      'id'=>$id,
      'name'=>$name
      );
  	return json_decode($this->consumer->sendRequest(constant('REQUEST_URI').'/device/setName', $params, 'GET')->getBody());
  }
  
  public function getClients()
  {                                
    echo 'in';
  	$params = array();
  	return json_decode($this->consumer->sendRequest(constant('REQUEST_URI').'/clients/list', $params, 'GET')->getBody());
  }  
  
  public function getClient($id)
  {
	  $params = array('id'=>$id);
  	return json_decode($this->consumer->sendRequest(constant('REQUEST_URI').'/client/info', $params, 'GET')->getBody());
  }  
  
}


How to use this class :

Code: Select all

// turn on all devices
$aDevices = $telldus_api->getDevices()->device;
foreach($aDevices as $device) 
{
  print_r($telldus_api->turnOnDevice($device->id));   
}


PS : I've create "Manticus2" account because I didn't received the mail to activate account with my ***@free.fr email ... Please admin, can you check ?
PS2 : Swedish and English forums, ok ... could we have an official French forum too ? :)
Image Using a Tellstick Net
Web app with group of devices : here
Map House + scheduler with sensors + Speech recognition : here
Android app : Domospeak
Post Reply