Skip to content

Instantly share code, notes, and snippets.

@jjensn
Last active January 18, 2017 17:04
Show Gist options
  • Select an option

  • Save jjensn/f4f2a29c20c3f4f9e2ca71759d3bb75a to your computer and use it in GitHub Desktop.

Select an option

Save jjensn/f4f2a29c20c3f4f9e2ca71759d3bb75a to your computer and use it in GitHub Desktop.

Revisions

  1. jjensn revised this gist Jan 18, 2017. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions rubix_cube.yaml
    Original file line number Diff line number Diff line change
    @@ -2,6 +2,7 @@
    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
  2. jjensn created this gist Jan 18, 2017.
    34 changes: 34 additions & 0 deletions rubix_cube.yaml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,34 @@
    - alias: "Magic Cube"
    hide_entity: false
    trigger:
    - platform: state
    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] }}