Giter VIP home page Giter VIP logo

shelly-php-client's Introduction

shelly-php-client

You can use this library to access the HTTP API of a Shelly device. You can find the official API documentation here.

Installation

Use composer

composer require gared/shelly-php-client

Getting started

Configure client

$client = new \ShellyClient\HTTP\Client('http://192.168.1.10');

If you have configured login credentials you have to create the client like this:

$client = new \ShellyClient\HTTP\Client('http://shellyuser:[email protected]');

Get current power usage

$meter = $client->getMeter(new \ShellyClient\Model\Request\MeterRequest());
$power = $meter->getPower();
echo "Current power usage: " . $power;

Power shelly plug "on"

$client->getRelay(0, \ShellyClient\Model\Request\RelayRequest::TURN_ON);

Full example

// Create new client for one device
$clientLightA = new \ShellyClient\HTTP\Client('http://192.168.1.10', 'ShellyDeviceLightA');
$clientLightB = new \ShellyClient\HTTP\Client('http://192.168.1.20', 'ShellyDeviceLightB');

// Switch device on and get relay data
$relayRequest = new \ShellyClient\Model\Request\RelayRequest();
$relayRequest->setRelayIndex(0);
$relayRequest->setTurn(\ShellyClient\Model\Request\RelayRequest::TURN_ON);
$relay = $clientLightA->getRelay($relayRequest);
// check if timer has been set
if ($relay->hasTimer()) {
    // do something
}

$meter = $clientLightA->getMeter(new \ShellyClient\Model\Request\MeterRequest());
// Get total power consumption in kW/h
$kilowattHours = $meter->getTotalInKilowattHours();
// Get last three watt per minute power consumption values
$counters = $meter->getCounters();

// Parallel call informations from device B
$power = $clientLightB->getMeter(new \ShellyClient\Model\Request\MeterRequest())->getPower();
// Get device name set above in construct
$deviceNameDeviceB = $clientLightB->getDeviceName();
// or use device name set in shelly device
$deviceNameShelly = $clientLightB->getSettings(new \ShellyClient\Model\Request\SettingsRequest())->getName();

Supported Platforms

  • You need at least PHP 7.4

Supported APIs

API Code
/light $client->getLight();
/meter $client->getMeter();
/relay $client->getRelay();
/settings $client->getSettings();
/settings/actions $client->getActions();
/settings/light $client->getSettingsLight();
/status $client->getStatus();

shelly-php-client's People

Contributors

gared avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.