1.0.4 • Published 11 months ago

node-hue v1.0.4

Weekly downloads
-
License
MIT
Repository
github
Last release
11 months ago

Node-hue

A minimalist approch to wrap the hue clip v2 api using pure javascript. There are no model objects and helper methods. The result of the calls are provided as they are returned by the hue bridge. The API methods return promises and can be used together with await.

Getting started

A hue user key is needed to access the bridge. This key can be obtained by following the advice here. Automatic discovery using mDNS is not supported. You need to know your hue bridge IP or have a valid host dns entry.

Example: List all lights

This example lists all lights with their ID and ui name.

const hueApi = require('node-hue');
run = async () => {
    const hue = hueApi.connect();
    let lights = await hue.getLights();
    lights.forEach(light => {
        console.log(light.id+"\t"+light.metadata.name);
    });
}
run();

Executing this example may produce a result like this one:

227cf111-a326-4d27-8d9f-c3e2e464b1a9    Kitchen lamp
c81f9556-b504-417d-8aee-2275b71a761d    Bedroom lamp
17c0bd7e-d7c3-43d6-9c85-a440ffa50930    Garden lamp

Using events

The library hue-push-client is used to retrieve the hue bridge notifications (server side events).

Example: React on events

This example lists endlessly for events emitted by the hue bridge.

const hueApi = require('node-hue');
run = async () => {
    const listener = (event) => {
        console.log(JSON.stringify(event,1,1));
    }
    const hue=hueApi.connect( {
        eventListener : listener   // The eventlistener is given as option
    });
}
run();

More examples can be found in the examples folder.

API connect options

The connect method accepts these options.

PropertyDescription
hostHostname or address of you hue bridge. Can also be set by the enviroment variable HUE_HOST and defaults to hue.
keyAPI access key. Can also be set by the enviroment variable HUE_KEY.
eventListenerThe event listener callback. A method with one parameter for the data.
logA custom log implementation, that provides the functions trace, debug, info, warn and error.

Environment variables

Environment variableDescriptionDefault
HUE_HOSTHostname or address of you hue bridge.hue
HUE_KEYAPI access key.
LOG_LEVELLog level : TRACE,DEBUG,INFO,WARN,ERRORINFO

API reference

This API reference is generated from the list of supported resources provided by the hue api. It should cover all methods that are provided by the clip V2 api. If you want to access the hue api description, you need a developer login at the meethue side.

