『瀚思彼岸』» 智能家居技术论坛

 找回密码
 立即注册
查看: 255|回复: 0

[已解决] HA如何新建并定义一个开关执行某一实体的选择后开关

[复制链接]

174

主题

634

帖子

3792

积分

论坛元老

Rank: 8Rank: 8

积分
3792
金钱
3153
HASS币
0
发表于 2024-9-29 16:33:39 | 显示全部楼层 |阅读模式
本帖最后由 ptlzx 于 2024-10-2 16:45 编辑

具体的流程如下:remote.harmonyhub选择比如Apple tv后的开关操作。
目标是直接定义3个开关提供给homekit,直接开关这3个选项
截屏2024-09-29 16.25.48.png

---------------------------------------------------------------------
configuration.yaml
switch:
  - platform: template
    switches:
      hifi_player_switch:
        unique_id: "32b33778a2614be0a3290f81afdeaba6"
        friendly_name: "HiFi Player Switch"
        value_template: "{{ states.remote.harmonyhub.attributes.current_activity == 'Hi-Fi Player' }}"

        turn_on:
          service: script.turn_on_hifi_player
        turn_off:
          service: script.turn_off_hifi_player
  - platform: template
    switches:
      apple_tv_switch:
        unique_id: "32b33778a2614be0a3290f81afdeaba7"
        friendly_name: "Apple TV Switch"
        value_template: "{{ states.remote.harmonyhub.attributes.current_activity == 'apple_tv' }}"
        turn_on:
          service: script.turn_on_apple_tv
        turn_off:
          service: script.turn_off_apple_tv
  - platform: template
    switches:
      blu_ray_player_switch:
        unique_id: "32b33778a2614be0a3290f81afdeaba8"
        friendly_name: "Blu-ray_Player Switch"
        value_template: "{{ states.remote.harmonyhub.attributes.current_activity == 'blu_ray_play' }}"
        turn_on:
          service: script.turn_on_blu_ray_player
        turn_off:
          service: script.turn_off_blu_ray_player



scripts.yaml
turn_on_hifi_player:
  alias: Turn On HiFi Player
  sequence:
  - service: remote.turn_on
    entity_id: remote.harmonyhub
    data:
      activity: Hi-Fi Player
turn_off_hifi_player:
  alias: Turn Off HiFi Player
  sequence:
  - service: remote.turn_off
    entity_id: remote.harmonyhub
    data:
      activity: Hi-Fi Player
turn_on_blu_ray_player:
  alias: Turn On Blu-ray Player
  sequence:
  - action: remote.turn_on
    metadata: {}
    data:
      activity: Blu-ray Play
    target:
      entity_id: remote.harmonyhub
  description: ''
turn_on_apple_tv:
  alias: Turn On Apple TV
  sequence:
  - action: remote.turn_on
    metadata: {}
    data:
      activity: Apple TV
    target:
      entity_id: remote.harmonyhub
  description: ''
turn_off_apple_tv:
  alias: Turn Off Apple TV
  sequence:
  - service: remote.turn_off
    entity_id: remote.harmonyhub
    data:
      activity: Hi-Fi Player
turn_off_blu_ray_player:
  alias: Turn Off Blu-ray Player
  sequence:
  - service: remote.turn_off
    entity_id: remote.harmonyhub
    data:
      activity: Blu-ray Play


回复

使用道具 举报

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

本版积分规则

Archiver|手机版|小黑屋|Hassbian

GMT+8, 2024-12-4 16:36 , Processed in 0.101702 second(s), 26 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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