Controlling Philips Hue Lamps

Last updated 2 months ago

Introduction

This app is designed for Philips Hue lights. It allows you to control lights in different rooms or groups by voice using Snips. The app supports color selection, built-in scenes, and brightness control.

More functionality, for e.g. controlling each individual light or handling more bespoke scenes, please follow the Developer section in order to customise your own bundle and action code.

Usage of the documentation

If you are a maker, you may only read the following sections:

If you are a developer, all the parts above will be helpful, but you may also want to check the following:

Installation

Installation with Sam (assistant and action code)

We assume that you already have the Sam command line interface installed on your computer. If not, please check out to the Quick Start Raspberry Pi to get you up and running.

Run the following command to install your assistant and its action code:

sam install assistant

Then select the assistant which contains Smart Light - Hue bundle.

Installation with Sam (action code only)

If you are a Snips app developer, you may need to only install the action code.

Run the following command to install it from snips-skill-hue-pro git repo:

sam install actions -g https://github.com/snipsco/snips-skill-hue-pro.git

Then sam will take care of the dependencies installation and put the app at the right path:/var/lib/snips/skills/. It will be run by the snips-skill-server component automatically.

Manual installation (Action code only)

If you do not run your snips assistant on an armv7l or armv6l microcomputer,sam will not work. But you can manually clone the skill repo to /var/lib/snips/skills/ directory where the snips-skill-server is based on. Please go to:

cd /var/lib/snips/skills/

Then run:

git clone https://github.com/snipsco/snips-skill-hue-pro.git

Go to the action code directory

cd snips-skill-hue-pro

Install:

To be able to run the following code, you need to have virtualenv installed, if not please install it by checking this page

sudo ./setup.sh

User configuration

When installing the App using sam. You will be asked to input some configuration information. If you did not install it by sam, you can edit the config file manually by doing:

sudo nano /var/lib/snips/skills/snips-skill-hue/config.ini

hostname

This entity value should be the IP address / hostname of you Hue bridge. You can find this in the official Hue mobile APP.

APP bundle design

When designing an intent, please follow the clean code rules. Which means that you should name your intent and its slots properly so that a third person can also understand it by reading it.

This table represent the bundle design of Smart Light - Hue :

Intent

Slots

Description

turnOn

house_room

Turn on the light

turnOff

house_room

Turn off the light

setBrightness

house_room percent

Set the brightness

setColor

house_room color

Set the color

setScene

house_room scene

Set the light mode

shiftUp

house_room percent

Increase the brightness

shiftDown

house_room percent

Decrease the brightness

APP action code

Files requiredCode file organisation

There are mainly two parts of code required. One for handling the intents from the mqtt bus, which is usually named action-{{action_name}.py. The other one is usually the class of the devices, which contains all the functional methods/ attributes.

In this example, we have action-philips_hue.py and snipshue.py. Moreover, there is a snipshelpers directory, which contains config_parser and thread_handler class. These two classes are provided in the action code template within action-{{action_name}.py file.

All the necessary files are listed below:

└── snips-skill-hue-pro
├── action-philips_hue.py # main handler for intents
├── config.ini # app configuration
├── requirements.txt # requirements for dependencies
├── setup.sh # setup script
├── snipshelpers # useful tools
│ ├── __init__.py
│ ├── config_parser.py
│ ├── singleton.py
│ └── thread_handler.py
└── snipshue # snipshue class
├── __init__.py
├── hue_setup.py
└── snipshue.py

Default handling

As we may have different default situation of slots, this section will explain the strategy used by this action code. There is no specific rule to handle this, so please refer to your use-case when making your design choices.

There are typically 3 different slot types in this bundle design. Different types need to be handled in different ways.

§house_room (All the intents)

This slot exists in all the intents for this bundle, it is used to indicate the location of where the action should happen.

Most users will set their room light by pronouncing the room name in the query, so we have made the following chart to explain what will happen under different scenarios.

If you are targeting the user who is using the satellite configuration, the default house_room value also can be the siteId of the audio device if they would like to properly name all the satellites.

§percent (shiftUp, shiftDown)

This slot exists in the intent shiftUp and shiftDown, it is used to indicate the amount of the brightness change.

We can say both "please make room lighter" or "turn up the light by 50%" (based on the current brightness, add 50% more brightness). Here is the chart explaining it:

§percent (setBrightness), scene, color

All of these 3 slots exist in the intent for setting this information, so it does not make sense to have a setColor / setScene / setBrightness intent detected but there is no key info provided. To handle this kind of defaults, we have decided that we should either make this slot mandatory when creating the intent (slot required) or just ignore it as nothing would happen.

Troubleshooting

1) Why the light does not perform like I expected?

We have designed some strategy to handle the default situation. If the light is not operating as you expect, this is normal. If you want to know how the light would perform by default, please check here.

2) Why the lights control does not work at all?

If the action code is not correctly detected/ performed by snips-skill-server, nothing will happen even though an intent is detected.

Please use ssh login to the raspberry device, manually then first stop the snips-skill-server:

sudo systemctl stop snips-skill-server

Then restart it:

snips-skill-server -vvv

Now you are able to watch the log of the action code. Please follow its prompt to fix the issue.

3) Why snips can't understand my room's name?

Snips is designed to understand both trained data & non-trained queries. But for the moment it can only understand the pre-trained data. Which means that when we design the voice bundle, we can not 'pre-know' what is your preferred room's name. Therefore when you pronounce your personal room's name Snips may not get it since all the trained data are more general words, like living room, bedroom, kitchen etc..

For instance if you have multi-bedroom for your kids, you may want to name the rooms like this:Oliver's bedroom and Olivia's bedroom instead of bedroom. To achieve it, we recommend that you log in the snips console, that you fork the bundle and add your own customised data and training examples. Then after the new deployment, you will have personalised voice assistant.

General problem

When setting up a new assistant and its action code, you may meet different problems from time to time. This section provides a simple reference to help you figure the potential problems.

Please usesam to check if all services are running properly. (If you have sam installed on your laptop)

sam status

If everything works well, you should get:

Connected to device raspi-hue.local
OS version ................... Raspbian GNU/Linux 9 (stretch)
Installed assistant .......... hue
Language ..................... en
Hotword ...................... hey_snips
ASR engine ................... snips
Status ....................... Live
Service status:
snips-analytics .............. 0.58.3 (running)
snips-asr .................... 0.58.3 (running)
snips-audio-server ........... 0.58.3 (running)
snips-dialogue ............... 0.58.3 (running)
snips-hotword ................ 0.58.3 (running)
snips-nlu .................... 0.58.3 (running)
snips-skill-server ........... 0.58.3 (running)
snips-tts .................... 0.58.3 (running)

If one or multiples of those services aren't running as expected, please ssh to login. Then use systemctl command to check its status. For example, in order to check the status of snips-audio-server:

systemctl status snips-audio-server

More information about general troubleshooting, please check out this page.