Giter VIP home page Giter VIP logo

laravel-philips-hue's Introduction

Laravel Philips Hue ๐Ÿ’ก

Introduction

I created this package for my company Ploi (https://ploi.io) to control our office lights. For example, when we receive a support ticket, our lights briefly light up green (Ploi's green color), fade out and in a bit.

This package makes it possible to easily manage your lights. Easily trigger your lights whenever a support ticket comes in, or if a new user signs up.

Syntax is as easy as this;

(new HueClient)->lights()->on(1)

Installation

Require the package first:

$ composer require cannonb4ll/laravel-philips-hue

Add this to the config/services.php file:

...

'philips-hue' => [
    'client_id' => env('PHILIPS_HUE_CLIENT_ID'),
    'client_secret' => env('PHILIPS_HUE_CLIENT_SECRET'),
    'app_id' => env('PHILIPS_HUE_APP_ID'),
    'device_id' => env('PHILIPS_HUE_DEVICE_ID'),
    'user' => env('PHILIPS_HUE_USERNAME')
]

...

Sign up (or login) to Philips Hue developer:

https://developers.meethue.com/register/

Next create a new Philips Hue App:

https://developers.meethue.com/add-new-hue-remote-api-app/

Fill in the fields accordingly to their form.

Callback URL: You will have to fill in a valid callback URL (certainly in testing enviroment, or you'd have to do this in production). This is because we will get the access and refresh tokens right away and store these in your application. In case if you are using valet, run valet share in your terminal to get an ngrok URL. Use this URL as callback in that case: {NGROK_HOST}/hue/auth/receive (Example: http://aa0515c9.ngrok.io/hue/auth/receive)

After that, note these variables:

  • AppId
  • ClientId
  • ClientSecret

We still need 2 variables, the device ID and username we will be using for your bridge.

Visit this URL and note the device ID: https://discovery.meethue.com/ (or visit https://account.meethue.com/bridge, you will see the bridge ID there too)

Fill in the details accordingly:

PHILIPS_HUE_CLIENT_ID=
PHILIPS_HUE_CLIENT_SECRET=
PHILIPS_HUE_APP_ID=
PHILIPS_HUE_DEVICE_ID=
PHILIPS_HUE_USERNAME= <-- We will get this in below step

Next we will have to create a user to be able to authenticate with your bridge.

The package will register 2 routes for you:

http://{app-url}/hue/auth

http://{app-url}/hue/auth/receive

Visit /hue/auth first to start creating a user.

You will be prompted to allow your own application permissions, accept this, you will be redirected to your own application. This is the point when you redirect that you will receive the username in the view from the package.

Grab this username (this is saved in your bridge), and also enter this in your .env file:

PHILIPS_HUE_USERNAME=

This is it! Now you should be able to execute the methods which we describe below.

You can also disable the default routes from the package by adding routes => false to your services.php file:

'philips-hue' => [
    'client_id' => env('PHILIPS_HUE_CLIENT_ID'),
    'client_secret' => env('PHILIPS_HUE_CLIENT_SECRET'),
    'app_id' => env('PHILIPS_HUE_APP_ID'),
    'device_id' => env('PHILIPS_HUE_DEVICE_ID'),
    'user' => env('PHILIPS_HUE_USERNAME'),
    'routes' => false
]

All the access data is saved in the storage/app/hue.json file, this contains the keys to access Philips Hue API.

Methods

    $hue = new HueClient();

    $hue->groups()->all();
    $hue->lights()->all();
    $hue->lights()->get(1);
    $hue->lights()->on(1);
    $hue->lights()->off(1);
    $hue->lights()->customState(1, [
        "hue" => 25500,
        "bri" =>200,
        "alert" => 'select'
    ]);

TODO

  • Ability to use without physically pressing the link button
  • Add scenes resource
  • Add schedules resource
  • Add sensors resource
  • Add rules resource
  • Add capabilities resource
  • Add exceptions
  • Add testing
  • Fix refresh token refreshing automatically
  • Update readme methods

Helpful links

https://discovery.meethue.com/

https://developers.meethue.com/develop/hue-api/

https://developers.meethue.com/my-apps/

https://account.meethue.com/apps

https://account.meethue.com/bridge

This is not an official package by Philips

laravel-philips-hue's People

Contributors

allentje avatar cannonb4ll avatar hermanbanken avatar szepeviktor avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

laravel-philips-hue's Issues

Missing Guzzle requirement in composer

The Guzzle package is missing from the composer file which will throw an error if the lib is used without installing guzzle.
The solution would be to add the requirement to the composer.json.

I can open a PR with these changes if you would like?
I would also be open to help developing the lib further if you would like some help?

ErrorCode: invalid_request - api.meethue.com

Hello,
Thanks for the great work. I have been attempting to utilize laravel-philips-hue however I'm having some odd experiences, listed out some things I've noticed in case these help identify the issue. My core issue is that when I http://{app-url}/hue/auth I receive a standard {"ErrorCode" : "invalid_request", "Error" :"The request is missing required parameters."}. Below is some areas where the issue might be occurring.

  1. composer require cannonb4ll/laravel-philips-hue is grabbing version 1.5 (Oct 5th) instead of using the current dev-master (Oct 9th - 62aaa30). Not sure if anything needs to be changed on the packagist.org site. To solve this I've been using composer require cannonb4ll/laravel-philips-hue:dev-master to force using the current master.

  2. Within HueClient.php & HueUser.php the below changes were made recently - should the "README.md" config area need to be update as well? The readme still directs that the config/services.php should use env('PHILIPS_HUE_CLIENT_ID') and env('PHILIPS_HUE_CLIENT_SECRET')....
    The example of the changes I'm referencing can be seen here
    REMOVED: env('PHILIPS_HUE_APP_ID')
    ADDED: config('services.philips-hue.app_id')

  3. I'm receiving the following message once completing the services.php file and using http://{app-url}/hue/auth
    ERROR CODE: {"ErrorCode" : "invalid_request", "Error" :"The request is missing required parameters."}
    This sadly is a very common / standard error code by Hue so I can't learn much from it. This is my main problem.

  4. As a side/bonus question: do you know of a clean and simple way to monitor the outbound post/get etc from Laravel so I can see the message it's sending when http://{app-url}/hue/auth is actioned? That way I could check the message I'm sending

Thanks again, I hope the above helps solve this issue (if it exists in the repo) or if I'm doing something wrong please point me in the better direction.

Undefined function array_first

Hi,

I've got an error inside HueUser.php on line 33. Is array_first a valid function? I searched already the Laravel and PHP docs but couldn't find any helper or something.

Add .env.example

with all required and optional variables
and some instructions

Compatibility Laravel 9 ?

Hi,

do you plan to add compatibility to laravel 9 ? It is not possible to install it as php 7 is required in composer.

Thank you for your project!

1.6 removed support for Laravel 5?

I need to upgrade to version 1.6 since i'm having trouble with the cached config for Hue when running this in an Job. This has been fixed in 1.6, but I don't see the reason why support for Laravel 5 has been dropped?

It will save me a lot of time if you can still support this version or make an 1.5.x release with this changes included, it is to much work for now to upgrade to newer Laravel.

Package not found

Hi, thanks for this package. However, the 'composer require dennissmink/laravel-philips-hue' command (as stated in the docs) is not working. Composer returns a not found notice. Running 'composer require cannonb4ll/laravel-philips-hue' does the trick.

It would be too bad to miss this package ;)

Thanks!

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.