ProductPromotion
Logo

Elixir

made by https://0x3d.site

GitHub - xavier/huex: Elixir client for Philips Hue connected light bulbs
Elixir client for Philips Hue connected light bulbs - xavier/huex
Visit Site

GitHub - xavier/huex: Elixir client for Philips Hue connected light bulbs

GitHub - xavier/huex: Elixir client for Philips Hue connected light bulbs

Huex

Elixir client for Philips Hue connected light bulbs.

Installation

Add Huex as a dependency in your mix.exs file.

def deps do
  [{:huex, "~> 0.8"}]
end

Also add HTTPoison as part of your applications, in your mix.exs file.

def application do
  [mod: {YourApp, []},
   applications: [:httpoison]]
end

After you are done, run mix deps.get in your shell to fetch and compile Huex.

Usage

First Connection

In order to issue queries and commands to the bridge, we need to request an authorization for a so-called devicetype (see Hue Configuration API) which is a string formatted as such: my-app#my-device.

Before requesting the authorization: you must press the link button on your bridge device to start a 30 second window during which you may request an authorization as follow:

bridge = Huex.connect("192.168.1.100") |> Huex.authorize("my-app#my-device")

# A random username is now set
IO.puts bridge.username
# YApVhLTwWUTlGJDo...

# The bridge connection is now ready for use
IO.inspect Huex.info(bridge)
# %{"config" => ...}

Subsequent Connections

Once a devicetype has been authorized with the bridge, there's no need to perform the authorization process again. In other words, you must store the generated username received set by authorize/2. With the username at hand, you can connect right away:

bridge = Huex.connect("192.168.1.100", "YApVhLTwWUTlGJDo...")

IO.inspect Huex.info(bridge)
# %{"config" => ...}

Bridge IP address discovery

You may use Huex.Discovery.discover/0 to retrieve a list of bridges on your network using SSDP:

Huex.Discovery.discover
# ["192.168.1.43"]

This optional feature depends on nerves_ssdp_client which must be added explicitly to your own application dependencies in mix.exs:

def deps do
  [{:huex, "~> 0.7"},
   {:nerves_ssdp_client, "~> 0.1"}]
end

Queries

Query functions return the message received from the bridge API.

IO.inspect Huex.info(bridge)
# %{"config" => %{"UTC" => "1970-01-01T03:00:40", "dhcp" => true,
#   "gateway" => "192.168.1.1", "ipaddress" => "192.168.1.100",
#    ...
#   "schedules" => %{}}

IO.inspect Huex.lights(bridge)
# %{"1" => %{"name" => "Lobby"}, "2" => %{"name" => "Living Room"},
#    "3" => %{"name" => "Bedroom"}}

IO.inspect Huex.light_info(bridge, 1)
# %{"modelid" => "LCT001", "name" => "Lobby",
#   ...
#   "swversion" => "66009663", "type" => "Extended color light"}

Commands

Command functions return a Huex.Bridge struct and are thus chainable.

bridge
|> Huex.turn_off(1)                                  # Turn off light 1
|> Huex.turn_on(2)                                   # Turn on light 2
|> Huex.set_color(2, {10000, 255, 255})              # HSV
|> Huex.set_color(2, {0.167, 0.04})                  # XY
|> Huex.set_color(2, Huex.Color.rgb(1, 0.75, 0.25))  # RGB (see limitations)
|> Huex.set_brightness(2, 0.75)                      # Brightness at 75%

Error Handling

For error handling, the Huex.Bridge struct has a status attribute which is either set to :ok or :error by command functions.

When an error occured, the complete error response is stored in the error attribute of the Huex.Bridge struct.

Examples

Look into the examples directory for more advanced usage examples.

Current Limitations

Color space conversion from RGB to XY currently feels a little fishy: I can't seem to get bright green or red using the given formula.

To Do

  • Reliable color conversion from RGB

Contributors

In order of appearance:

License

Copyright 2014 Xavier Defrang

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Articles
to learn more about the elixir concepts.

Resources
which are currently available to browse on.

mail [email protected] to add your project or resources here 🔥.

FAQ's
to know more about the topic.

mail [email protected] to add your project or resources here 🔥.

Queries
or most google FAQ's about Elixir.

mail [email protected] to add more queries here 🔍.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory