本帖最后由 chinyaolin 于 2019-9-16 15:46 编辑
2019/6/17 update: 論壇三開模塊的按鍵觸發太敏感, 代碼新增 filters delayed_on delayed_off
2019/9/14 update: 補兩張很久以前拆開電風扇的圖片
2019/9/16 update: 其實不見得要使用 ESPhome, 只需要選擇能支持 interlock 的固件都能達成目的
直接給代碼
ESPHome 代碼
這裡的重點是 relay1,2,3 必需互鎖(interlock) 以及同按鈕按第二次則關閉電扇
建立一個 sensor, 計算風扇檔位
sensor:
- platform: template
sensors:
hassmart_3ch_412707_speed:
value_template: >
{% if states('switch.hassmart_3ch_412707_sw3') == 'on' %}
3
{% elif states('switch.hassmart_3ch_412707_sw2') == 'on' %}
2
{% elif states('switch.hassmart_3ch_412707_sw1') == 'on' %}
1
{% else %}
0
{% endif %}
建立 FAN 元件
- platform: template
fans:
hassmart_3ch_412707:
value_template: >
{% if is_state("sensor.hassmart_3ch_412707_speed", "0") %}
off
{% else %}
on
{% endif %}
speed_template: '{{ states("sensor.hassmart_3ch_412707_speed") }}'
turn_on:
- service: switch.turn_on
entity_id: switch.hassmart_3ch_412707_sw3
turn_off:
- service: switch.turn_off
entity_id: switch.hassmart_3ch_412707_sw1
- service: switch.turn_off
entity_id: switch.hassmart_3ch_412707_sw2
- service: switch.turn_off
entity_id: switch.hassmart_3ch_412707_sw3
set_speed:
- service: switch.turn_on
data_template:
entity_id: >
{% if speed == '1' %}
switch.hassmart_3ch_412707_sw1
{% elif speed == '2' %}
switch.hassmart_3ch_412707_sw2
{% else %}
switch.hassmart_3ch_412707_sw3
{% endif %}
speeds:
- '1'
- '2'
- '3'
成果
|