sensor.avanza_stock icon indicating copy to clipboard operation
sensor.avanza_stock copied to clipboard

accept templates as element for the field "shares"

Open ggonmar opened this issue 1 year ago • 5 comments

Proposing a nice enhancement: I think it would be great if we could set the number of shares via a template, coming from an input number, or any other service:

- platform: avanza_stock
  stock:
    - id: 506278
      name: Stocks:Alibaba
      shares: {{ states("input_number.shares_of_alibaba") }}
      purchase_price: {{ states("input_number.purchase_price_alibaba") }} 

This way, one could easily update the sensor without having to dig into the code to change that value!

ggonmar avatar Oct 09 '24 15:10 ggonmar

This would be really nice.

oli737 avatar Oct 09 '24 17:10 oli737

I'll see what I can do, the proper way would probably be if this component created that input_number sensor by itself. But the code for this is so far behind...

claha avatar Oct 09 '24 18:10 claha

Got some time to test this today, it was easy to allow a template in the config and it gets the value correctly. What's left is to figure out how to make it responsive to changes made in the referenced states in the template

claha avatar Oct 13 '24 18:10 claha

How to try it?

oli737 avatar Oct 14 '24 19:10 oli737

Here is the branch, but as I said above it will only pull the value of the template when HA is started

https://github.com/custom-components/sensor.avanza_stock/tree/shares-template

claha avatar Oct 16 '24 21:10 claha