flutter_hue 0.1.1 copy "flutter_hue: ^0.1.1" to clipboard
flutter_hue: ^0.1.1 copied to clipboard

An SDK designed for the Flutter framework that enables developers to easily integrate Philips Hue smart devices into their applications.

Flutter Hue #

Flutter Hue logo

An SDK designed for the Flutter framework that enables developers to easily integrate Philips Hue smart devices into their applications.

Note: This SDK uses Philips Hue's new API v2.

With Flutter Hue, developers can easily discover Hue bridges on the network, establish communication with them, and manipulate their connected devices. All of this is shown in the examples below. Also shown is how to chang the color of lights and turning them on and off.

Features #

Shown in this demo gif:

  1. Discover bridges on the network
  2. Establish connection with the bridges
  3. Discover the devices that are connected to the bridges
  4. Identify a light (used to let the user know what light they are configuring)
  5. Toggle a light on and off
  6. Change the color of a light

A gif demonstrating Flutter Hue in action.

Installation #

In the pubspec.yaml of your flutter project, add the following dependency:

dependencies:
 flutter_hue: ^0.1.1

Import it to each file you use it in:

import 'package:flutter_hue/flutter_hue.dart';

Usage #

Example 1 #

This example shows how to get a list of all of the IP addresses of the Philips Hue bridges on the network.

List<String> bridgeIps = await BridgeDiscoveryRepo.discoverBridges();

Example 2 #

This example shows how to establish first contact with a bridge on a device. This is what causes the bridge to create an application key for the user's device.

Warning: Any device with this key will have access to the bridge. It is meant to be kept secret.

Bridge myBridge = await BridgeDiscoveryRepo.firstContact(
  bridgeIpAddr: 192.168.1.1, // Get IP in example 1
  controller: timeoutController,
);

Example 3 #

This example shows how to find every Philips Hue device on the network.

Note: This is only for devices that are connected to a bridge that the user's device has access to (see example 2).

// Create the network object
// Get the bridges in example 2
HueNetwork myHueNetwork = HueNetwork(bridges: [bridge1, bridge2]);

// Populate the network object
await hueNetwork.fetchAll();

Example 4 #

This example shows how to change the color of a light.

// Get a light to change the color of.
// Hue Network can be found in example 3
Light myLight = myHueNetwork.lights.first;

// Set a new color that you want to change the light to
myLight = myLight
	.copyWith(
		color: myLight.color.copyWith(
			xy: LightColorXy(x: 0.6718, y: 0.3184),
		),
	);

// Send the PUT request to change the color of the ligth.
await bridge.put(myLight);

Example 5 #

This example shows how to turn multiple lights on and off.

// Figure out which group is the one you want
// Get network from example 3
Relative myRelative = myHueNetwork
	.rooms
	.first
	.services
	.firstWhere((service) => 
		service.type == ResourceType.groupedLight);

// Get the group who's ID was just found
GroupedLight myGroupedLight = myHueNetwork.groupedLights.firstWhere(
  (groupedLight) => groupedLight.id == myRelative.id,
);

// Toggle the on/off state
myGroupedLight.on.isOn = !myGroupedLight.on.isOn;

// PUT the new state
myBridge.put(myGroupedLight);

If you found this helpful, please consider donating. Thanks!

buy me a coffee      paypal      venmo



24
likes
150
pub points
51%
popularity

Publisher

verified publisherhexcat.dev

An SDK designed for the Flutter framework that enables developers to easily integrate Philips Hue smart devices into their applications.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

collection, flutter, http, multicast_dns, path_provider

More

Packages that depend on flutter_hue