MethodDescriptionHTTP methodHue api link
getLights()Get all light(s).GETAPI Link
getLight(id)Get single light.GETAPI Link
createLight(data)Create light.POSTAPI Link
setLight(id,data)Update light.PUTAPI Link
getScenes()Get all scene(s).GETAPI Link
getScene(id)Get single scene.GETAPI Link
createScene(data)Create scene.POSTAPI Link
setScene(id,data)Update scene.PUTAPI Link
deleteScene(id)Delete scene.DELETEAPI Link
getRooms()Get all room(s).GETAPI Link
getRoom(id)Get single room.GETAPI Link
createRoom(data)Create room.POSTAPI Link
setRoom(id,data)Update room.PUTAPI Link
deleteRoom(id)Delete room.DELETEAPI Link
getZones()Get all zone(s).GETAPI Link
getZone(id)Get single zone.GETAPI Link
createZone(data)Create zone.POSTAPI Link
setZone(id,data)Update zone.PUTAPI Link
deleteZone(id)Delete zone.DELETEAPI Link
getBridgeHomes()Get all bridge_home(s).GETAPI Link
getBridgeHome(id)Get single bridge_home.GETAPI Link
getGroupedLights()Get all grouped_light(s).GETAPI Link
getGroupedLight(id)Get single grouped_light.GETAPI Link
setGroupedLight(id,data)Update grouped_light.PUTAPI Link
getDevices()Get all device(s).GETAPI Link
getDevice(id)Get single device.GETAPI Link
setDevice(id,data)Update device.PUTAPI Link
deleteDevice(id)Delete device.DELETEAPI Link
getBridges()Get all bridge(s).GETAPI Link
getBridge(id)Get single bridge.GETAPI Link
setBridge(id,data)Update bridge.PUTAPI Link
deleteBridge(id)Delete bridge.DELETEAPI Link
getDevicePowers()Get all device_power(s).GETAPI Link
getDevicePower(id)Get single device_power.GETAPI Link
setDevicePower(id,data)Update device_power.PUTAPI Link
getZigbeeConnectivitiys()Get all zigbee_connectivitiy(s).GETAPI Link
getZigbeeConnectivitiy(id)Get single zigbee_connectivitiy.GETAPI Link
setZigbeeConnectivitiy(id,data)Update zigbee_connectivitiy.PUTAPI Link
getZgpConnectivitys()Get all zgp_connectivity(s).GETAPI Link
getZgpConnectivity(id)Get single zgp_connectivity.GETAPI Link
setZgpConnectivity(id,data)Update zgp_connectivity.PUTAPI Link
getZigbeeDeviceDiscoverys()Get all zigbee_device_discovery(s).GETAPI Link
getZigbeeDeviceDiscovery(id)Get single zigbee_device_discovery.GETAPI Link
setZigbeeDeviceDiscovery(id,data)Update zigbee_device_discovery.PUTAPI Link
getMotions()Get all motion(s).GETAPI Link
getMotion(id)Get single motion.GETAPI Link
setMotion(id,data)Update motion.PUTAPI Link
getTemperatures()Get all temperature(s).GETAPI Link
getTemperature(id)Get single temperature.GETAPI Link
setTemperature(id,data)Update temperature.PUTAPI Link
getLightLevels()Get all light_level(s).GETAPI Link
getLightLevel(id)Get single light_level.GETAPI Link
setLightLevel(id,data)Update light_level.PUTAPI Link
getButtons()Get all button(s).GETAPI Link
getButton(id)Get single button.GETAPI Link
setButton(id,data)Update button.PUTAPI Link
getRelativeRotarys()Get all relative_rotary(s).GETAPI Link
getRelativeRotary(id)Get single relative_rotary.GETAPI Link
setRelativeRotary(id,data)Update relative_rotary.PUTAPI Link
getBehaviorScripts()Get all behavior_script(s).GETAPI Link
getBehaviorScript(id)Get single behavior_script.GETAPI Link
getBehaviorInstances()Get all behavior_instance(s).GETAPI Link
getBehaviorInstance(id)Get single behavior_instance.GETAPI Link
createBehaviorInstance(data)Create behavior_instance.POSTAPI Link
setBehaviorInstance(id,data)Update behavior_instance.PUTAPI Link
deleteBehaviorInstance(id)Delete behavior_instance.DELETEAPI Link
getGeofenceClients()Get all geofence_client(s).GETAPI Link
getGeofenceClient(id)Get single geofence_client.GETAPI Link
createGeofenceClient(data)Create geofence_client.POSTAPI Link
setGeofenceClient(id,data)Update geofence_client.PUTAPI Link
deleteGeofenceClient(id)Delete geofence_client.DELETEAPI Link
getGeolocations()Get all geolocation(s).GETAPI Link
getGeolocation(id)Get single geolocation.GETAPI Link
setGeolocation(id,data)Update geolocation.PUTAPI Link
getEntertainmentConfigurations()Get all entertainment_configuration(s).GETAPI Link
getEntertainmentConfiguration(id)Get single entertainment_configuration.GETAPI Link
createEntertainmentConfiguration(data)Create entertainment_configuration.POSTAPI Link
setEntertainmentConfiguration(id,data)Update entertainment_configuration.PUTAPI Link
deleteEntertainmentConfiguration(id)Delete entertainment_configuration.DELETEAPI Link
getEntertainments()Get all entertainment(s).GETAPI Link
getEntertainment(id)Get single entertainment.GETAPI Link
setEntertainment(id,data)Update entertainment.PUTAPI Link
getHomekits()Get all homekit(s).GETAPI Link
getHomekit(id)Get single homekit.GETAPI Link
setHomekit(id,data)Update homekit.PUTAPI Link
getMatters()Get all matter(s).GETAPI Link
getMatter(id)Get single matter.GETAPI Link
setMatter(id,data)Update matter.PUTAPI Link
getMatterFabrics()Get all matter_fabric(s).GETAPI Link
getMatterFabric(id)Get single matter_fabric.GETAPI Link
deleteMatterFabric(id)Delete matter_fabric.DELETEAPI Link
getSmartScenes()Get all smart_scene(s).GETAPI Link
getSmartScene(id)Get single smart_scene.GETAPI Link
deleteSmartScene(id)Delete smart_scene.DELETEAPI Link
getResources()Get all resources.GETAPI Link
close()Closes the hue connection. Removes a eventually registered event listener.
getDocumentation()Returns this API documentation as markdown.

Motivation

There are tons of hue api libraries around for the usage with node.js. But most provide just a subset of the available features or are based on the v1 api. They are often written in typescript and using data models. May be convenient in the usage, but missing flexibility. This library is handling the http request/response while keeping the original response value and without wrapping or changing the json data expected by the hue bridge. The dependency list should be short. For a home automation service I need fast access to buttons, temperature sensors, motion sensors, lights together with the possibility to get push events from the bridge. I didn't found it in the existing libraries - so this one was born.

1.0.4

11 months ago

1.0.3

12 months ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago