Skip to content

3. Basic usage

Rutger Kirkels edited this page Feb 7, 2018 · 3 revisions

Instantiate the client. Username and password are optional. They're only needed if you enabled Basic Auth in the Domoticz settings.

<?php
use rutgerkirkels\DomoticzPHP\Client;

$client = new Client('<domoticz_api_host>',<username>, <password>);
?>

Devices can be retrieved as an array or as a single device (by idx):

<?php
// Get all devices
$allDevices = $client->getDevices();

// Get a single device by idx
$idx = 10; // You can lookup the IDX of a device in the Domoticz settings -> Devices
$specificDevice = $client->getDeviceByIdx($idx)

// Get the name of the device
$deviceName = $specificDevice->getName();

// Check if the device is turned on
$turnedOn = $specificDevice->isOn(); // Returns TRUE if turned on, otherwise FALSE
?>

Devices cannot be controlled directly. To control a device, you need to instantiate a controller

Clone this wiki locally