Hey.
I’ve created sensors for all my plants and they all have an attribute called “watering_interval”. Example:
- sensor:
- name: "Avocado"
unique_id: 7604a08d-1f22-49b8-98e2-e0c9b35a2308
unit_of_measurement: "Days"
icon: mdi:sprout
state: >
{% set dt = states('input_datetime.avocado') | as_datetime | as_local %}
{{ (dt.date() - now().date()).days | abs }}
attributes:
plant_name: "Persea Americana"
watering_interval: 7
datetime_id: "input_datetime.avocado"
I want to use auto-entities to list all plant sensors in a entity-progress-card, but because each plant has a different watering_interval, I want to use a template to provide the entity-progress-card with the “max_value”, like below:
type: custom:auto-entities
filter:
include:
- label: plant
domain: sensor
options:
type: custom:entity-progress-card
entity: this.entity_id
theme: optimal_when_low
max_value: "{{ state_attr('this.entity_id', 'watering-interval') }}"
icon_tap_action:
action: more-info
card:
square: false
type: grid
columns: 2
show_empty: true
card_param: cards
sort:
method: state
numeric: true
ignore_case: false
But this gives me the following error:
When I put it in the Template developer tool it does provide the correct information:
Is it even possible to use templates in auto-entities options or am I doing something wrong?
No idea about that particular progress card, just a guess that it does not accept jinja templates.
Means - you need to use a “template” option of auto-entities, see examples in auto-entities thread.
Btw, that main auto-entities thread is the proper place to ask related questions.
Also, “this.entity_id” is a variable, it should not be in quotes. Of course this not why the code does not work.
My bad, I will post in the correct thread next time. I’m managed to create a workaround by pasting the following in the template console in developer tools:
{% for plant in states.sensor if plant.attributes.watering_interval is defined %}
type: custom:config-template-card
entities:
- {{ plant.entity_id }}
variables:
max_value: 'states["{{ plant.entity_id }}"].attributes.watering_interval'
card:
type: custom:entity-progress-card
entity: {{ plant.entity_id }}
min_value: 0
max_value: '${parseFloat(max_value)}'
custom_theme:
- min: 0
max: ${parseFloat(max_value)}
color: green
- min: ${parseFloat(max_value)}
max: 1000
color: red
{% endfor %}
I paste the output in a grid card on my dashboard. Not as dynamic as I wanted but for now it works.
Edit:
Managed to get it working dynamically:
type: custom:auto-entities
card:
type: grid
columns: 2
square: false
card_param: cards
filter:
include:
- attributes:
watering_interval: "*"
options:
type: custom:config-template-card
entities:
- this.entity_id
variables:
max_value: states['this.entity_id'].attributes.watering_interval
datetime_id: states['this.entity_id'].attributes.datetime_id
card:
type: custom:entity-progress-card
entity: this.entity_id
min_value: 0
max_value: ${parseFloat(max_value)}
tap_action:
action: perform-action
perform_action: script.reset_olijfboom_date_helper
target: {}
data:
trig_id: ${datetime_id}
custom_theme:
- min: 0
max: ${parseFloat(max_value)}
color: green
- min: ${parseFloat(max_value)}
max: 1000
color: red
exclude: []
Are you talking about Lovelace-gen?