Newton's Poleless Magnet

    gun-hue

    1.0.0 • Public • Published

    Gun-Hue

    Real-time updates with hue and gunDB

    What it is

    This is a tiny library that syncs hue data and lets you change your lights through gunDB.

    By using gun, you get some immediate benefits:

    • simpler API interface
    • easy real-time UI updates
    • real-time updates on other client's apps
    • offline editing
    • street cred

    How to use it

    The best way to install is from npm. Here's how:

    npm install gun-hue

    You can import this library instead of Gun (or just import it for side effects) and it'll add a new method to your gun instances called hue.

    var Gun = require('gun-hue')
    var gun = new Gun().get('hue')
     
    typeof gun.hue // 'function'

    .hue() takes an object with the IP of the bridge and your private key. To find the bridge and get an API key, read this great guide.

    gun.hue({
        domain: '192.168.1.337',
        key: 'HfBwAl0gNPUQnmqCaxZCcNfd',
    })

    Once you've done that, it'll fetch the hue state and plug it in your gun instance. That's when the fun begins! Every GET/POST command hue supports is available through gun.

    var lights = hue.path('lights')
    // Print out your available lights
    lights.map().val('Lights:')
     
    // Turn on all the lights
    lights.map().path('state.on').put(true)
     
    // Print out all the rules
    hue.get('rules').map().val('Rules:')
     
    // Listen for changes to a lights' brightness
    lights.path('5.state.bri').on(change => {
        // Brightness update!
    })
     
    // Change the brightness
    lights.path('5.state.bri').put(42)

    For more stuff you can do, I shall defer to the Philips Hue API (you may need to register to see it all).

    Warning

    If you change the state of the lights through something other than gun after it's already connected, the state won't sync. This is because this library doesn't poll the rest service.

    Once this gun issue has been resolved, I'll probably build the polling logic.

    Support

    Have questions? Either post an issue or tag me on Gitter (I usually hang out there as @PsychoLlama).

    Thanks for checking out the project! 😊

    Install

    npm i gun-hue

    DownloadsWeekly Downloads

    1

    Version

    1.0.0

    License

    MIT

    Last publish

    Collaborators

    • psychollama