『瀚思彼岸』» 智能家居技术论坛

 找回密码
 立即注册
查看: 4670|回复: 4

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

[复制链接]

7

主题

155

帖子

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
回复

使用道具 举报

30

主题

997

帖子

4149

积分

论坛元老

Rank: 8Rank: 8

积分
4149
金钱
3147
HASS币
0

活跃会员

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

使用道具 举报

11

主题

337

帖子

1390

积分

金牌会员

iLee

Rank: 6Rank: 6

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

使用道具 举报

1

主题

42

帖子

324

积分

中级会员

Rank: 3Rank: 3

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

使用道具 举报

3

主题

286

帖子

2660

积分

版主

懵懂的小白

Rank: 7Rank: 7Rank: 7

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

使用道具 举报

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

本版积分规则

Archiver|手机版|小黑屋|Hassbian

GMT+8, 2024-11-23 07:44 , Processed in 0.103682 second(s), 27 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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