下面的这些无线开关设都是可以利用Home Assistant来设置动作的。但如果觉得这些动作还不够,又或者想根据实际情况实现动态开关,请继续看下文:

  • 小米无线开关,目前支持3个动作:单击、双击、长按 aqara无线开关,支持4个动作:单击、双击、长按、摇一摇;
  • aqara贴墙式开关,最多支持3个动作:左右键单击、双键单击;
  • 小米魔方,目前支持9个动作:翻转90度、翻转180度、平移、双击、摇一摇、用力甩、静止一段时间后被触动、自由下落、旋转;

原理:利用input_select来选择动作,然后用自动化触发这些动作。由于大家想要设置的动作不一样、拥有的设备也不一样,所以这次不发packages包了,直接用例子说明:

24345-ze9fw4zbr8j.png

1、在input_select里设置想要添加的动作;

input_select:
  changeable_switch_turnon:
    name: 智能开启
    options:
      - Select Input
      - 闹钟1
      - 闹钟2
      - 浪漫模式
      - 打开客厅灯
    initial: 'Select Input'
    icon: mdi:toggle-switch

2、在automation里设置设备自动化触发这些动作。知识点:service: homeassistant.turn_on 是支持多种设备的写法。

automation:
  - id: bedroom_changeable_switch_turn_on
    alias: bedroom_changeable_switch_turn_on
    trigger:
      platform: event
      event_type: click
      event_data:
        entity_id: binary_sensor.wall_switch_both_xxxxxxxxxxxx
        click_type: both
    action:
      - service: homeassistant.turn_on
        data_template:
          entity_id: >-
            {% if is_state("input_select.changeable_switch_turnon", "睡房闹钟1") %}
              input_boolean.alarm1
            {% elif is_state("input_select.changeable_switch_turnon", "睡房闹钟2") %}
              input_boolean.alarm2
            {% elif is_state("input_select.changeable_switch_turnon", "浪漫模式") %}
              input_boolean.romantic_time
            {% elif is_state("input_select.changeable_switch_turnon", "打开客厅灯") %}
              switch.wall_switch_right_xxxxxxxxxxxx
            {% endif %}

3、在按键前选择好动作,以后每次按键都是这个动作,需要更改时在input_select里面选择一下又是另一个动作了。

本文作者:
文章标题:抛砖引玉:aqara小米开关、魔方等按键动作不够用?我帮你...
本文地址:https://blog.coolsong.com/tech/137.html
版权说明:若无注明,本文皆T Journal原创,转载请保留文章出处。
最后修改:2021 年 10 月 06 日