本帖最后由 killadm 于 2018-3-23 20:27 编辑
我来提供个切换频道的思路
主要来源于这个帖子
https://bbs.hassbian.com/forum.php?mod=viewthread&tid=1868&highlight=%E7%94%B5%E8%A7%86
我修改了一个只需要用下拉菜单选择频道的版本
packages/channel.yaml
#频道列表下拉菜单,格式:频道号 频道名称,自动化只会取前三位数字
input_select:
mod_channel_select:
icon: mdi:television-classic
options:
- 301 CCTV-1
- 302 CCTV-2
- 303 CCTV-3
- 304 CCTV-4
- 305 CCTV-5
- 319 CCTV-5+
- 306 CCTV-6
- 307 CCTV-7
- 308 CCTV-8
- 309 CCTV-9
- 310 CCTV-10
- 312 CCTV-12
- 33 CCTV-13
- 314 CCTV-14
- 320 河北卫视
- 321 北京卫视
- 322 东方卫视
- 323 湖南卫视
- 324 广东卫视
- 325 江苏卫视
- 326 浙江卫视
- 327 深圳卫视
- 328 天津卫视
- 329 山东卫视
- 330 湖北卫视
- 331 黑龙江卫视
- 332 安徽卫视
- 333 纪实高清
- 334 辽宁卫视
- 335 重庆卫视
- 336 四川卫视
#定义遥控器0-9按键脚本
script:
mod_remote_0:
sequence:
- service: switch.broadlink_send_packet_192_168_123_217
data:
packet:
- 'JgBQAAABLZUUEhMTExMRORIUFBETExITFRESOBU2ExMUEhI3FTYUNhU2ExMUNhQ2EhQTExI4ExIVEhM2FRISExM3FTYUEhE5EwAFjwABLUoUAA0FAAAAAAAAAAA='
mod_remote_1:
sequence:
- service: switch.broadlink_send_packet_192_168_123_217
data:
packet:
- 'JgBQAAABLZUSFBIUEhMSOBIUEhQTExEUEhQRORI4ExMSFBE5EjgTNxIUEjgSFBIUExMRFBI4EhQSOBIUEjgSOBU2EjgTExI4EwAFjQABLUsUAA0FAAAAAAAAAAA='
mod_remote_2:
sequence:
- service: switch.broadlink_send_packet_192_168_123_217
data:
packet:
- 'JgBQAAABLZUVERMSEhQTNxURExMRFREUEhQTNxI4ExMSExQ3FDYSOBQ3FBEUExEUEhMSFRE4EhUSExM3EjgSORI4EjgSFBI4EgAFjwABLUoRAA0FAAAAAAAAAAA='
mod_remote_3:
sequence:
- service: switch.broadlink_send_packet_192_168_123_217
data:
packet:
- 'JgBQAAABLJYSFBITEhQSOBIUEhQSFBEUEhQSOBI4EhQSFBI4EjgVNhITEhQSFBITEhQSFBI4EhQSOBI4EjkSOBI4EjgUExE5EQAFkAABLEsUAA0FAAAAAAAAAAA='
mod_remote_4:
sequence:
- service: switch.broadlink_send_packet_192_168_123_217
data:
packet:
- 'JgBQAAABLJYVERQRFBIUNhQSFBIUERQSFBIUNhQ2FREUEhQ2FTUVNRURFTUVNhUQFREUEhU1FRETNxQSFBEVNRU2FDYUEhU1FAAFjQABKk0TAA0FAAAAAAAAAAA='
mod_remote_5:
sequence:
- service: switch.broadlink_send_packet_192_168_123_217
data:
packet:
- 'JgBQAAABLZUSFBITExMSOBIUFRESFBQSERQSOBI4FRESFBI4EzcTOBQ2EhQTNxIUExITExI4ExMTExI4EhQSOBI4EzgTEhU2EgAFjgABLUsTAA0FAAAAAAAAAAA='
mod_remote_6:
sequence:
- service: switch.broadlink_send_packet_192_168_123_217
data:
packet:
- 'JgBQAAABLZUVERQSExMRORQSExIUEhQSFBEUNhU2ExITExM3EzgUNhURExMSNxUSExITExQ2FBITNxQ2FBIUNhM3FDYVEhI3FQAFjAABLUoUAA0FAAAAAAAAAAA='
mod_remote_7:
sequence:
- service: switch.broadlink_send_packet_192_168_123_217
data:
packet:
- 'JgBQAAABLZUUEhQSEhMUNhMTFBIUEhQRFBIUNhQ2ExMUEhQ2FDYTNxUSFDUVEhE4FRITEhM3ExMUNhMTFDYVERQ2EzcTExM3FAAFjQABLEsUAA0FAAAAAAAAAAA='
mod_remote_8:
sequence:
- service: switch.broadlink_send_packet_192_168_123_217
data:
packet:
- 'JgBQAAABK5cSFBIUEhQRORQSExMRFBIUEhQRORI4EhQSFBE5EjgSOBI5ERQSFBI4ExMSFBI4EhQSFBE4EzgSFBI4EjgSFBI4EgAFjwABK00RAA0FAAAAAAAAAAA='
mod_remote_9:
sequence:
- service: switch.broadlink_send_packet_192_168_123_217
data:
packet:
- 'JgBQAAABLZUVERMSEhQSOBQSExMSFBEUExMTNxI4FBIUEhI4FDYVNRURFBIUEhM3FBIRFRQ1FRETNxU2FDYUEhQ2FDYUEhI4FQAFjAABLUoVAA0FAAAAAAAAAAA='
#拆分频道列表前三位数字,调用相关频道脚本,通过博联发送频道号
#{{"123ABC" | list}} = ['1', '2', '3', 'A', 'B', 'C']
#{{("123ABC"| list)[0] }} = '1'
automation:
- alias: "change channel"
hide_entity: True
trigger:
platform: state
entity_id: input_select.mod_channel_select
action:
- service: script.turn_on
data_template:
entity_id:
- script.mod_remote_{{ (states('input_select.mod_channel_select') | list)[0] }}
- service: script.turn_on
data_template:
entity_id:
- script.mod_remote_{{ (states('input_select.mod_channel_select') | list)[1] }}
- service: script.turn_on
data_template:
entity_id:
- script.mod_remote_{{ (states('input_select.mod_channel_select') | list)[2] }}
#如果当前输入源不是有线电视,自动切换到HDMI2
- alias: "switch input source"
hide_entity: True
trigger:
platform: state
entity_id: input_select.mod_channel_select
condition:
condition: and
conditions:
- condition: state
entity_id: media_player.mybraviatv
state: 'on'
- condition: template
value_template: "{{ not is_state_attr('media_player.mybraviatv', 'media_content_id', 'HDMI2') }}"
action:
- service: media_player.select_source
data:
entity_id: media_player.mybraviatv
source: HDMI2
homeassistant:
customize:
input_select.mod_channel_select:
friendly_name: 选择频道
只需要加个自动化判断是否开机就可以满足你的需求
切换频道的部分可以通过调用input_select.select_option服务选择频道
action:
service: input_select.select_option
data:
entity_id: input_select.mod_channel_select
option: '326' #浙江卫视台号
目前有个bug就是如果有频道号含重复数字,博联会只发送一次(比如322,电视只收到32),原因未知。
还有就是按键偶尔会有延迟,发送的频道号会从中间断掉(比如301,发送完30卡了一次,电视会切换到30再切换到1)。
|