Template sensor Calculation HELP needed

Dear Hass Community,

I need your help:

I want to calculate currency exchange rates. I am using for this the API of fixer.

Now I want to add a new sensor. The Value of my new sensor “currency_calculated” should be:

1 / sensor value of “currency”

This is my code: What did I do wrong?

Thanks so much for your help!

  • platform: fixer
    api_key: XXX
    target: GBP
    name: currency

  • platform: template
    sensors:
    currency_calculated:
    value_template: {{ 1 / (states(‘sensor.currency’)) }}

Hello Jürgen,

I only have a vague idea about template calculating, but I find this thread useful.
Maybe it’s just a filter like | float or | int that’s missing.

1 Like

You have posted unformatted code so it’s difficult for others to detect syntax errors because all formatting is missing.

What I can see is that the last line of the Template Sensor is missing outer quotes and, in the calculation, fails to convert the sensor’s state value from a string to a number. It should be like this:

value_template: "{{ 1 / (states('sensor.currency') | float) }}"
1 Like