From ad5ae4f11bb9bfeb7648a17e26e73b7d714fc8e0 Mon Sep 17 00:00:00 2001 From: Denys Dovhan Date: Thu, 21 Apr 2022 23:16:39 +0300 Subject: [PATCH] feat: provide value inside value_template --- README.md | 18 +++++++++--------- src/purifier-card.js | 1 + 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 3911721..ed8c434 100644 --- a/README.md +++ b/README.md @@ -73,8 +73,8 @@ stats: - attribute: motor_speed unit: RPM subtitle: Motor Speed - - value_template: >- - {{ (states('sensor.purifier_filter_life') | float(0) / 3600) | round(1) }} + - entity_id: sensor.purifier_filter_life + value_template: '{{ (value | float(0) / 3600) | round(1) }}' unit: hours subtitle: Filter Life shortcuts: @@ -130,13 +130,13 @@ Here is what every option means: You can use any attribute of purifier or even any entity by `entity_id` to display by stats section: -| Name | Type | Default | Description | -| ---------------- | :------: | -------- | ---------------------------------------------------- | -| `entity_id` | `string` | Optional | An entity_id with state, i.e. `sensor.purifier_aqi`. | -| `attribute` | `string` | Optional | Attribute name of the stat, i.e. `filter_left`. | -| `value_template` | `string` | Optional | Jinja2 template returning a value. | -| `unit` | `string` | Optional | Unit of measure, i.e. `hours`. | -| `subtitle` | `string` | Optional | Friendly name of the stat, i.e. `Filter`. | +| Name | Type | Default | Description | +| ---------------- | :------: | -------- | ---------------------------------------------------------------------------------------------------- | +| `entity_id` | `string` | Optional | An entity_id with state, i.e. `sensor.purifier_aqi`. | +| `attribute` | `string` | Optional | Attribute name of the stat, i.e. `filter_left`. | +| `value_template` | `string` | Optional | Jinja2 template returning a value. `value` variable represents the `entity_id` or `attribute` state. | +| `unit` | `string` | Optional | Unit of measure, i.e. `hours`. | +| `subtitle` | `string` | Optional | Friendly name of the stat, i.e. `Filter`. | ### `shortcuts` object diff --git a/src/purifier-card.js b/src/purifier-card.js index a02f436..2089ba0 100644 --- a/src/purifier-card.js +++ b/src/purifier-card.js @@ -325,6 +325,7 @@ class PurifierCard extends LitElement { hass=${this.hass} template=${value_template} value=${state} + variables=${{ value: state }} > `;