custom-components / sensor.avanza_stock

Custom component to get stock data from Avanza for Home Assistant
MIT License
46 stars 10 forks source link

accept templates as element for the field "shares" #185

Open ggonmar opened 1 month ago

ggonmar commented 1 month ago

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!

oli737 commented 1 month ago

This would be really nice.

claha commented 1 month ago

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 commented 3 weeks ago

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

oli737 commented 3 weeks ago

How to try it?

claha commented 3 weeks ago

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