I am trying to round the result of a template sensor to 2 decimal places would like some help of how to best place the rounding syntax.
This is what I have so far
sensor:
- platform: alpha_vantage
api_key: !secret alphavantage_key
foreign_exchange:
- from: AUD
to: USD
name: AUD_USD
- from: USD
to: GBP
name: USD_GBP
- from: BTC
to: AUD
name: Bitcoin
## AUS to GBP Conversion - Did this as for some reason alpha vantage doesn't provide AUD to GBP Rates propably due to being USD based site
- platform: template
sensors:
aud_to_gbp:
unit_of_measurement: 'GBP'
value_template: "{{ states('sensor.aud_usd')|float * states('sensor.usd_gbp')|float }}"
friendly_name: 'AUD to GBP'
can I just add something like '%+.2f'|format to the front of the value_template?
Little offtopic, you can try the Developer tools Template page to verify the output
I also just created a template value and also used round(2) a t the end to give it 2 decimals, but if the value_template is alright like that i’m not sure, try with the Developer Tools and then the Template page
The expression doesn’t fail, it just doesn’t round(2), I have successfully used this function in other templates this is the only one where I am multiplying the result of 2 separate sensors states and need to round the entire. Maybe I need to encompass in brackets