请选择 进入手机版 | 继续访问电脑版

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

 找回密码
 立即注册
查看: 13501|回复: 16

[基础教程] 【小米智能家居系列】无线开关

[复制链接]

38

主题

748

帖子

4673

积分

论坛元老

Freddy.

Rank: 8Rank: 8

积分
4673
金钱
3900
HASS币
0

最佳新人卓越贡献

发表于 2017-10-20 20:02:34 | 显示全部楼层 |阅读模式
本帖最后由 27hh 于 2018-2-4 18:02 编辑

单击,双击和长按的自动化代码。。
#单击
  - alias: single_button
    initial_state: true
    trigger:
      platform: event
      event_type: click
      event_data:
        entity_id: binary_sensor.switch_158d0000d2def2
        click_type: single
    action:
      service: switch.turn_on
      entity_id: switch.left_button
#双击
  - alias: double_button
    initial_state: true
    trigger:
      platform: event
      event_type: click
      event_data:
        entity_id: binary_sensor.switch_158d0000d2def2
        click_type: double
    action:
      service: switch.turn_on
      entity_id: switch.left_button,switch.right_button
#长按
  - alias: hold_button
    initial_state: true
    trigger:
      platform: event
      event_type: click
      event_data:
        entity_id: binary_sensor.switch_158d0000d2def2
        click_type: long_click_press
    action:
      service: switch.turn_off
      entity_id: switch.left_button,switch.right_button
回复

使用道具 举报

38

主题

748

帖子

4673

积分

论坛元老

Freddy.

Rank: 8Rank: 8

积分
4673
金钱
3900
HASS币
0

最佳新人卓越贡献

 楼主| 发表于 2017-10-20 20:04:31 | 显示全部楼层
自己占沙发~~
回复

使用道具 举报

0

主题

24

帖子

110

积分

注册会员

Rank: 2

积分
110
金钱
86
HASS币
0
发表于 2017-10-20 20:30:17 | 显示全部楼层
赞一个!支持~~~~~
回复

使用道具 举报

1

主题

159

帖子

552

积分

高级会员

Rank: 4

积分
552
金钱
393
HASS币
0
发表于 2017-10-20 21:52:05 | 显示全部楼层
赞一个!支持~~~~~
回复

使用道具 举报

32

主题

986

帖子

4233

积分

论坛元老

Rank: 8Rank: 8

积分
4233
金钱
3207
HASS币
110

教程狂人论坛风云人物

发表于 2017-10-21 12:55:01 | 显示全部楼层
楼主,你这个的alias和要实现的功能完全不符啊。。。
回复

使用道具 举报

38

主题

748

帖子

4673

积分

论坛元老

Freddy.

Rank: 8Rank: 8

积分
4673
金钱
3900
HASS币
0

最佳新人卓越贡献

 楼主| 发表于 2017-10-21 13:03:05 | 显示全部楼层
61741514 发表于 2017-10-20 21:52
赞一个!支持~~~~~

感谢。。。。
回复

使用道具 举报

38

主题

748

帖子

4673

积分

论坛元老

Freddy.

Rank: 8Rank: 8

积分
4673
金钱
3900
HASS币
0

最佳新人卓越贡献

 楼主| 发表于 2017-10-21 13:04:41 | 显示全部楼层
27hh 发表于 2017-10-21 12:55
楼主,你这个的alias和要实现的功能完全不符啊。。。

- -看注释就行了
回复

使用道具 举报

9

主题

787

帖子

3819

积分

论坛元老

Rank: 8Rank: 8

积分
3819
金钱
3032
HASS币
87
发表于 2018-1-10 10:52:23 | 显示全部楼层
咨询下有没有组合触发?
比如说连按三次,
或者两个开关顺序各按一下之类的?
回复

使用道具 举报

0

主题

18

帖子

52

积分

注册会员

Rank: 2

积分
52
金钱
34
HASS币
0
发表于 2018-1-18 16:28:18 | 显示全部楼层
6666666666666
回复

使用道具 举报

163

主题

613

帖子

3613

积分

论坛元老

Rank: 8Rank: 8

积分
3613
金钱
2995
HASS币
0
发表于 2018-2-4 08:44:22 | 显示全部楼层
本帖最后由 ptlzx 于 2018-2-4 09:51 编辑

刚才试了一下双击的代码,出现错误,能否帮忙看看。

automations.yaml内容:
- alias: double_button
  initial_state: true
  trigger:
    platform: event
    event_type: click
    event_data:
      entity_id: binary_sensor.switch_158d0001bf2271 //这个是小米无线开关有三个动作:点击、双击、长按
      click_type: double
  action:
    service: switch.toggle  //使用切换操作控制sonoff开关
    entity_id: Sonoff_3  //双击要控制的设备是sonoff开关


