I having trouble rounding a double math template;
{{ state_attr(config.entity, 'price') | multiply(100.0)-79.03 | round(2) }}
Without the subtraction it will multiply and round. I tried various ways but the output is always a blank
I having trouble rounding a double math template;
{{ state_attr(config.entity, 'price') | multiply(100.0)-79.03 | round(2) }}
Without the subtraction it will multiply and round. I tried various ways but the output is always a blank
You are only rounding the number 79.03.
Add some brackets:
{{ ( state_attr(config.entity, 'price') | multiply(100.0)-79.03 ) | round(2) }}
Sorry Tom, but adding the bracket after subtraction gives me a blank as well.
Adding an opening bracket before multiply as well…
Try this:
{{ ( state_attr(config.entity, 'price')|float * 100 - 79.03 ) | round(2) }}
Nope! Still gives me 15 decimals
I’m surprised you got anything. You are missing quotes around the entity id.
{{ ( state_attr('config.entity', 'price')|float * 100 - 79.03 )|round(2) }}
Unless that is a variable?
Perhaps showing the full context would help.
It’s part of a litecoin view that I have. The latter part is a copy of the ‘secondary’ node, but there I multiply by the amount of coins and substract the start amount in euro’s.
Having wins or losses displayed
- entity: sensor.crypto_ltc_30_d
name: 30 Days
type: custom:template-entity-row
state: €{{ states(config.entity) | round(2) }}
secondary: >-
{{ state_attr(config.entity, 'price_change_pct') | multiply(100) |
round(4) }}%
icon: |
{% if states(config.entity) | float > 0 %}
mdi:arrow-up-bold
{% elif states(config.entity) | float < 0 %}
mdi:arrow-down-bold
{% else %}
mdi:arrow-right-bold
{% endif %}
- type: markdown
entity: sensor.crypto_ltc
content: >
<h1>€ {{ state_attr(config.entity, 'price') | multiply(0.99979276) -125.88 | round(2)
</h1> <br> start: €125,88 <br>litecoin: 0,99979276
icon: mdi:arrow-up-bold
You are still rounding the number:
And there are no closed braces }}
after your template. Try this:
- entity: sensor.crypto_ltc_30_d
name: 30 Days
type: custom:template-entity-row
state: €{{ states(config.entity) | round(2) }}
secondary: >-
{{ ( state_attr(config.entity, 'price_change_pct') | float * 100 ) | round(4) }}%
icon: |
{% if states(config.entity) | float > 0 %}
mdi:arrow-up-bold
{% elif states(config.entity) | float < 0 %}
mdi:arrow-down-bold
{% else %}
mdi:arrow-right-bold
{% endif %}
- type: markdown
entity: sensor.crypto_ltc
content: >
<h1>€ {{ ( state_attr(config.entity, 'price') | float * 0.99979276 - 125.88 ) | round(2) }}
</h1> <br> start: €125,88 <br>litecoin: 0,99979276
icon: mdi:arrow-up-bold
That did the trick! Thanks