se/pilight

Library to call Pilight (currently pilight-send) from php.

v0.1-beta 2013-12-11 08:03 UTC

This package is not auto-updated.

Last update: 2020-07-06 05:26:10 UTC


README

#pilight

Latest Stable Version SensioLabsInsight

Library to call pilight (currently via pilight-send) from php.

Dev branch is master branch.

Build Status

Table of Contents
  1. Installation
  2. Usage

Installation

The recommended way to install is through Composer.

{
    "require": {
        "se/pilight": "dev-master"
    }
}

Basic usage

Require the composer autload file and import the namespace.

require_once __DIR__.'/vendor/autoload.php';

use \SE\Component\Pilight;

Send

$sender =  new Pilight\Sender();
// or set a custom ip and port
$sender =  new Pilight\Sender($host = '129.168.2.1', $port = 6535);

$protocol = 'elro';
$arguments = array(
    's' => 31,
    'u' => 1,
);

$device = new Pilight\Device($protocol, $arguments);
// or add the arguments later via setArguments
$device->setArguments($arguments);

// turn it on
$device->addArgument('t');

// send it!
$sender->send($device);

If you need root permissions to call pilight-send, call setSudo(true) on $sender.

$sender->setSudo(true);
$sender->send($device);

You can add the pilight-send executable to your sudoers configuration to make it callable via sudo without the need to enter a password. This is in case your pilight-send needs to be called via sudo rights you can get some unexpected output during runtime if setting it not.

$ sudo nano /etc/sudoers.d/pilight

Contents:

www-data ALL= NOPASSWD: /usr/local/sbin/pilight-send
pi ALL= NOPASSWD: /usr/local/sbin/pilight-send
<REPLACE YOU USER> ALL= NOPASSWD: /usr/local/sbin/pilight-send