Scaling sensor values

I’ve been trying to figure out a way to scale sensor values in templates. Here’s what I’m trying to do: There is a great little add-on called YahooFinance that will go out periodically and get stock quotes. It turns out that stock-based funds from places like Vanguard and Fidelity can also be retrieved.

For stocks, it’s fine to say that Stock A has a current value of $123.45USD. Most of us buy stocks in lots of 5, 10, 100, etc. so it’s easy to calculate the total value we have invested. With funds, it’s not so cut-and-dry. When I give Vanguard $1K, they convert that into something like 123.456 shares of their fund. If the fund is worth say, $17.89 today, figuring out how much money is in one’s retirement account is hard to estimate quickly. However, when Vanguard sells me those 123.456 shares, that number is pretty much a constant, other than 1-2x per year when they buy/sell and make adjustments. So, all I want is:

{variable y} = {variable x} * 123.456

YahooFinance turns each tracked stock/fund into a sensor (sensor.yahoofinance_nnnnn). I’ve tried creating a new sensor with a value template that multiplies the old sensor by a constant, but it doesn’t seem to work. Most of the template documentation and examples focus on either a) if/then/else redirection; or b) formatting the end result (ex: time). I can’t find anything that helps me figure out why my templates either return zero, or ‘unknown.’

Does someone have a straightforward example of how to do what I want?

Thanks in advance for any assistance.

Regards,
-BW

value_template: "{{ states('sensor.variable_x')|float(0) * 123.456 }}"

Perfect! Thank you very much. FWIW, I was on the right track, but did not have the right number of sets of quotes (2).

Just for my understanding, why does one use |float(0) and not just |float ?

Regards,
-BW

The very first breaking change this month.