eric1905
(Eric1905)
1
Hello everyone. I am having a strange behavior in my lovelace UI.
I am working with a decluttering card and I want to hand over a number as a variable:
- type: custom:decluttering-card
template: weather_now_template
variables:
- coverage: '100'
Within the decluttering template I am storing the variable in a jinja variable and want the value to display:
weather_now_template:
card:
type: custom:stack-in-card
cards:
- type: markdown
content: >-
{% set coverage ='[[coverage]]'%}
Value: "{{coverage}}"
Value: "{{coverage|int}}"
The output is:
Value: “100” Value: “0”
But there seems to be a problem to convert this to int. This expression is always 0. Why is this the case and how can I fix this?
Have you tested in Template section in Developer Tools?
It seems it’s not an issue regarding jinja2 functions
Troon
(Troon)
4
Try removing one set of quotes, so either:
variables:
- coverage: 100
or
{% set coverage = [[coverage]] %}
eric1905
(Eric1905)
5
When I change it to:
{% set coverage =[[coverage]]%}
I get:
Value: “[[Undefined]]” Value: “0”
When I change both without the quotes it is still undefined.
When I only change
- coverage: 100
it is Value: “100” Value: “0” again.
eric1905
(Eric1905)
6
yes. There is no problem.
Even when I change this code in my decluttering_card it is working:
{% set coverage ='100'%}
Value: "{{coverage}}"
Value: "{{coverage|int}}"
Both values are 100
eric1905
(Eric1905)
8
only {{coverage}} is working. But I need the value as an integer, because i want to do something like this:
Value: "{{coverage<20}}"
that a test and would be between {% %}
in regards of these statement:
Blockquote
{% set coverage =‘[[coverage]]’%}
Value: “{{coverage}}”
Value: “{{coverage|int}}”
Where are you getting [[coverage]] from?
If it’s an entity, you should get it from something likethat: states(‘number.entity_name’)
Blockquote
{% set coverage = states(‘input_number.flowers_shifted’) %}
Value: “{{coverage}}”
Value: “{{coverage|int}}”
Troon
(Troon)
10
Read the top of the topic: it’s coming from the decluttering card. Something odd is happening in the way it’s being brought across.
No, it’s a statement that returns true
or false
.