Closed jamiekris closed 3 years ago
It should work for funds too, I'm tracking a few myself. Can you share an example config that does not work and any error messages?
I think I misunderstood it initially. It works fine I think.
How would one track one's fund evolution over time? Simply plot ((current price - buy price) * number of shares)? In my config I have as below:
sensor:
How will I get entities that track the purchase price and number of shares?
If you have set shares
to some value there should be an attribute totalProfitLoss
which does exactly that calculation. To save that over time I would create a template sensor that extracts that attribute, look here https://www.home-assistant.io/integrations/template/#sun-angle for a simple example.
Is this the right approach? Seems like I am missing something still.
sensor:
- platform: avanza_stock
stock: 878733
name: Avanza Global
purchase_price: yyyy
shares: xxxx
template:
- sensor:
- name: Avanza Global Total Value
unit_of_measurement: "SEK"
state: "{{ '%+.1f'|format(state_attr('Avanza Global', 'TotalValue')) }}"
Looks about right except that TotalValue
should be totalValue
, so that probably gives you some error.
Strange... I tried to change to as below, but still the attribute value is not reported as an entity
template:
- sensor:
- name: Avanza Global Total Value
unit_of_measurement: "SEK"
state: "{{ '%+.1f'|format(state_attr('avanza_global', 'totalValue')) }}"
If it does not work there should be some kind of error in the log. I would otherwise try and remove the format stuff just use "{{ state_attr(...) }}"
The following seemed to do the trick
- platform: template
sensors:
avanza_global_current_holding:
value_template: '{{ states.sensor.avanza_global.attributes.totalValue}}'
unit_of_measurement: SEK
Thanks. I will close this issue! Very useful project btw!
I tried the same approach for a couple of funds, however seems not to work. Has this been discussed before? Might be a cool feature to add funds too.