Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- - 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] }}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement