Up-voted。这将是一个好去处。周围有组装的方法(如大多数事情)。就其价值而言我使用hass-variables (https://github.com/rogro82/hass-variables)和一些自动化和传感器。
我们的大门是一个例子。
variable.yaml:
front_gate_open:值:' 0 '恢复:真的
我必须为我的一些实体创建模板切换,我想跟踪触发脚本把他们所以我可以设置变量(假设我也可以做一个自动化监听”:在“状态改变…
switches.yaml
平台:模板开关:front_drive_gate: friendly_name:“前面车道门”value_template:“{{is_state (“binary_sensor.front_gate_contact”,“上”)}}“turn_on:服务:script.front_gate_open turn_off:服务:script.front_gate_close icon_template:“mdi:门”
这里的关键是当门打开脚本变量设置为现在().timestamp ()
scripts.yaml
front_gate_open:序列:条件:国家entity_id: binary_sensor.front_gate_contact状态:“离开”——服务:开关。turn_on entity_id: switch.front_gate -服务:变量。set_variable数据:变量:front_gate_open value_template:“{{现在().timestamp ()}}”
我创建了一个传感器显示的时间自去年开放。当然很多方面显示这一次,这就是我选择去做。
sensors.yaml
front_gate_last_open: value_template: >{%设置运行= (as_timestamp(州(sensor.date_time) .replace(" ", ")) -状态(“variable.front_gate_open”) | int) %}{%设置天=(运行/ 86400)| int %}{%设置小时=((运行% 86400)/ 3600)| int %}{%设置分钟=((运行% 3600)/ 60)| int %}{%设置秒=运行| int % 60%}{%如果天> 0%}{{天}}d{%如果小时<}0 10% {% endif %}{{小时}}:{%如果分钟10% <}0 {% endif %}{{分钟}}{% elif小时> 0%}{%如果小时<}0 10% {% endif %}{{小时}}:{%如果分钟10% <}0 {% endif %}{{分钟}}{% elif分钟> 0%}{{分钟}}m{%其他%}{{秒}}年代{% endif %}
然后我有一个条件卡在我的UI显示多久大门已经打开,并重启。
ui-lovelace.yaml
类型:有条件的条件:-实体:binary_sensor.front_gate_contact state_not:“关闭”名片:类型:实体风格:| ha-card #州{margin-bottom: 5 px !重要;padding-top: 5 px !重要;padding-bottom: 0 px;}实体:实体:switch.front_drive_gate类型:自定义:multiple-entity-row名称:前门state_color:真正的切换:假show_state:假实体:-实体:switch.front_drive_gate切换:真实姓名:假tap_action:行动:调用服务服务:脚本。turn_on service_data: entity_id: script.front_gate_close -实体:sensor.front_gate_last_open名称:持续时间
这显示打开的时候:
![图像](//www.sz-tiancheng.com/community-assets/original/3X/b/f/bf763efae9b3675088d6f845885bae8d4df2ea9f.png)
总是一群皮肤一只猫的方法哈,但这肯定是一个迂回的交际方法。(我理解我可以创建自动化去除其中的一些步骤,但嘿,一年前我编码,我懒得改变(如果没坏,就不要修复它])。![:man_shrugging: :man_shrugging:](//www.sz-tiancheng.com/community/images/emoji/twitter/man_shrugging.png?v=9)