本帖最后由 icecrown365 于 2017-9-17 22:54 编辑
利用小米魔方旋转角度控制智睿灯泡亮度,在automations.yaml加入一下代码即可。 如果感觉亮度改变慢,可以将1.00改成1.25或者更高。代码同样适合控制音响后者电视音量,将set state部分改成音量相关即可。
- id: cube_brightness
alias: Set brightness by rotating cube
trigger:
platform: event
event_type: cube_action
event_data:
# 此处为魔方entity id
entity_id: binary_sensor.cube_158d000xxxxxc2
action_type: rotate
action:
service: light.turn_on
data_template:
# 此处为灯泡entity id
entity_id: light.xiaomi_philips_smart_led_ball
brightness: >
{% set state = states.light.xiaomi_philips_smart_led_ball.attributes.brightness|int + ((trigger.event.data.action_value|float)*1.00)|int -%}
{%- if state > 255 -%}
{%- set state = 255 -%}
{%- elif state < 0 -%}
{%- set state = 0 -%}
{%- endif %}
{{ state }}
|