Using Homeassistant as my self hosted stock alert

I recently start to take an interest into the stock markets and investing into stocks directly instead of funds or the like. For some interesting stocks I was looking for an online stock alert website or app but soon realized that all of them required at least my email and would start sending me tons of spam mails. Why not use this great system I have at home the one which is focused on privacy?

Available Stock Sensors

Homeassistant does have the built in component alpha_vantage which requires an API key and in return offers you information on stocks and cryptocoins. Unfortunately the stock information is currently broken and I can only use it to track my Monero investment.

I took a short look in the HACS store and found the custom component avanza_stock.

The first stock sensor

Following the instructions I searched for the Microsoft stock, got the ID from the URL and created my first sensor:

  - platform: avanza_stock
    stock: 3873
    name: avanza_microsoft
      - change
      - changePercent
      - country
      - currency
      - 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

I am not sure if I will not all the attributes but I can always get rid of them again later. To display the sensor in the form of a stock tracker I chose the custom card mini-graph-card:


The configuration for this card is as follows:

- animate: true
    - sensor.avanza_microsoft
  graph: line
  hour24: true
  hours_to_show: 720 # 1 month
  name: Microsoft Stock last Month
    extrema: true
    icon: true
    name: true
  type: 'custom:mini-graph-card'

The stock alert system

I want to be notified when the tracked stock reaches a certain upper or lower limit. These limits change frequently so I don’t want to restart homeassistant every time I want to adjust the limits.

I chose input_text elements to hold my tresholds:

    icon: mdi:arrow-collapse-down
    name: Min Alert
    icon: mdi:arrow-collapse-up
    name: Max Alert

I combined them with an automation which sends me a notification as soon as the sensor is above the max or under the min limit:

- id: avanza_microsoft
  alias: Avanza Microsoft
    - platform: template
      value_template: >
    - platform: template
      value_template: >
    - service: notify.kevin
        message: >
          "Stock alert:  under threshold of "

I use Telegram as my notification system but you can use every supported notification component.

The whole sensor with the stock alert controls looks like this:


As soon as the sensor reaches a treshold I get a notification:


The Microsoft Alert did not trigger yet so I had to choose another stock ;-)

As always you can find the whole configuration in my repo under