Custom component to get stock data from Avanza for Home Assistant.
The api changed recently, I'm trying to keep as much as possible working but some attributes may still not work. Please open an issues if you find something. The plan for the future is to create a new component that should be merged to homeassitant core.
The easiest way is to install it with HACS. First install HACS if you don't have it yet. After installation you can find this custom component in the HACS store under integrations.
Alternatively, you can install it manually. Just copy paste the content of the
sensor.avanza_stock/custom_components
folder in your config/custom_components
directory. As example, you will get the sensor.py
file in the following path:
/config/custom_components/avanza_stock/sensor.py
.
key | type | description |
---|---|---|
platform (Required) | string | avanza_stock |
stock (Required) | number / list | Stock id or list of stocks, see here and here. |
name (Optional) | string | Name of the sensor. Default avanza_stock_{stock} . Redundant if stock is defined as a list. |
shares (Optional) | number | Number of shar, can be fractional. Redundant if stock is defined as a list. |
purchase_date (Optional) | string | Date when stock was purchased. Redundant if stock is defined as a list. Does not get processed further. |
purchase_price (Optional) | number | Price paid when stock was purchased (per share). Redundant if stock is defined as a list. |
conversion_currency (Optional) | number | Index id used for currency conversion, see here. |
monitored_conditions (Optional) | list | Attributes to monitor, see here. |
invert_conversion_currency (Optional) | boolean | Wether or not to invert the conversion currency, default false. |
currency (Optional) | string | Overwrite currency given by the api. |
key | type | description |
---|---|---|
id (Required) | number | Stock id, see here. |
name (Optional) | string | Name of the sensor. Default avanza_stock_{stock} . |
shares (Optional) | number | Number of shares, can be fractional. |
purchase_date (Optional) | string | Date when stock was purchased. Does not get processed further. |
purchase_price (Optional) | number | Price paid when stock was purchased (per share). |
conversion_currency (Optional) | number | Index id used for currency conversion, see here. |
invert_conversion_currency (Optional) | boolean | Wether or not to invert the conversion currency, default false. |
currency (Optional) | string | Overwrite currency given by the api. |
If no monitored_conditions
is defined, change, changePercent and name will be tracked. Full list of available attributes, see here (With the new api change only change and changePercent is currently supported.) Note that the data from the api is not realtime but lagging behind by 15 minutes.
Got to Avanza and search for the stock you want to track. In the resulting url there is a number, this is the stock id needed for the configuration. Even though it is a Swedish bank it is possible to find stocks from the following countries: Sweden, USA, Denmark, Norway, Finland, Canada, Belgium, France, Italy, Netherlands, Portugal and Germany. To find conversion currencies search for example "USD/SEK" and look for the id in the resulting url. If you can not find your conversion try and search the reverse (NOK/SEK instead of SEK/NOK) and use the invert_conversion_currency
to get your preffered currency.
Configuration with default settings:
sensor:
- platform: avanza_stock
stock: 5361
Configuration with custom settings:
sensor:
- platform: avanza_stock
name: Avanza Bank Holding
stock: 5361
monitored_conditions:
- totalVolumeTraded
- totalValueTraded
Configuration with multiple stocks:
sensor:
- platform: avanza_stock
stock:
- id: 5361
name: Avanza Bank Holding
- id: 8123
name: Home Assistant
monitored_conditions:
- totalVolumeTraded
- totalValueTraded
Configuration with conversion currency:
sensor:
- platform: avanza_stock
stock:
- id: 238449
name: TESLA USD
shares: 1
purchase_price: 600
- id: 238449
name: TESLA SEK
shares: 1
conversion_currency: 19000
purchase_price: 7000
- id: 5361
name: Avanza Bank Holding (NOK)
conversion_currency: 53293
invert_conversion_currency: true
Configuration with untrackable stock, use id 0 and the purchase_price will be the current state:
sensor:
- platform: avanza_stock
stock:
- id: 0
name: MY STOCK
shares: 1
purchase_price: 600
currency: SEK
Automation to send summary at 18:00 using telegram:
# Telegram Stock Summary
- alias: 'Telegram Stock Summary'
initial_state: true
trigger:
- platform: time
at: '18:00:00'
action:
- service: notify.telegram
data:
message: '
<b>Stock Summary </b>
<code>
{{ states.sensor.avanza_stock_5361.attributes.name }} : {{ states.sensor.avanza_stock_5361.attributes.changePercent }}
</code>
'