Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/ansible/ansible-examples.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSean Cavanaugh <sean@cavanaugh.pro>2019-05-22 23:05:44 +0300
committerGitHub <noreply@github.com>2019-05-22 23:05:44 +0300
commit945b1c5d39475ac61047a58355f533b337e45589 (patch)
treee6ee7737f5965fb9b6ee9a81d187a30cb0545664
parenta319fc11ef888c81a763279a3bfef4da01d6d409 (diff)
parentff882ce1764dbbc98b42089310e7329fe4d787af (diff)
Merge pull request #252 from IPvSean/IPvSean/2019demo
uploading demo of phillips hue
-rw-r--r--phillips_hue/README.md71
-rw-r--r--phillips_hue/ansible.cfg22
-rw-r--r--phillips_hue/ansible_colors.yml51
-rw-r--r--phillips_hue/effect.yml39
-rw-r--r--phillips_hue/hosts1
-rw-r--r--phillips_hue/hue.gifbin0 -> 35729911 bytes
-rw-r--r--phillips_hue/on_off.yml52
-rw-r--r--phillips_hue/register.yml29
-rw-r--r--phillips_hue/username_info.yml5
9 files changed, 270 insertions, 0 deletions
diff --git a/phillips_hue/README.md b/phillips_hue/README.md
new file mode 100644
index 0000000..d25fbe1
--- /dev/null
+++ b/phillips_hue/README.md
@@ -0,0 +1,71 @@
+## HUE LIGHTS WITH ANSIBLE
+
+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 :)
+
+## PREREQUISITES
+
+- Ansible
+ - [Install Guide](https://www.amazon.com/gp/product/B07D1J5QC7/ref=oh_aui_detailpage_o01_s00?ie=UTF8&psc=1)
+- Phillips Hue Lights
+ - 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)
+- IP Address of the Hue Controller (known as the bridge).
+ - 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.
+
+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.
+
+## SETUP
+
+### Step 1
+
+Open up the username_info.yml file and change the IP Address to the IP address of your Hue bridge.
+
+```nano username_info.yml```
+
+```yaml
+---
+username: FmAXS-XpnLIxBQwyaw1tkIw04YzIt-BIG4YL0v8X
+ip_address: "192.168.86.30"
+body_info:
+ devicetype: "Ansible!"
+```
+
+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.
+
+### Step 2
+
+For the Playbooks to work correctly you must run the `register.yml` playbook first->
+
+```ansible-playbook register.yml```
+
+The playbook will run and then prompt you on the terminal window->
+```
+[PROMPT USER TO PRESS PHYSICAL BUTTON HUE HUB]
+Press the button on the hub now...:
+```
+
+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.
+
+This will save a unique Hue generated authorized user to `username_info` which will look like a long string of text (e.g. `elY1xx9p5twUBYDjELgMUuQT99kLaVqGT1p0eDrl`).
+
+## PLAYBOOKS
+
+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`.
+
+ - `on_off.yml `
+
+ This playbook turns off all bulbs that are registered to the Hue bridge. It then prompts the user, and then turns them back on.
+ - `ansible_colors.yml `
+
+ 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).
+
+ - `effect.yml`
+
+ 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.
+
+## DEMONSTRATION
+
+![hue screencast](hue.gif)
+
+## License
+
+GPLv3
diff --git a/phillips_hue/ansible.cfg b/phillips_hue/ansible.cfg
new file mode 100644
index 0000000..11d6dd4
--- /dev/null
+++ b/phillips_hue/ansible.cfg
@@ -0,0 +1,22 @@
+# config file for ansible -- http://ansible.com/
+# ==============================================
+
+# nearly all parameters can be overridden in ansible-playbook
+# or with command line flags. ansible will read ANSIBLE_CONFIG,
+# ansible.cfg in the current working directory, .ansible.cfg in
+# the home directory or /etc/ansible/ansible.cfg, whichever it
+# finds first
+
+[defaults]
+
+# some basic default values...
+
+inventory = hosts
+forks = 50
+host_key_checking = False
+retry_files_enabled = False
+no_target_syslog = False
+callback_whitelist = time
+
+[ssh_connection]
+scp_if_ssh = True
diff --git a/phillips_hue/ansible_colors.yml b/phillips_hue/ansible_colors.yml
new file mode 100644
index 0000000..8daae66
--- /dev/null
+++ b/phillips_hue/ansible_colors.yml
@@ -0,0 +1,51 @@
+- hosts: localhost
+ gather_facts: no
+ connection: local
+ vars:
+ ansible_mango:
+ "on": true
+ "bri": 254
+ "xy": [0.5701, 0.313]
+ ansible_pool:
+ "on": true
+ "bri": 254
+ "xy": [0.1593, 0.2522]
+ tasks:
+ - name: INCLUDE UNIQUE USERNAME FROM REGISTER.YML
+ include_vars:
+ file: username_info.yml
+
+ - name: GRAB HUE LIGHT INFORMATION
+ uri:
+ url: "http://{{ip_address}}/api/{{username}}"
+ method: GET
+ body: '{{body_info|to_json}}'
+ register: light_info
+
+ - name: TURN LIGHTS TO MANGO
+ uri:
+ url: "http://{{ip_address}}/api/{{username}}/lights/{{item}}/state"
+ method: PUT
+ body: '{{ansible_mango|to_json}}'
+ loop: "{{ range(1, light_info.json.lights | length + 1)|list }}"
+
+ - name: TURN LIGHTS TO POOL
+ uri:
+ url: "http://{{ip_address}}/api/{{username}}/lights/{{item}}/state"
+ method: PUT
+ body: '{{ansible_pool|to_json}}'
+ loop: "{{ range(1, light_info.json.lights | length + 1)|list }}"
+
+ - name: TURN LIGHTS TO MANGO
+ uri:
+ url: "http://{{ip_address}}/api/{{username}}/lights/{{item}}/state"
+ method: PUT
+ body: '{{ansible_mango|to_json}}'
+ loop: "{{ range(1, light_info.json.lights | length + 1)|list }}"
+
+ - name: TURN LIGHTS TO POOL
+ uri:
+ url: "http://{{ip_address}}/api/{{username}}/lights/{{item}}/state"
+ method: PUT
+ body: '{{ansible_pool|to_json}}'
+ loop: "{{ range(1, light_info.json.lights | length + 1)|list }}"
diff --git a/phillips_hue/effect.yml b/phillips_hue/effect.yml
new file mode 100644
index 0000000..a1f1b28
--- /dev/null
+++ b/phillips_hue/effect.yml
@@ -0,0 +1,39 @@
+- hosts: localhost
+ gather_facts: no
+ connection: local
+ vars:
+ ansible_effect:
+ "on": true
+ "effect": "colorloop"
+ ansible_none:
+ "on": true
+ "effect": "none"
+ tasks:
+ - name: INCLUDE UNIQUE USERNAME FROM REGISTER.YML
+ include_vars:
+ file: username_info.yml
+
+ - name: GRAB HUE LIGHT INFORMATION
+ uri:
+ url: "http://{{ip_address}}/api/{{username}}"
+ method: GET
+ body: '{{body_info|to_json}}'
+ register: light_info
+
+ - name: TURN LIGHTS INTO COLORLOOP EFFECT
+ uri:
+ url: "http://{{ip_address}}/api/{{username}}/lights/{{item}}/state"
+ method: PUT
+ body: '{{ansible_effect|to_json}}'
+ loop: "{{ range(1, light_info.json.lights | length + 1)|list }}"
+
+ # Pause for 10 seconds
+ - pause:
+ seconds: 5
+
+ - name: TURN LIGHTS INTO COLORLOOP EFFECT
+ uri:
+ url: "http://{{ip_address}}/api/{{username}}/lights/{{item}}/state"
+ method: PUT
+ body: '{{ansible_none|to_json}}'
+ loop: "{{ range(1, light_info.json.lights | length + 1)|list }}"
diff --git a/phillips_hue/hosts b/phillips_hue/hosts
new file mode 100644
index 0000000..2fbb50c
--- /dev/null
+++ b/phillips_hue/hosts
@@ -0,0 +1 @@
+localhost
diff --git a/phillips_hue/hue.gif b/phillips_hue/hue.gif
new file mode 100644
index 0000000..5c67492
--- /dev/null
+++ b/phillips_hue/hue.gif
Binary files differ
diff --git a/phillips_hue/on_off.yml b/phillips_hue/on_off.yml
new file mode 100644
index 0000000..c3c807d
--- /dev/null
+++ b/phillips_hue/on_off.yml
@@ -0,0 +1,52 @@
+- hosts: localhost
+ gather_facts: no
+ connection: local
+
+ vars:
+ off_state:
+ "on": false
+ on_state:
+ "on": true
+
+ tasks:
+ - name: INCLUDE UNIQUE USERNAME FROM REGISTER.YML
+ include_vars:
+ file: username_info.yml
+
+ - name: GRAB HUE LIGHT INFORMATION
+ uri:
+ url: "http://{{ip_address}}/api/{{username}}"
+ method: GET
+ body: '{{body_info|to_json}}'
+ register: light_info
+
+ - name: PRINT DATA TO TERMINAL WINDOW
+ debug:
+ var: light_info.json.lights
+
+ - name: PRINT AMOUNT OF LIGHTS TO TERMINAL WINDOW
+ debug:
+ msg: "THERE ARE {{light_info.json.lights | length}} HUE LIGHTS PRESENT"
+
+ # - name: PRINT OUT LOOP VARS
+ # debug:
+ # msg: "http://{{ip_address}}/api/{{username}}/lights/{{item}}/state"
+ # loop: "{{ range(1, light_info.json.lights | length + 1)|list }}"
+
+ - name: TURN LIGHTS OFF
+ uri:
+ url: "http://{{ip_address}}/api/{{username}}/lights/{{item}}/state"
+ method: PUT
+ body: '{{off_state|to_json}}'
+ loop: "{{ range(1, light_info.json.lights | length + 1)|list }}"
+
+ - name: PROMPT USER TO TURN BACK ON
+ pause:
+ prompt: "Turn them back on?"
+
+ - name: TURN LIGHTS ON
+ uri:
+ url: "http://{{ip_address}}/api/{{username}}/lights/{{item}}/state"
+ method: PUT
+ body: '{{on_state|to_json}}'
+ loop: "{{ range(1, light_info.json.lights | length + 1)|list }}"
diff --git a/phillips_hue/register.yml b/phillips_hue/register.yml
new file mode 100644
index 0000000..38a7d6c
--- /dev/null
+++ b/phillips_hue/register.yml
@@ -0,0 +1,29 @@
+- hosts: localhost
+ gather_facts: no
+ connection: local
+
+ tasks:
+
+ - name: PROMPT USER TO PRESS PHYSICAL BUTTON HUE HUB
+ pause:
+ prompt: "Press the button on the hub now..."
+
+ - name: INCLUDE IP ADDRESS FROM username_info.yml
+ include_vars:
+ file: username_info.yml
+
+ - name: GRAB UNIQUE USERNAME
+ uri:
+ url: "http://{{ip_address}}/api"
+ method: POST
+ body: '{{body_info|to_json}}'
+ register: username_info
+
+ - name: PRINT DATA TO TERMINAL WINDOW
+ debug:
+ var: username_info.json
+ - lineinfile:
+ path: "./username_info.yml"
+ regexp: '^username'
+ insertafter: EOF
+ line: 'username: {{username_info.json[0]["success"]["username"]}}'
diff --git a/phillips_hue/username_info.yml b/phillips_hue/username_info.yml
new file mode 100644
index 0000000..7df8c11
--- /dev/null
+++ b/phillips_hue/username_info.yml
@@ -0,0 +1,5 @@
+---
+username: elY1xx9p5twUBYDjELgMUuQT99kLaVqGT1p0eDrl
+ip_address: "192.168.86.30"
+body_info:
+ devicetype: "Ansible!"