#Convert number to string

3 messages · Page 1 of 1 (latest)

sterile peak
#

I'm using API Ninjas to add some fun stuff to my kids morning briefings. There is one which will return a "on this day" fact. I want to generate a random number between 1900 and 2023 to feed into the API so I only get "recent" events. The API requires a string input, but for the life of me I cannot get home assistant to convert the number into a string. I've tried piping the result into string, using string(), etc and every time the result remains as a number. Any help on this is greatly appreciated!

hardy idol
#

Try:

| string

example.
Numeric:

{% set home_humidavg = 10 | float(0) %}
{% set onsuite_humid = 35 | float(0) %}
{{ ( onsuite_humid  - home_humidavg ) | round(2) }}

Setting one numeric to string, it will complain

{% set home_humidavgalt = 10 | string %}
{% set onsuite_humidalt = 35 | float(0) %}
{{ ( onsuite_humidalt  - home_humidavgalt ) | round(2) }}
#
TypeError: unsupported operand type(s) for -: 'float' and 'str'