Custom component to get stock data from Avanza for Home Assistant.
- Using the tool of choice open the directory (folder) for your HA configuration (where you find
configuration.yaml
). - If you do not have a
custom_components
directory (folder) there, you need to create it. - In the
custom_components
directory (folder) create a new folder calledavanza_stock
. - Download all the files from the
custom_components/avanza_stock/
directory (folder) in this repository. - Place the files you downloaded in the new directory (folder) you created.
- Add a sensor
- platform: avanza_stock
to your HA configuration.
Using your HA configuration directory (folder) as a starting point you should now also have this:
custom_components/avanza_stock/__init__.py
custom_components/avanza_stock/sensor.py
custom_components/avanza_stock/manifest.json
key | type | description |
---|---|---|
platform (Required) | string | avanza_stock |
stock (Required) | number | The stock id, see below how to find it. |
name (Optional) | string | Custom name for the sensor. Default avanza_stock_{stock} . |
shares (Optional) | number | The number of shares you own of this stock. |
monitored_conditions (Optional) | list | Defines the attributes of the sensor, see below. |
The following attributes are tracked by default
- change
- changePercent
- name
Full list of available attributes.
- change
- changePercent
- country
- currency
- description
- directYield
- dividends
- flagCode
- hasInvestmentFees
- highestPrice
- id
- isin
- lastPrice
- lastPriceUpdated
- loanFactor
- lowestPrice
- marketCapital
- marketList
- marketMakerExpected
- marketPlace
- marketTrades
- morningStarFactSheetUrl
- name
- numberOfOwners
- orderDepthReceivedTime
- priceAtStartOfYear
- priceEarningsRatio
- priceFiveYearsAgo
- priceOneMonthAgo
- priceOneWeekAgo
- priceOneYearAgo
- priceSixMonthsAgo
- priceThreeMonthsAgo
- priceThreeYearsAgo
- pushPermitted
- quoteUpdated
- sector
- shortSellable
- superLoan
- tickerSymbol
- totalNumberOfShares
- totalValueTraded
- totalVolumeTraded
- tradable
- volatility
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
- Germany
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
Automation to send summary after stock market closes on workdays using telegram:
# Telegram Stock Summary
- alias: 'Telegram Stock Summary'
initial_state: true
trigger:
- platform: time
at: '18:00:00'
condition:
condition: state
entity_id: binary_sensor.workday
state: 'on'
action:
- service: notify.telegram
data:
message: '
<b>Stock Summary {{ states.sensor.date.state }}</b>
<code>
{{ states.sensor.avanza_stock_5361.attributes.name }} : {{ states.sensor.avanza_stock_5361.attributes.changePercent }}
</code>
'
Note: This automation could be further improved by looping over all sensors and checking if their entity_id starts with sensor.avanza_stock_
and then extract the information.
- 1.0.0 - Add number of shares as optional configuration
- 0.0.10 - Clean up monitored conditions
- 0.0.9 - Compare payment date with todays date, ignore time
- 0.0.8 - Ignore dividend if amount is zero, add resources.json and manfiest.json
- 0.0.7 - Changed to async setup
- 0.0.6 - Make sure dividend payment date has not passed
- 0.0.5 - Add dividends information
- 0.0.4 - Add companny information (description, marketCapital, sector, totalNumberOfShares)
- 0.0.3 - Add key ratios (directYield, priceEarningsRatio, volatility)
- 0.0.2 - Configure monitored conditions
- 0.0.1 - Initial version