PHP code example of rutgerkirkels / domoticz-php

1. Go to this page and download the library: Download rutgerkirkels/domoticz-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

rutgerkirkels / domoticz-php example snippets


// Initialize the Domoticz library with the hostname of the Domoticz machine.
// If you didn't set login credentials, you can leave the username and password
// attributes empty.

$client = new \rutgerkirkels\DomoticzPHP\Client('http://YOUR_DOMOTICZ_MACHINE:PORT', <USERNAME>, <PASSWORD>);

// Get all lights and switches
$lightsAndSwitches = $client->getDevices('light');

// Get the status of a device
$device = $client->getDeviceByIdx(<idx>);
echo $device->getStatus();

// When the device is a dimmer, get the current set level in percentages (return false of not a dimmer)
$level = $device->getLevel();

// Initiate a controller for this dimmer
$dimmerController = (new \rutgerkirkels\DomoticzPHP\Factories\ControllerFactory($device))->get();

// and turn it on...
$dimmerController->turnOn();

// and off again...
$dimmerController->turnOff();