HomeAssistant(5) - HelloMorningStar/HomeAssistant GitHub Wiki

1, floorplan

纪念一下当前的界面

准备花点时间改变一下,画出房型图
要点:
1)自定义ha-floorplan.html页面文件,配合SVG格式图片floorplan.svg,将图片中的可视化设备赋予系统设备的实例ID,达到关联控制的目的。
2)2D/3D(可以先从2D入手学习,据说3D有一些问题:角度固定导致设备显示问题;灯具的显示控制问题;SVG本身的局限性,不支持三位物体的描述)
3)使用工具:Inkscape(sketchup可以吗?)
4)安装项目:需要修改的文件floorplan.yaml(设备配置)/floorplan.svg(平面图片文件)/floorplan.css(显示效果样式文件)
5)显示方式:
侧边栏

panel_custom:    
  - name: floorplan    
    sidebar_title: Floorplan     
    sidebar_icon: mdi:bulletin-board    
    url_path: floorplan    
    config: !include floorplan.yaml

状态卡片

homeassistant:     
  customize:       
    binary_sensor.floorplan:    
      custom_ui_state_card: floorplan    
      config: !include floorplan.yaml    
binary_sensor:   
  - platform: mqtt    
    state_topic: dummy/floorplan/sensor    
    name: Floorplan    
group:    
  zones:    
    name: Zones  
    entities:  
      - binary_sensor.floorplan    

6)Floorplan初始界面:有默认图,需要我们自己在floorplan.yaml中加入设备

安装floorplan Jump to floorplan

如图复制下载到对应的位置
在configuration.yaml加入以下配置:

panel_custom:  
  - name: floorplan  
    sidebar_title: 我的家  
    sidebar_icon: mdi:home  
    config: !include floorplan.yaml  

HomeAssistant的http组件会将配置目录中www目录中的文件映射为前端可以访问的local静态文件。panel_custom组件根据其配置项提供服务。

制作2D图,使用inkspace,图标和阴影的ID设置成HomeAssistant中实体的ID,将文件保存为floorplan.svg去覆盖源文件。
配置floorplan.yaml文件
动态的样式作为状态卡配置(略过)

制作3D图 去sweet home 3d官方网站下载 安装sweet home 3d
最终在homeassistant使用效果

以上再次总结:

1,SWEET HOME 3D制作 房型3D图,导出SVG格式
2,INK SPACE 制作2D图,导出兼容格式(由于iPad是ios10.3.3,高版本无需兼容格式)
3,别忘记了!!!floorplan.yaml文件把图上的entities添加上(时间久了容易忘记)

2, 吸尘器充电检测以及定时关闭电源保护电池

Whirlpool WVC-L1496Y说明书要求充电4小时拔下充电器,我考虑利用智能插座根据功率的变化自动定时切断电源。
利用automation
(trigger) if socket get power is not zero, will trigger for 4 hours
(condition) ?:
(action) Turn off the socket after 4 hours

#xiaomi_socket get power
  - alias: xiaomi_socket_get_power
    initial_state: true
    trigger:
      platform: numeric_state
      entity_id: switch.plug_158d000153de1f
      # Optional
      value_template: '{{ state.attributes.load_power }}'
      # At least one of the following required
      above: 10
#      below: 25
      for:
#        seconds: 5
        hours: 4
    condition:
    action:
      service: homeassistant.turn_off
      entity_id:
        - switch.plug_158d000153de1f

以上实现充电4小时自动关闭电源,但是没有实现插上充电器自动开启电源(好像关闭socket后可以检测的参数不够)
attributes中只有这些参数返回,如果自动关闭电源后in_use和load_power就为0了,也就是说插上充电器时没有可以检测的参数返回?
in_use: 1
load_power: 13.96
power_consumed: 1019928
battery_level: 100
friendly_name: 充电插座
icon: mdi:power-socket
充满后状态值的变化,说明吸尘器自己的充电管理可以断电,无需用插头开关控制(说明书的描述并不妥当)
in_use: 0
load_power: 0
power_consumed: 1019959
battery_level: 100
friendly_name: 充电插座
icon: mdi:power-socket
本次充电用了0.031KW/h
以上白忙活了,那么就联动一下网关灯改变颜色表示充满电了吧(目前我还不会设置网关灯的颜色,这里暂时用开关代替)

  - alias: xiaomi_socket_in_use
    initial_state: true
    hide_entity: true
    trigger:
      platform: numeric_state
      entity_id: switch.plug_158d000153de1f
      value_template: '{{ state.attributes.in_use }}'
      above: 0
    condition:
    action:
      service: homeassistant.turn_on
      entity_id: light.gateway_light_286c0788b4c4  #网关灯

  - alias: xiaomi_socket_not_in_use
    initial_state: true
    hide_entity: true
    trigger:
      platform: numeric_state
      entity_id: switch.plug_158d000153de1f
      value_template: '{{ state.attributes.in_use }}'
      below: 1
    condition:
    action:
      service: homeassistant.turn_off
      entity_id: light.gateway_light_286c0788b4c4  #网关灯

后续判断改为load_power比in_use好一些,吸尘器充满电后,对后续的涓流充电(功率在3W以下,这里阀值设为5)我并不关心。
改进后:

#xiaomi_socket in_use
  - alias: xiaomi_socket_in_use
    initial_state: true
    hide_entity: true
    trigger:
      platform: numeric_state
      entity_id: switch.plug_158d000153de1f
#      value_template: '{{ state.attributes.in_use }}'
      value_template: '{{ state.attributes.load_power }}'
#      above: 0    
      above: 5
    condition:
    action:
      service: homeassistant.turn_on
      data_template:
        entity_id: light.gateway_light_286c0788b4c4  #网关灯
        brightness: 25
#        color_name: red
        rgb_color: [255,0,255]
  - alias: xiaomi_socket_not_in_use
    initial_state: true
    hide_entity: true
    trigger:
      platform: numeric_state
      entity_id: switch.plug_158d000153de1f
#      value_template: '{{ state.attributes.in_use }}'
      value_template: '{{ state.attributes.load_power }}'
#      below: 1    
      below: 5
    condition:
    action:
      service: homeassistant.turn_on
      data_template:
        entity_id: light.gateway_light_286c0788b4c4  #网关灯
        brightness: 25
        color_name: green

⚠️ **GitHub.com Fallback** ⚠️