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

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

通过插座功率判断电器是否运行

[复制链接]

3

主题

29

帖子

271

积分

论坛积极会员

积分
271
金钱
242
HASS币
0
发表于 2021-7-15 15:29:50 | 显示全部楼层 |阅读模式
场景:通过红外遥控控制的老电器,远程控制不知道是否开启.
实例:家里是个老空调,使用博联的红外控制和小米空调伴侣2都存在远程控制开启,但实际上并没有运行的情况.
思路:调用服务,开启空调 ,检测插座功率是否上升到50,延长30秒,重复此过程知道插座功率上升到50,推送到手机,提示空调开启成功.
前置条件:1.电器使用的是带功率检测的插座,并且在HA中可以查看 2.可以控制电器的设备,比如博联红外遥控器、小米空调伴侣2
turn_the_air_conditioner_on:
  sequence:
  - repeat:
      while:
      - condition: numeric_state
        entity_id: climate.xiaomi_air_conditioning_companion_2
        attribute: load_power
        below: '50'
      sequence:
      - service: switch.turn_on
        target:
          entity_id: switch.kong_diao
      - delay:
          hours: 0
          minutes: 0
          seconds: 30
          milliseconds: 0
  - choose:
    - conditions:
      - condition: state
        entity_id: sensor.season
        state: winter
      sequence:
      - repeat:
          until:
          - condition: state
            entity_id: climate.xiaomi_air_conditioning_companion_2
            state: heat
            attribute: hvac_mode
          sequence:
          - service: climate.set_hvac_mode
            target:
              entity_id: climate.xiaomi_air_conditioning_companion_2
            data:
              hvac_mode: heat
      - service: climate.set_temperature
        target:
          entity_id: climate.xiaomi_air_conditioning_companion_2
        data:
          temperature: 30
    - conditions:
      - condition: state
        entity_id: sensor.season
        state: summer
      sequence:
      - repeat:
          until:
          - condition: state
            entity_id: climate.xiaomi_air_conditioning_companion_2
            state: cool
            attribute: hvac_mode
          sequence:
          - service: climate.set_hvac_mode
            target:
              entity_id: climate.xiaomi_air_conditioning_companion_2
            data:
              hvac_mode: cool
      - service: climate.set_temperature
        target:
          entity_id: climate.xiaomi_air_conditioning_companion_2
        data:
          temperature: 20
    default: []
  - service: notify.mobile_app_iphone
    data:
      message: 空调已开启
  mode: single
  alias: 开空调
turn_the_air_conditioner_off:
  sequence:
  - repeat:
      while:
      - condition: numeric_state
        entity_id: climate.xiaomi_air_conditioning_companion_2
        attribute: load_power
        above: '50'
      sequence:
      - service: switch.turn_off
        target:
          entity_id: switch.kong_diao
      - delay:
          hours: 0
          minutes: 0
          seconds: 30
          milliseconds: 0
  - service: notify.mobile_app_iphone
    data:
      message: 空调已关闭
  mode: single
  alias: 关空调
这个问题困扰了我好几年,其实并不难,但对于小白来说,就是漫漫的摸索过程,写出来,希望能帮到有同样需求的小白.
回复

使用道具 举报

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

本版积分规则

Archiver|手机版|小黑屋|Hassbian

GMT+8, 2024-11-27 08:31 , Processed in 0.043002 second(s), 23 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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