Advertisement
Guest User

Untitled

a guest
Jan 17th, 2017
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. - alias: "Magic Cube"
  2. hide_entity: false
  3. trigger:
  4. - platform: state
  5. entity_id: sensor.magic_cube
  6. action:
  7. - service: light.turn_on
  8. entity_id:
  9. # any lights you want to change would go here
  10. - light.yeelinklightcolor1_miio45091268local
  11. - light.yeelinklightcolor1_miio46034208local
  12. - light.yeelinklightcolor1_miio48212400local
  13. data_template:
  14. color_name: >-
  15. # there is a limitation with home assistant -- you can't template out RGB colors -- have to use HTML names for now
  16. {% set rgb_colors = [ 'white', 'Moccasin', 'PaleVioletRed', 'TOMATO', 'LIGHTSKYBLUE', 'MEDIUMAQUAMARINE' ] %}
  17. {% set threeAxis = trigger.to_state.state.split(',')|map('int')|list %}
  18. {% set x = 0 if threeAxis[0]|abs < 250 else (1 if threeAxis[0] > 0 else -1) %}
  19. {% set y = 0 if threeAxis[1]|abs < 250 else (1 if threeAxis[1] > 0 else -1) %}
  20. {% set z = 0 if threeAxis[2]|abs < 250 else (1 if threeAxis[2] > 0 else -1) %}
  21. {% if z > 0 %}
  22. {% set orientation = 0 if x == 0 and y == 0 %}
  23. {% elif z < 0 %}
  24. {% set orientation = 1 if x == 0 and y == 0 %}
  25. {% else %}
  26. {% if x > 0 %}
  27. {% set orientation = 2 if y == 0 %}
  28. {% elif x < 0 %}
  29. {% set orientation = 3 if y == 0 %}
  30. {% else %}
  31. {% set orientation = 4 if y > 0 else 5 if y < 0 %}
  32. {% endif %}
  33. {% endif %}
  34. {{ rgb_colors[orientation] }}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement