Skip to content

gdziadkiewicz/philips-hue-haskell

Repository files navigation

Philips Hue API wrapper

GitHub CI

Control Philips Hue lights with Haskell.

To get started, import the Hue module.

API Coverage

  • Lights
    • Get all lights
    • Get new lights
    • Search for lights
    • Get light attributes/state
    • Rename lights
    • Set light state
    • Delete light
  • Groups
    • Get all groups
    • Create group
    • Get group attributes
    • Set group attributes
    • Set group state
    • Delete group
  • Schedules
  • Scenes
  • Sensors
    • Get all sensors
    • Get new sensors
    • Search for sensor
    • Get sensor attributes/state/config
    • Set sensor attributes/state/config
    • Rename sensor
    • Delete sensor
  • Rules
  • Configuration
  • Resourcelinks
  • Capabilities

Running Hue actions

runHue $ do
  ls <- lights
  traverse (setLight on) ls

Examples

Slowly change a lights' color:

colorShift = do
  Just l <- lightWithName "light-on-my-desk"
  forever $ do
    setLight (on <> increaseHue 1000 <> increaseSaturation 32) l 
    liftIO $ threadDelay 500000

Change the state of multiple lights:

allLightsOn = lights >>= traverse (setLight on)
someLightsOn = do
  ls <- catMaybes <$> traverse lightWithName ["Desk", "Couch", "Kitchen"]
  traverse (setLight (on <> brightness 100)) ls 

Change the display name:

renameTo name newName = do
  Just l <- lightWithName name
  renameLight l (LightName newName)

Perform an alert:

doAlert name = do
  Just l <- lightWithName name
  setLight (alert MultipleCycles) l 

Bridge discovery and configuration

Interactive auto discovery is provided by Hue.Config.

Example with GHCi:

> stack ghci
λ import Hue.Config
λ let conf = getHueConfig
λ configIP <$> conf
It seems like there is no configuration present.
Searching for bridge, this may take a minute...
Found bridge with id: 0017881717c1
Push the button on your bridge.
BridgeIP {ipAddress = "192.168.1.100"}
λ 

About

Haskell API wrapper for Philips Hue

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •