找回密码
 立即注册

微信扫码登录

搜索
查看: 95912|回复: 339

【更新】场景切换执行自动化

 火... [复制链接]

2

主题

195

回帖

1367

积分

金牌会员

积分
1367
金钱
1170
HASS币
0
发表于 2018-3-1 15:09:14 | 显示全部楼层 |阅读模式
本帖最后由 bluefire1982 于 2018-3-1 22:48 编辑

更新部分
游客,如果您要查看本帖隐藏内容请回复



----------------------------------------------我是分隔线--------------------------------------------------------------
原帖部分
先用input_select定义场景。我设置了2个:“在家”和“离开”。初始状态为“在家”。
input_select:
  scenes:
    name: '场景'
    options:
      - 在家
      - 离开
    initial: '在家'
    icon: mdi:home-assistant

sence.png
可以通过下拉框手动选择,或根据其他设备联动。我通过group.all_devices的状态自动切换。

因为场景有初始值,重启会恢复默认值。这里我加入了重启HA时的触发,确保重启后仍能保持场景正确。
automation:
  # 根据家人是否在家触发场景切换
  - alias: 'Select_the_scene'
    initial_state: true
    trigger:
      - platform: homeassistant
        event: start
      - platform: state
        entity_id: group.all_devices
    action:
      - service: input_select.select_option
        data_template:
          entity_id: input_select.scenes
          option: >
            {% if is_state('group.all_devices', 'home') %}
              在家
            {% else %}
              离开
            {% endif %}

然后根据选择的场景执行设备联动。我这里设置了在家关闭/离开打开小米网关警戒(另一个自动化)和小方摄像头(小米智能插座控制)。
  - alias: 'Scene_Trigger'
    initial_state: true
    trigger:
      - platform: homeassistant
        event: start
      - platform: state
        entity_id: input_select.scenes
    action:
      - service_template: "automation.turn_{% if trigger.to_state.state == '离开' %}on{% else %}off{% endif %}"
        entity_id: automation.alert_playing
      - service_template: "switch.turn_{% if trigger.to_state.state == '离开' %}on{% else %}off{% endif %}"
        entity_id: switch.xiaomi_smart_wifi_plug

这里用了service_template简化了脚本,不用分2种场景写2个自动化。

分享完毕!






评分

参与人数 6金钱 +45 收起 理由
jason_shu + 1 论坛有你更精彩!
sorrypqa + 8 感谢楼主分享!
gt_man + 2 大神666!
lidicn + 12 我来瀚思就为看你!
neroxps + 10 谢谢分享!
+ 12 谢谢分享!

查看全部评分

★Raspberry + Raspbian + Home Assistant v0.1
★树莓派 + Raspbian系统 + HomeAssistant
https://github.com/huangqian8/homeassistant
回复

使用道具 举报

2

主题

195

回帖

1367

积分

金牌会员

积分
1367
金钱
1170
HASS币
0
 楼主| 发表于 2018-3-1 21:15:50 | 显示全部楼层
27hh 发表于 2018-3-1 18:41
为什么不使用Home Assistant自带的场景功能呢?

惭愧,新手没看到过Scenes,这就去看看文档。
★Raspberry + Raspbian + Home Assistant v0.1
★树莓派 + Raspbian系统 + HomeAssistant
https://github.com/huangqian8/homeassistant
回复

使用道具 举报

2

主题

195

回帖

1367

积分

金牌会员

积分
1367
金钱
1170
HASS币
0
 楼主| 发表于 2018-5-9 10:22:24 | 显示全部楼层
yxm203 发表于 2018-5-8 21:32
请问你的小米网关警戒模式怎样在ha中设置?

人体传感器触发网关发出声音
★Raspberry + Raspbian + Home Assistant v0.1
★树莓派 + Raspbian系统 + HomeAssistant
https://github.com/huangqian8/homeassistant
回复

使用道具 举报

2

主题

195

回帖

1367

积分

金牌会员

积分
1367
金钱
1170
HASS币
0
 楼主| 发表于 2018-7-28 05:36:20 | 显示全部楼层
zxh 发表于 2018-7-27 23:45
mmlklkkl扣扣【klk'ljmkljmkjmkl

灌水!
★Raspberry + Raspbian + Home Assistant v0.1
★树莓派 + Raspbian系统 + HomeAssistant
https://github.com/huangqian8/homeassistant
回复

使用道具 举报

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

本版积分规则

Archiver|手机版|小黑屋|Hassbian ( 晋ICP备17001384号-1 )

GMT+8, 2025-9-3 09:19 , Processed in 1.080419 second(s), 7 queries , MemCached On.

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

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