Config Template Card 使用教程

Config Template Card 使用教程

config-template-card📝 Templatable Lovelace Configurations项目地址:https://gitcode.com/gh_mirrors/co/config-template-card

1. 项目介绍

Config Template Card 是一个用于 Home Assistant 的 Lovelace UI 插件,允许用户在配置中使用 JavaScript 模板。通过这个插件,用户可以动态地生成和更新 Home Assistant 的 UI 元素,从而实现更灵活和个性化的界面配置。

2. 项目快速启动

安装

首先,确保你已经安装了 Home Assistant 并且版本在 0.110.0 或更高。然后,你可以通过 HACS(Home Assistant Community Store)来安装 Config Template Card。

  1. 打开 Home Assistant 的 HACS 界面。
  2. 导航到“前端”部分。
  3. 搜索“Config Template Card”并点击安装。
  4. 安装完成后,重启 Home Assistant。

配置

安装完成后,你可以在 Lovelace 配置中使用 Config Template Card。以下是一个简单的配置示例:

type: entities
entities:
  - type: 'custom:config-template-card'
    variables:
      - states['light.bed_light'].state
    entities:
      - light.bed_light
    row:
      type: section
      label: "$[vars[0] === 'on' ? 'Light On' : 'Light Off']"
  - entity: light.bed_light

在这个示例中,我们使用了一个模板来动态显示灯的状态。

3. 应用案例和最佳实践

动态显示状态

Config Template Card 最常见的用途是动态显示实体的状态。例如,你可以根据传感器的状态来显示不同的图标或文本。

type: picture-elements
image: http://hs-sbcounty.gov/CN/Photo%20Gallery/_t/Sample%20Picture%20-%20Koala_jpg.jpg
elements:
  - type: 'custom:config-template-card'
    variables:
      - states['light.bed_light'].state
    entities:
      - light.bed_light
      - sensor.light_icon_color
    element:
      type: icon
      icon: "$[vars[0] === 'on' ? 'mdi:home' : 'mdi:circle']"
      style:
        '--paper-item-icon-color': "$[states['sensor.light_icon_color'].state]"
      style:
        top: 47%
        left: 75%

全局函数

如果你需要在多个地方重复使用相同的逻辑,可以在变量中定义全局函数,然后在模板中调用这些函数。

type: 'custom:config-template-card'
variables:
  setTempMessage: |
    temp => {
      if (temp <= 19) {
        return 'Quick, get a blanket!';
      } else if (temp >= 20 && temp <= 22) {
        return 'Cozy';
      }
      return 'It's getting hot in here!';
    }
  currentTemp: states['climate.ecobee'].attributes.current_temperature
entities:
  - climate.ecobee
card:
  type: entities
  entities:
    - entity: climate.ecobee
      name: "$[setTempMessage(currentTemp)]"

4. 典型生态项目

Config Template Card 通常与其他 Home Assistant 插件和组件一起使用,以实现更复杂的自动化和 UI 定制。以下是一些常见的生态项目:

  • Home Assistant: 作为 Config Template Card 的基础平台,Home Assistant 提供了丰富的自动化和集成功能。
  • HACS (Home Assistant Community Store): 用于管理和安装社区开发的插件,包括 Config Template Card。
  • Lovelace UI: Home Assistant 的默认用户界面,Config Template Card 可以在这里进行配置和展示。

通过结合这些项目,用户可以创建高度定制化和动态的 Home Assistant 界面。

config-template-card📝 Templatable Lovelace Configurations项目地址:https://gitcode.com/gh_mirrors/co/config-template-card

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

黎情卉Desired

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值