Skip to content
Custom component to get stock data from Avanza for Home Assistant
Python
Branch: master
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
custom_components/avanza_stock Add number of shares as optional conf May 6, 2019
tests Ignore dividends from the past Apr 13, 2019
.gitignore Initial commit Mar 10, 2019
.hound.yml Update .hound.yml Mar 29, 2019
LICENSE
README.md Add number of shares as optional conf May 6, 2019
TEST.md Add unit test support Apr 8, 2019
resources.json remove unnecessary resource May 5, 2019

README.md

sensor.avanza_stock

GitHub Release GitHub Activity custom_updater License

Project Maintenance BuyMeCoffee

Custom component to get stock data from Avanza for Home Assistant.

Installation

  1. Using the tool of choice open the directory (folder) for your HA configuration (where you find configuration.yaml).
  2. If you do not have a custom_components directory (folder) there, you need to create it.
  3. In the custom_components directory (folder) create a new folder called avanza_stock.
  4. Download all the files from the custom_components/avanza_stock/ directory (folder) in this repository.
  5. Place the files you downloaded in the new directory (folder) you created.
  6. 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

Configuration

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.

Monitored conditions

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

Finding stock id

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

Example

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

Usage

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.

Changelog

  • 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
You can’t perform that action at this time.