Custom Component Avanza Stock

I’ve created an own thread for the Entities table card, notifications about updates will be posted here: Entities table card

Hi, I just installed this, and it looks very good.
But I have some questions. My sensor config looks like this:

  shares: 222
  purchase_date: "2021-10-21T-00:00+00"
  purchase_price: 2991.32

the price is in euro (the stock is also in euro)
In the sensor’s attributes, I get this:

shares: 222
totalValue: 5066.04
purchaseDate:  2021-10-21T-00:00+00
purchasePrice: 2991.32
profitLoss: -2968.5
totalChange: -39.96
profitLossPercentage: -99.24
totalProfitLoss: -659007

Could someone explain the meaning of the last 4 values to me please?
If I calculate 2991.32-5066.04 I get -2074.72 not -2968.5 for profitLoss.

Also, I couldn’t find any information about the date format. Is the above the correct one?

Thanks

Hi!

profitLoss is the current price minus purchasePrice.
totalChange is todays change mulitplied with shares.
profitLossPercentage is how much the price has changed compared to purchasePrice
totalProfitLoss is profitLoss multiplied by shares.

In your example totalValue is the current price multiplied by shares

Ah, thank you.
What irritated me was the purchase_price in the sensor config is per share and profitLoss is profit or loss not the loss of profit.

Do I even need the prurchaseDate if I provide the purchasePrice already?

Sorry I missed your question about the date. It is just a string, not used for anything so you can remove it. It was requested by someone to have, not sure what they use it for.

I can’t find the ID corresponding to MSOS symbol on Avanza. It’s an ETF trading on the NYSE it should be easy to find but it’s not on Avanza website :frowning:

Unfourtnately (I think it is beacuse of EU-law) not all US based ETF are possible to invest in through Avanza :frowning:

Just wondering, is this an issue specific to MSOS ETF, or other ETFs are also blocked in Europe? Is this due to the legal status of cannabis in EU?

There are a lot of ETFs that are blocked/not available, dont think has anything to do with cannabis.

I installed the entities-table-card via hacs but whatever i do: no result:

type: custom:entities-table-card
name: Portfolio
showSummary: true
entities:
  - entity: sensor.btc_eur
dataColumns:
  - header: Name
    attr: name
  - header: Daily
    attr: changePercent
    format: percentage
  - header: State
    source: state
    format: number
  - header: '%'
    attr: profitLossPercentage
    format: percentage
  - header: Profit/Loss
    attr: totalProfitLoss
    format: currency
  - header: Value
    attr: totalValue
    format: currency

tried various versions of the card but none of them are working , anybody a hint?

found the issue.

in configuration.yaml I needed to add

    monitored_conditions:
      - totalVolumeTraded
      - totalValueTraded
      - change
      - changePercent

Hello!

I find this HACS very interesting but while setting my configuration.yaml, I cannot pass the verification. It keeps running and I can’t get the Configuration Valid! confirmation.

sensor:

  - platform: avanza_stock
    stock:
      - id: 789695
        name: Nouveau Monde Graphite
        shares: XXX
        purchase_price: 19.17
      - id: 691678
        name: Euro Sun Mining
        share: XXX
        purchase_price: 2.12
    monitored_conditions:
      - totalVolumeTraded
      - totalValueTraded
      - change
      - changePercent
      - lastPrice

Is there something I am missing here?

Your second entry has share, should be shares. Maybe that’s it?

Even correcting that mistake, I cannot pass the verification for my YAML file.

And if I remove the code for avanza_stock, it’s fine

Could you please post your logs, found under Settings->System->Logs.

I don’t know if it can help because Home Assistant did not run while this integration was working, but I did added the code to configuration.yaml and start the verification, while it was checking I looked into logs and I saw this:

I am reluctant to restart Home Assistant with the code in configuration.yaml since it does not pass the inspection.

Have you restarted homeassistant after adding the custom component in HACS, I think you need to do it once for homeassistant to pick it up.

Also homeassistant has this “safe mode” so if your config is invalid when you restart it you will be able to to fix it and restart again. So dont be afraid to restart :slight_smile:

I was almost certain I had reset HA after adding the HACS, but I guess I didn’t… After restarting I could add the code to configuration.yaml, and it is working!

Can you let me know the frequency update of the values pulled from Avanza and if we can adjust these.

Default is one hour, see this discussion on how to change it https://github.com/custom-components/sensor.avanza_stock/issues/125#issuecomment-967235632

Great, I managed to configure the frequency update. Thanks @claha!

Is there a way to tell a graph not to record data between 16:30 and 9:30? Most stock market are closed between those times and graphs get a steady value for many hours.

That would be very useful to have a graph that look similar to the real stock market.