1mfaasj
(Bowa)
April 5, 2024, 12:25pm
1
Hi
Any help is appreciated , I’ve got a strange issue with rounding the second value. Whatever I try I doesn’t give a short EUR value?!
The first is accepting it’s need for change, only the second one refuses.
type: vertical-stack
cards:
- type: horizontal-stack
cards:
- type: markdown
content: >
Difference:
**1l**: {{ (
states('sensor.carbu_com_super95_6129ne_stein_stadhouderslaan_price')|float(0)
-
states('sensor.carbu_com_super95_3630_gabriels_maasmechelen_price')|float(0)
) | round(2) }} EUR
**40l:** {{ ((
states('sensor.carbu_com_super95_6129ne_stein_stadhouderslaan_price')|float(0)
-
states('sensor.carbu_com_super95_3630_gabriels_maasmechelen_price')|float(0)
)) * 40 | round(2) }} EUR
result is everytime:
how both sensors look like:
& this one:
You’re just rounding the 40, try enclosing in brackets before rounding:
states(('sensor.carbu_com_super95_3630_gabriels_maasmechelen_price')|float(0)
)) * 40) | round(2) }} EUR
1mfaasj
(Bowa)
April 5, 2024, 12:37pm
3
you sure?
It gives me this error when trying:
TemplateSyntaxError: unexpected '}', expected ')'
code:
{{ (( states('sensor.carbu_com_super95_6129ne_stein_stadhouderslaan_price')|float(0)
- (( states(('sensor.carbu_com_super95_3630_gabriels_maasmechelen_price')|float(0) )) * 40) | round(2) }} EUR
Are you trying to do (sensor - sensor) *40 or sensor - (sensor *40) ?
The first I think ?
{{ ((states('sensor.carbu_com_super95_6129ne_stein_stadhouderslaan_price')|float(0) - states('sensor.carbu_com_super95_3630_gabriels_maasmechelen_price')|float(0)) *40) | round(2) }} EUR
1mfaasj
(Bowa)
April 5, 2024, 12:42pm
6
Yes and this one works thanks!
To explain the problem you encountered explicitly, filters (things that follow the pipe symbol ( |
). Apply only to the thing immediately before it. So your original approach was only rounding the 40, not the result of 40 multiplied by the sensor value.
Said more technically, filters are first in the order of operations .
1 Like