找回密码
 立即注册

微信扫码登录

搜索
查看: 5543|回复: 4

转自官方论坛的(小米饼干长按控制亮度)

[复制链接]

7

主题

148

回帖

1327

积分

论坛技术达人

积分
1327
金钱
1171
HASS币
0
发表于 2017-10-23 17:08:25 | 显示全部楼层 |阅读模式
本帖最后由 leoyanger 于 2017-10-23 17:09 编辑
input_boolean:
  landing_dim:
    name: Landing Dim
    initial: off
#变暗脚本        
script:
  dim_light_landing:
    sequence:

      - condition: state
        entity_id: input_boolean.landing_dim
        state: 'on'

      - service: light.turn_on
        entity_id: light.landing_light
        data_template:
          brightness: '{{states.light.landing_light.attributes.brightness - 10}}'

      - service: script.turn_off
        entity_id: script.dim_light_landing

      - service: script.turn_on
        entity_id: script.dim_light_landing
#变亮脚本                
script:
  brighten_light_landing:
    sequence:

  - condition: state
    entity_id: input_boolean.landing_dim
    state: 'off'

  - service: light.turn_on
    entity_id: light.landing_light
    data_template:
      brightness: '{{states.light.landing_light.attributes.brightness + 10}}'

  - service: script.turn_off
    entity_id: script.brighten_light_landing

  - service: script.turn_on
    entity_id: script.brighten_light_landing
#开灯并调亮        
- alias: xiaomi landing brighten on
  initial_state: 'on'
  trigger:
    - platform: event
      event_type: click
      event_data:
        entity_id: binary_sensor.switch_158d00019df218
        click_type: long_click_press
    - platform: event
      event_type: click
      event_data:
        entity_id: binary_sensor.switch_158d00016c0bac
        click_type: long_click_press
  condition:
    condition: and
    conditions:
    - condition: state
      entity_id: input_boolean.landing_dim
      state: 'off'
    - condition: state
      entity_id: light.landing_light
      state: 'on'
  action:
    - service: script.turn_on
      entity_id: script.brighten_light_landing
#更改input_boolean.landing_dim状态      
- alias: xiaomi landing brighten off
  initial_state: 'on'
  trigger:
    - platform: state
      entity_id: binary_sensor.switch_158d00019df218
      from: 'on'
      to: 'off'
    - platform: state
      entity_id: binary_sensor.switch_158d00016c0bac
      from: 'on'
      to: 'off'
  condition:
    condition: and
    conditions:
    - condition: state
      entity_id: input_boolean.landing_dim
      state: 'off'
    - condition: state
      entity_id: light.landing_light
      state: 'on'
  action:
    - service: input_boolean.turn_on
      entity_id: input_boolean.landing_dim

- alias: xiaomi landing dim on
  initial_state: 'on'
  trigger:
    - platform: event
      event_type: click
      event_data:
        entity_id: binary_sensor.switch_158d00019df218
        click_type: long_click_press
    - platform: event
      event_type: click
      event_data:
        entity_id: binary_sensor.switch_158d00016c0bac
        click_type: long_click_press
  condition:
    condition: and
    conditions:
    - condition: state
      entity_id: input_boolean.landing_dim
      state: 'on'
    - condition: state
      entity_id: light.landing_light
      state: 'on'
  action:
    - service: script.turn_on
      entity_id: script.dim_light_landing

- alias: xiaomi landing brighten off
  initial_state: 'on'
  trigger:
    - platform: state
      entity_id: binary_sensor.switch_158d00019df218
      from: 'on'
      to: 'off'
    - platform: state
      entity_id: binary_sensor.switch_158d00016c0bac
      from: 'on'
      to: 'off'
  condition:
    condition: and
    conditions:
    - condition: state
      entity_id: input_boolean.landing_dim
      state: 'on'
    - condition: state
      entity_id: light.landing_light
      state: 'on'
  action:
    - service: input_boolean.turn_off
      entity_id: input_boolean.landing_dim
回复

使用道具 举报

wqqs 手机认证

30

主题

969

回帖

4185

积分

论坛元老

积分
4185
金钱
3181
HASS币
0

活跃会员

发表于 2017-10-23 18:53:19 | 显示全部楼层
script还能嵌套用啊,学习了
回复

使用道具 举报

iLee 

11

主题

326

回帖

1390

积分

金牌会员

iLee

积分
1390
金钱
1052
HASS币
0
发表于 2017-10-26 16:42:44 | 显示全部楼层
很不错 学习了
回复

使用道具 举报

1

主题

41

回帖

324

积分

中级会员

积分
324
金钱
282
HASS币
0
发表于 2018-2-5 22:29:10 | 显示全部楼层
正好用到,学习了,谢谢
回复

使用道具 举报

3

主题

284

回帖

2782

积分

版主

懵懂的小白

积分
2782
金钱
2495
HASS币
0
发表于 2018-2-8 18:32:32 | 显示全部楼层
谢谢分享,支持
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|Hassbian ( 晋ICP备17001384号-1 )

GMT+8, 2025-8-14 00:34 , Processed in 0.052235 second(s), 6 queries , MemCached On.

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

快速回复 返回顶部 返回列表