错误日志:
Testing configuration at /config
2018-02-04 01:37:21 INFO (MainThread) [homeassistant.setup] Setting up mqtt
2018-02-04 01:37:21 INFO (MainThread) [homeassistant.setup] Setting up introduction
2018-02-04 01:37:21 INFO (MainThread) [homeassistant.setup] Setting up http
2018-02-04 01:37:21 INFO (MainThread) [homeassistant.setup] Setup of domain mqtt took 0.0 seconds.
2018-02-04 01:37:21 INFO (MainThread) [homeassistant.setup] Setting up recorder
2018-02-04 01:37:21 INFO (MainThread) [homeassistant.setup] Setup of domain introduction took 0.0 seconds.
2018-02-04 01:37:21 INFO (MainThread) [homeassistant.setup] Setup of domain http took 0.0 seconds.
2018-02-04 01:37:21 INFO (MainThread) [homeassistant.setup] Setup of domain recorder took 0.0 seconds.
2018-02-04 01:37:21 INFO (MainThread) [homeassistant.setup] Setting up system_log
2018-02-04 01:37:21 INFO (MainThread) [homeassistant.setup] Setting up api
2018-02-04 01:37:21 INFO (MainThread) [homeassistant.setup] Setting up websocket_api
2018-02-04 01:37:21 INFO (MainThread) [homeassistant.setup] Setting up history
2018-02-04 01:37:21 INFO (MainThread) [homeassistant.setup] Setup of domain system_log took 0.0 seconds.
2018-02-04 01:37:21 INFO (MainThread) [homeassistant.setup] Setup of domain api took 0.0 seconds.
2018-02-04 01:37:21 INFO (MainThread) [homeassistant.setup] Setup of domain websocket_api took 0.0 seconds.
2018-02-04 01:37:21 INFO (MainThread) [homeassistant.setup] Setup of domain history took 0.0 seconds.
2018-02-04 01:37:21 INFO (MainThread) [homeassistant.setup] Setting up frontend
2018-02-04 01:37:21 INFO (MainThread) [homeassistant.setup] Setup of domain frontend took 0.0 seconds.
2018-02-04 01:37:21 INFO (MainThread) [homeassistant.setup] Setting up discovery
2018-02-04 01:37:21 INFO (MainThread) [homeassistant.setup] Setting up sun
2018-02-04 01:37:21 INFO (MainThread) [homeassistant.setup] Setting up sensor
2018-02-04 01:37:21 INFO (MainThread) [homeassistant.setup] Setting up group
2018-02-04 01:37:21 ERROR (MainThread) [homeassistant.config] Invalid config for [automation]: Entity ID sonoff_3 is an invalid entity id for dictionary value @ data['action'][0]['entity_id']. Got None. (See /config/configuration.yaml, line 155). Please check the docs at https://home-assistant.io/components/automation/
2018-02-04 01:37:21 INFO (MainThread) [homeassistant.setup] Setting up xiaomi_aqara
2018-02-04 01:37:21 INFO (MainThread) [homeassistant.setup] Setting up map
2018-02-04 01:37:21 INFO (MainThread) [homeassistant.setup] Setting up updater
2018-02-04 01:37:21 INFO (MainThread) [homeassistant.setup] Setup of domain discovery took 0.1 seconds.
2018-02-04 01:37:21 INFO (MainThread) [homeassistant.setup] Setup of domain sun took 0.1 seconds.
2018-02-04 01:37:21 INFO (MainThread) [homeassistant.setup] Setup of domain sensor took 0.1 seconds.
2018-02-04 01:37:21 INFO (MainThread) [homeassistant.setup] Setup of domain group took 0.0 seconds.
2018-02-04 01:37:21 INFO (MainThread) [homeassistant.setup] Setup of domain xiaomi_aqara took 0.0 seconds.
2018-02-04 01:37:21 INFO (MainThread) [homeassistant.setup] Setup of domain map took 0.0 seconds.
2018-02-04 01:37:21 INFO (MainThread) [homeassistant.setup] Setup of domain updater took 0.0 seconds.
2018-02-04 01:37:21 INFO (MainThread) [homeassistant.setup] Setting up tts
2018-02-04 01:37:21 INFO (MainThread) [homeassistant.setup] Setting up config
2018-02-04 01:37:21 INFO (MainThread) [homeassistant.setup] Setting up logbook
2018-02-04 01:37:21 INFO (MainThread) [homeassistant.setup] Setting up conversation
2018-02-04 01:37:21 INFO (MainThread) [homeassistant.setup] Setup of domain tts took 0.0 seconds.
2018-02-04 01:37:21 INFO (MainThread) [homeassistant.setup] Setting up script
2018-02-04 01:37:21 INFO (MainThread) [homeassistant.setup] Setting up light
2018-02-04 01:37:21 INFO (MainThread) [homeassistant.setup] Setting up automation
2018-02-04 01:37:21 INFO (MainThread) [homeassistant.setup] Setup of domain config took 0.0 seconds.
2018-02-04 01:37:21 INFO (MainThread) [homeassistant.setup] Setup of domain logbook took 0.0 seconds.
2018-02-04 01:37:21 INFO (MainThread) [homeassistant.setup] Setup of domain conversation took 0.0 seconds.
2018-02-04 01:37:21 INFO (MainThread) [homeassistant.setup] Setup of domain script took 0.0 seconds.
2018-02-04 01:37:21 INFO (MainThread) [homeassistant.setup] Setup of domain light took 0.0 seconds.
2018-02-04 01:37:21 INFO (MainThread) [homeassistant.setup] Setup of domain automation took 0.0 seconds.
Failed config
  automation:
    - action: [source /config/automations.yaml:21]
        entity_id: Sonoff_3
        service: switch.toggle
      alias: double_button
      initial_state: True
      trigger: [source /config/automations.yaml:15]
        platform: event
        event_data: [source /config/automations.yaml:18]
          click_type: double
          entity_id: binary_sensor.switch_158d0001bf2271
        event_type: click

Successful config (partial)
  automation:
回复

使用道具 举报

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

本版积分规则

Archiver|手机版|小黑屋|Hassbian

GMT+8, 2024-3-29 10:14 , Processed in 0.060852 second(s), 33 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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