Last active
January 18, 2017 17:04
-
-
Save jjensn/f4f2a29c20c3f4f9e2ca71759d3bb75a to your computer and use it in GitHub Desktop.
Rubix Light Cube for Home Assistant
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- alias: "Magic Cube" | |
hide_entity: false | |
trigger: | |
- platform: state | |
# this is a smartthings multisensor, connected via MQTT from a SmartThings hub to Home Assistant | |
entity_id: sensor.magic_cube | |
action: | |
- service: light.turn_on | |
entity_id: | |
# any lights you want to change would go here | |
- light.yeelinklightcolor1_miio45091268local | |
- light.yeelinklightcolor1_miio46034208local | |
- light.yeelinklightcolor1_miio48212400local | |
data_template: | |
color_name: >- | |
# there is a limitation with home assistant -- you can't template out RGB colors -- have to use HTML names for now | |
{% set rgb_colors = [ 'white', 'Moccasin', 'PaleVioletRed', 'TOMATO', 'LIGHTSKYBLUE', 'MEDIUMAQUAMARINE' ] %} | |
{% set threeAxis = trigger.to_state.state.split(',')|map('int')|list %} | |
{% set x = 0 if threeAxis[0]|abs < 250 else (1 if threeAxis[0] > 0 else -1) %} | |
{% set y = 0 if threeAxis[1]|abs < 250 else (1 if threeAxis[1] > 0 else -1) %} | |
{% set z = 0 if threeAxis[2]|abs < 250 else (1 if threeAxis[2] > 0 else -1) %} | |
{% if z > 0 %} | |
{% set orientation = 0 if x == 0 and y == 0 %} | |
{% elif z < 0 %} | |
{% set orientation = 1 if x == 0 and y == 0 %} | |
{% else %} | |
{% if x > 0 %} | |
{% set orientation = 2 if y == 0 %} | |
{% elif x < 0 %} | |
{% set orientation = 3 if y == 0 %} | |
{% else %} | |
{% set orientation = 4 if y > 0 else 5 if y < 0 %} | |
{% endif %} | |
{% endif %} | |
{{ rgb_colors[orientation] }} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment