2024年11月24日星期日 上午6:13:47

小爱音箱控制虚拟设备-虚拟风扇 configuration.yaml

1 年 前
#20959 引用
虚拟风扇

https://bbs.hassbian.com/thread-14006-1-1.html
0
1 年 前
#20960 引用
下面是一个使用小爱服务结合模板生成一个虚拟的风扇实体的例子:



# configuration.yaml http://localhost:4999/boards/postedit/20960
fan:
  - platform: template
    # https://www.home-assistant.io/integrations/fan.template
    fans:
      xiaoai_fan:
        friendly_name: "小爱风扇"
        value_template: "{{ states('input_boolean.xiaoai_fan_state') }}" # 创建一个辅助元素记录状态
        percentage_template: 0
        preset_mode_template: ""
        oscillating_template: false
        speed_count: 3
        preset_modes:
          - 直吹风
          - 自然风
        turn_on:
          - service: xiaomi_miot.intelligent_speaker
            data:
              entity_id: media_player.xiaoai_entity_id # 改成你的小爱实体ID
              text: 打开风扇
              execute: true
              silent: true
          - service: input_boolean.turn_on
            target:
              entity_id: input_boolean.xiaoai_fan_state
        turn_off:
          - service: xiaomi_miot.intelligent_speaker
            data:
              entity_id: media_player.xiaoai_entity_id # 改成你的小爱实体ID
              text: 关闭风扇
              execute: true
              silent: true
          - service: input_boolean.turn_off
            target:
              entity_id: input_boolean.xiaoai_fan_state
        set_percentage:
          service: xiaomi_miot.intelligent_speaker
          data:
            entity_id: media_player.xiaoai_entity_id # 改成你的小爱实体ID
            text: "风扇风速调到{{ percentage }}"
            execute: true
            silent: true
        set_preset_mode:
          service: xiaomi_miot.intelligent_speaker
          data:
            entity_id: media_player.xiaoai_entity_id # 改成你的小爱实体ID
            text: "风扇模式切换为{{ preset_mode }}"
            execute: true
            silent: true
        set_oscillating:
          service: xiaomi_miot.intelligent_speaker
          data:
            entity_id: media_player.xiaoai_entity_id
            text: "{{ '风扇摇头' if oscillating else '风扇停止摇头' }}"
            execute: true
            silent: true


0
6 个月 前
#34046 引用
1
0
3 个月 前
#44529 引用
下面是一个使用小爱服务结合模板生成一个虚拟的风扇实体的例子:



# configuration.yaml http://localhost:4999/boards/postedit/20960
fan:
  - platform: template
    # https://www.home-assistant.io/integrations/fan.template
    fans:
      xiaoai_fan:
        friendly_name: "小爱风扇"
        value_template: "{{ states('input_boolean.xiaoai_fan_state') }}" # 创建一个辅助元素记录状态
        percentage_template: 0
        preset_mode_template: ""
        oscillating_template: false
        speed_count: 3
        preset_modes:
          - 直吹风
          - 自然风
        turn_on:
          - service: xiaomi_miot.intelligent_speaker
            data:
              entity_id: media_player.xiaomi_lx06_026c_play_control # 改成你的小爱实体ID
              text: 打开风扇
              execute: true
              silent: true
          - service: input_boolean.turn_on
            target:
              entity_id: input_boolean.xiaoai_fan_state
        turn_off:
          - service: xiaomi_miot.intelligent_speaker
            data:
              entity_id: media_player.xiaomi_lx06_026c_play_control # 改成你的小爱实体ID
              text: 关闭风扇
              execute: true
              silent: true
          - service: input_boolean.turn_off
            target:
              entity_id: input_boolean.xiaoai_fan_state
        set_percentage:
          service: xiaomi_miot.intelligent_speaker
          data:
            entity_id: media_player.xiaomi_lx06_026c_play_control # 改成你的小爱实体ID
            text: "风扇风速调到{{ percentage }}"
            execute: true
            silent: true
        set_preset_mode:
          service: xiaomi_miot.intelligent_speaker
          data:
            entity_id: media_player.xiaomi_lx06_026c_play_control # 改成你的小爱实体ID
            text: "风扇模式切换为{{ preset_mode }}"
            execute: true
            silent: true
        set_oscillating:
          service: xiaomi_miot.intelligent_speaker
          data:
            entity_id: media_player.xiaomi_lx06_026c_play_control
            text: "{{ '风扇摇头' if oscillating else '风扇停止摇头' }}"
            execute: true
            silent: true


0
3 个月 前
#44530 引用
# configuration.yaml
sensor:
  - platform: template
    sensors:
# Period of the day  https://community.home-assistant.io/t/wth-is-there-no-at-night-condition/470064/7
      period_of_day:
        friendly_name: 'period of the day'
        value_template: >-
          {% if (as_timestamp(states.sun.sun.attributes.next_dusk)) - (as_timestamp(states.sun.sun.attributes.next_setting)) < 0 %}
            dusk
          {% elif (as_timestamp(states.sun.sun.attributes.next_rising)) - (as_timestamp(states.sun.sun.attributes.next_dawn)) < 0 %}
            dawn
          {% elif (states.sun.sun.attributes.elevation) < 0 %}
            night
          {% else %}
            day
          {% endif %}
        icon_template: >-
          {% if is_state('sun.sun', 'above_horizon') %}
            mdi:weather-sunny
          {% else %}
            mdi:weather-night
          {% endif %}
# Period of the day  https://community.home-assistant.io/t/wth-is-there-no-at-night-condition/470064/7
      motion_toilet_active:
           entity_id: sensor.time
           friendly_name: "motion sensor - toilet active"
           device_class: presence
           value_template: >-
             {{  (as_timestamp(now()) -  as_timestamp(states.binary_sensor.motion_sensor_no1_by_homekit_controller_in_living_room.last_changed)) < 60 }}
0