Skip to content
This repository was archived by the owner on May 27, 2024. It is now read-only.

Commit 945b1c5

Browse files
authored
Merge pull request #252 from IPvSean/IPvSean/2019demo
uploading demo of phillips hue
2 parents a319fc1 + ff882ce commit 945b1c5

File tree

9 files changed

+270
-0
lines changed

9 files changed

+270
-0
lines changed

phillips_hue/README.md

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
## HUE LIGHTS WITH ANSIBLE
2+
3+
This README written on September 5th, 2018 by [Sean Cavanaugh](https://github.com/ipvsean). The original username feature seems to have been disabled since James Cammarata wrote the original modules and URI based Playbooks in 2016. I updated my Phillips Hue Bulbs to the latest firmware as of this post and made some new Playbooks based off the original Cammarata URI playbooks :)
4+
5+
## PREREQUISITES
6+
7+
- Ansible
8+
- [Install Guide](https://www.amazon.com/gp/product/B07D1J5QC7/ref=oh_aui_detailpage_o01_s00?ie=UTF8&psc=1)
9+
- Phillips Hue Lights
10+
- The kit used for this particular demo was a Philips Hue White and Color Ambiance A19 60W Equivalent LED Smart Light Bulb Starter Kit. The link on Amazon can [be found here](https://www.amazon.com/gp/product/B07D1J5QC7/ref=oh_aui_detailpage_o01_s00?ie=UTF8&psc=1)
11+
- IP Address of the Hue Controller (known as the bridge).
12+
- Most home networks will allow you to pin a static IP address to the Hue bridge. I use Google Wifi and this took a couple clicks on my iPhone.
13+
14+
Also make sure that you can control the lights normally from the free iPhone or Android app. This may require you adding the serial numbers manually which can be found on the side of the bulbs.
15+
16+
## SETUP
17+
18+
### Step 1
19+
20+
Open up the username_info.yml file and change the IP Address to the IP address of your Hue bridge.
21+
22+
```nano username_info.yml```
23+
24+
```yaml
25+
---
26+
username: FmAXS-XpnLIxBQwyaw1tkIw04YzIt-BIG4YL0v8X
27+
ip_address: "192.168.86.30"
28+
body_info:
29+
devicetype: "Ansible!"
30+
```
31+
32+
Ignore the `username` and `body_info` fields. The `username` is automatically generated by the Hue bridge and updated in this file in the following step. The `body_info` is just used to register this particular computer (the computer you are executing Ansible from) in the following step, the `devicetype` could be anything. Please refer to the [getting started guide](https://www.developers.meethue.com/documentation/getting-started) from Phillips for more information.
33+
34+
### Step 2
35+
36+
For the Playbooks to work correctly you must run the `register.yml` playbook first->
37+
38+
```ansible-playbook register.yml```
39+
40+
The playbook will run and then prompt you on the terminal window->
41+
```
42+
[PROMPT USER TO PRESS PHYSICAL BUTTON HUE HUB]
43+
Press the button on the hub now...:
44+
```
45+
46+
You must physically touch the button on the Hue bridge (the top of it where the word PHILLIPS is clearly printed) as a security measure. Press enter on the terminal window after you have pressed the Hue bridge button.
47+
48+
This will save a unique Hue generated authorized user to `username_info` which will look like a long string of text (e.g. `elY1xx9p5twUBYDjELgMUuQT99kLaVqGT1p0eDrl`).
49+
50+
## PLAYBOOKS
51+
52+
There are three demo playbooks included. All three of them use the [include_vars](https://docs.ansible.com/ansible/latest/modules/include_vars_module.html) task to grab the IP address and username information from `username_info.yml`. Run them with `ansible-playbook <name>.yml` e.g. `ansible-playbook on_off.yml`.
53+
54+
- `on_off.yml `
55+
56+
This playbook turns off all bulbs that are registered to the Hue bridge. It then prompts the user, and then turns them back on.
57+
- `ansible_colors.yml `
58+
59+
This playbook cycles all bulbs between Ansible mango and Ansible pool a couple times You can find the [official Ansible colors and logos here](https://www.ansible.com/logos).
60+
61+
- `effect.yml`
62+
63+
This playbook takes all bulbs and puts them into a mode called colorloop where the bulbs will randomly cycle colors. This will happen for 5 seconds then it will turn off the effect.
64+
65+
## DEMONSTRATION
66+
67+
![hue screencast](hue.gif)
68+
69+
## License
70+
71+
GPLv3

phillips_hue/ansible.cfg

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# config file for ansible -- http://ansible.com/
2+
# ==============================================
3+
4+
# nearly all parameters can be overridden in ansible-playbook
5+
# or with command line flags. ansible will read ANSIBLE_CONFIG,
6+
# ansible.cfg in the current working directory, .ansible.cfg in
7+
# the home directory or /etc/ansible/ansible.cfg, whichever it
8+
# finds first
9+
10+
[defaults]
11+
12+
# some basic default values...
13+
14+
inventory = hosts
15+
forks = 50
16+
host_key_checking = False
17+
retry_files_enabled = False
18+
no_target_syslog = False
19+
callback_whitelist = time
20+
21+
[ssh_connection]
22+
scp_if_ssh = True

phillips_hue/ansible_colors.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
- hosts: localhost
2+
gather_facts: no
3+
connection: local
4+
vars:
5+
ansible_mango:
6+
"on": true
7+
"bri": 254
8+
"xy": [0.5701, 0.313]
9+
ansible_pool:
10+
"on": true
11+
"bri": 254
12+
"xy": [0.1593, 0.2522]
13+
tasks:
14+
- name: INCLUDE UNIQUE USERNAME FROM REGISTER.YML
15+
include_vars:
16+
file: username_info.yml
17+
18+
- name: GRAB HUE LIGHT INFORMATION
19+
uri:
20+
url: "http://{{ip_address}}/api/{{username}}"
21+
method: GET
22+
body: '{{body_info|to_json}}'
23+
register: light_info
24+
25+
- name: TURN LIGHTS TO MANGO
26+
uri:
27+
url: "http://{{ip_address}}/api/{{username}}/lights/{{item}}/state"
28+
method: PUT
29+
body: '{{ansible_mango|to_json}}'
30+
loop: "{{ range(1, light_info.json.lights | length + 1)|list }}"
31+
32+
- name: TURN LIGHTS TO POOL
33+
uri:
34+
url: "http://{{ip_address}}/api/{{username}}/lights/{{item}}/state"
35+
method: PUT
36+
body: '{{ansible_pool|to_json}}'
37+
loop: "{{ range(1, light_info.json.lights | length + 1)|list }}"
38+
39+
- name: TURN LIGHTS TO MANGO
40+
uri:
41+
url: "http://{{ip_address}}/api/{{username}}/lights/{{item}}/state"
42+
method: PUT
43+
body: '{{ansible_mango|to_json}}'
44+
loop: "{{ range(1, light_info.json.lights | length + 1)|list }}"
45+
46+
- name: TURN LIGHTS TO POOL
47+
uri:
48+
url: "http://{{ip_address}}/api/{{username}}/lights/{{item}}/state"
49+
method: PUT
50+
body: '{{ansible_pool|to_json}}'
51+
loop: "{{ range(1, light_info.json.lights | length + 1)|list }}"

phillips_hue/effect.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
- hosts: localhost
2+
gather_facts: no
3+
connection: local
4+
vars:
5+
ansible_effect:
6+
"on": true
7+
"effect": "colorloop"
8+
ansible_none:
9+
"on": true
10+
"effect": "none"
11+
tasks:
12+
- name: INCLUDE UNIQUE USERNAME FROM REGISTER.YML
13+
include_vars:
14+
file: username_info.yml
15+
16+
- name: GRAB HUE LIGHT INFORMATION
17+
uri:
18+
url: "http://{{ip_address}}/api/{{username}}"
19+
method: GET
20+
body: '{{body_info|to_json}}'
21+
register: light_info
22+
23+
- name: TURN LIGHTS INTO COLORLOOP EFFECT
24+
uri:
25+
url: "http://{{ip_address}}/api/{{username}}/lights/{{item}}/state"
26+
method: PUT
27+
body: '{{ansible_effect|to_json}}'
28+
loop: "{{ range(1, light_info.json.lights | length + 1)|list }}"
29+
30+
# Pause for 10 seconds
31+
- pause:
32+
seconds: 5
33+
34+
- name: TURN LIGHTS INTO COLORLOOP EFFECT
35+
uri:
36+
url: "http://{{ip_address}}/api/{{username}}/lights/{{item}}/state"
37+
method: PUT
38+
body: '{{ansible_none|to_json}}'
39+
loop: "{{ range(1, light_info.json.lights | length + 1)|list }}"

phillips_hue/hosts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
localhost

phillips_hue/hue.gif

34.1 MB
Loading

phillips_hue/on_off.yml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
- hosts: localhost
2+
gather_facts: no
3+
connection: local
4+
5+
vars:
6+
off_state:
7+
"on": false
8+
on_state:
9+
"on": true
10+
11+
tasks:
12+
- name: INCLUDE UNIQUE USERNAME FROM REGISTER.YML
13+
include_vars:
14+
file: username_info.yml
15+
16+
- name: GRAB HUE LIGHT INFORMATION
17+
uri:
18+
url: "http://{{ip_address}}/api/{{username}}"
19+
method: GET
20+
body: '{{body_info|to_json}}'
21+
register: light_info
22+
23+
- name: PRINT DATA TO TERMINAL WINDOW
24+
debug:
25+
var: light_info.json.lights
26+
27+
- name: PRINT AMOUNT OF LIGHTS TO TERMINAL WINDOW
28+
debug:
29+
msg: "THERE ARE {{light_info.json.lights | length}} HUE LIGHTS PRESENT"
30+
31+
# - name: PRINT OUT LOOP VARS
32+
# debug:
33+
# msg: "http://{{ip_address}}/api/{{username}}/lights/{{item}}/state"
34+
# loop: "{{ range(1, light_info.json.lights | length + 1)|list }}"
35+
36+
- name: TURN LIGHTS OFF
37+
uri:
38+
url: "http://{{ip_address}}/api/{{username}}/lights/{{item}}/state"
39+
method: PUT
40+
body: '{{off_state|to_json}}'
41+
loop: "{{ range(1, light_info.json.lights | length + 1)|list }}"
42+
43+
- name: PROMPT USER TO TURN BACK ON
44+
pause:
45+
prompt: "Turn them back on?"
46+
47+
- name: TURN LIGHTS ON
48+
uri:
49+
url: "http://{{ip_address}}/api/{{username}}/lights/{{item}}/state"
50+
method: PUT
51+
body: '{{on_state|to_json}}'
52+
loop: "{{ range(1, light_info.json.lights | length + 1)|list }}"

phillips_hue/register.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
- hosts: localhost
2+
gather_facts: no
3+
connection: local
4+
5+
tasks:
6+
7+
- name: PROMPT USER TO PRESS PHYSICAL BUTTON HUE HUB
8+
pause:
9+
prompt: "Press the button on the hub now..."
10+
11+
- name: INCLUDE IP ADDRESS FROM username_info.yml
12+
include_vars:
13+
file: username_info.yml
14+
15+
- name: GRAB UNIQUE USERNAME
16+
uri:
17+
url: "http://{{ip_address}}/api"
18+
method: POST
19+
body: '{{body_info|to_json}}'
20+
register: username_info
21+
22+
- name: PRINT DATA TO TERMINAL WINDOW
23+
debug:
24+
var: username_info.json
25+
- lineinfile:
26+
path: "./username_info.yml"
27+
regexp: '^username'
28+
insertafter: EOF
29+
line: 'username: {{username_info.json[0]["success"]["username"]}}'

phillips_hue/username_info.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
username: elY1xx9p5twUBYDjELgMUuQT99kLaVqGT1p0eDrl
3+
ip_address: "192.168.86.30"
4+
body_info:
5+
devicetype: "Ansible!"

0 commit comments

Comments
 (0)