菲神的HA的窗帘带滑块的组件最大的好处就是用滑块设置位置自动停止,但是也有一点小问题,因为是虚拟判断位置的情况,所以有时候在HA、HK中会不时的出现明明是关上了却显示closing、正在关上 的状态,而非closed、已关上的状态,所以想通过对门磁历史状态的判断强制定义它的状态。
cover:
- platform: template
covers:
garage:
friendly_name: '车库门'
value_template: >-
{% if is_state('[color=#ff0000]sensor.broadlink_s1c_dongmenci[/color]', 'closed') %}
closed
{% elif is_state('[color=#ff0000]sensor.broadlink_s1c_dongmenci[/color]', 'open') %}
open
{% elif trigger.event.data.old_state.state == "closed" and trigger.event.data.entity_id == "[color=#ff0000]sensor.broadlink_s1c_dongmenci[/color]" %}
opening
{% elif trigger.event.data.old_state.state == "open" and trigger.event.data.entity_id == "[color=#ff0000]sensor.broadlink_s1c_dongmenci[/color]" %}
closing
{% else %}
unknown
{% endif %}
open_cover:
service: script.turn_on
entity_id: [color=#ff0000]script.garage_open[/color]
close_cover:
service: script.turn_on
entity_id: [color=#ff0000]script.garage_close[/color]
stop_cover:
service: script.turn_on
entity_id: [color=#ff0000]script.garage_stop[/color]
icon_template: "{% if not is_state('[color=#ff0000]sensor.broadlink_s1c_dongmenci[/color]', 'closed') %}mdi:garage-open{% else %}mdi:garage{% endif %}"
homeassistant:
customize:
cover.garage:
homebridge_cover_type: garage_door
device_class: garage
完整代码在此,欢迎测试。
|