rutgerkirkels/domoticz-php

用于连接 Domoticz 的库

v0.1.1-alpha 2018-02-07 22:44 UTC

This package is auto-updated.

Last update: 2024-09-28 08:01:51 UTC


README

PHP 库,用于连接 Domoticz

使用这个库,您可以通过连接到开源家庭自动化系统 Domoticz 来使用 PHP 控制灯光、开关、恒温器和其他家庭自动化设备。

安装

php composer.phar require rutgerkirkels/domoticz-php

基本用法

// 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();