图片1是xiaomi_miot集成的改动
图片2是设置的自动化
下面的代码是其中一个自动化和相关脚本的代码,可以参考自行设置
自动化:
alias: 客厅电视-打开-HDMI2
description: ""
trigger:
- platform: device
device_id: 119f2d460e048922250f1887d5afc1f0
domain: media_player
entity_id: media_player.xiaomi_rmaxv1_3406_play_control
type: turned_on
- platform: device
device_id: b867dbc8ac5466bb66b44f0aa5ccbf16
domain: media_player
entity_id: media_player.ke_ting_de_dian_shi
type: playing
- platform: device
device_id: 119f2d460e048922250f1887d5afc1f0
domain: media_player
entity_id: media_player.xiaomi_rmaxv1_3406_play_control
type: idle
condition:
- condition: device
device_id: 119f2d460e048922250f1887d5afc1f0
domain: select
entity_id: select.xiaomi_rmaxv1_3406_tv_input_control
type: selected_option
option: HDMI 2
action:
- service: script.1691593676406
data: {}
mode: single
脚本
alias: 桥接客厅电视HDMI2
sequence:
- service: xiaomi_miot.intelligent_speaker
data:
execute: true
silent: true
throw: true
entity_id: media_player.xiaomi_l05c_899a_play_control
text: 桥接客厅电视信号源二
- if:
- condition: state
entity_id: automation.zhuang_tai_hdmiqie_huan_yin_xiao
state: "on"
- condition: and
conditions:
- condition: device
device_id: be6d7ca794f535b83be658aab631268f
domain: alarm_control_panel
entity_id: alarm_control_panel.lumi_mgl03_1d28_arming
type: is_armed_home
then:
- service: automation.turn_off
data:
stop_actions: true
target:
entity_id: automation.zhuang_tai_hdmiqie_huan_yin_xiao
- service: script.1691593380724
data: {}
- delay:
hours: 0
minutes: 1
seconds: 0
milliseconds: 0
- service: automation.turn_on
data: {}
target:
entity_id: automation.zhuang_tai_hdmiqie_huan_yin_xiao
mode: single
icon: mdi:hdmi-port
图片3是桥接到米家APP,然后再让中枢执行切换信号的操作
图4是中枢的设置
最简单的就是,识别到信号源切换,执行氛围灯切换(或者执行关闭房间灯之类的),可以不用搞我这么长的链路。
因为我的设备比较多,而且要实现切换信号后,播放提示音,而且还要避免睡觉、或者不在家时,由于hass重启之类的重设信号源等误触发切换信号等,所以我的链路比较长,大家可以根据自己的需要自行精简就行了。
注:由于 xiaomi_miot 是轮询的方式来检测属性变化的,所以可能最长要一分钟之内才能触发自动化,不过问题不大。
现在我实现的场景如下,供大家参考:
HDMI1:看电视直播,氛围灯切换到电视联动,如果是夜间,打开房间灯
HDMI2:看AppleTV,氛围灯切换到电影模式(常驻白光),关闭房间灯
HDMI3:玩PS5游戏,氛围灯切换到游戏模式(常驻更暗的白光),如果是夜间,打开房间较暗的灯
显示电视桌面(一般是在使用电视自带的APP):氛围灯切换到电视联动,如果是夜间,打开房间灯
关闭电视:氛围灯切换到渐变颜色并显示跑马灯动画,如果是夜间、非睡觉、非离家,打开房间灯
|