Custom Component Avanza Stock

I guess you could set the scan_interval really high and then create some automation that calls the update_entity when you want it to. I do suspect that the graps would look the same though, so you probably have to create some custom graph-card…

I’ll look into it with the Discord community.

Thanks @claha

Anyone experiencing problems with Avanza integration after update to 2022.12? for me it stopped to update and in I can see multiple errors in log file (I guess one per configured stock id):

2022-12-09 11:48:29.884 WARNING (MainThread) [pyavanza] Response Error 404: Not Found
2022-12-09 11:48:29.968 WARNING (MainThread) [pyavanza] Response Error 404: Not Found
2022-12-09 11:48:29.969 WARNING (MainThread) [pyavanza] Response Error 404: Not Found
2022-12-09 11:48:29.970 WARNING (MainThread) [pyavanza] Response Error 404: Not Found
2022-12-09 11:48:29.987 WARNING (MainThread) [pyavanza] Response Error 404: Not Found

Yes, same behavior for me. Avanza obviously changed their API.
For now, until the component is updated, I extract it from the API with an own sensor:

- platform: command_line
    name: 'stock_name'
    command: curl -s -XGET 'https://www.avanza.se/_api/market-index/[PUT_ID_HERE]'
    scan_interval: 900
    value_template: "{{ value_json.quote.last | round (2) }}"

I will try to find some time to update, since there still seem to be an identical api available it should be easy. But work and two smal children doesn’t make it easier :laughing:

1 Like

Do you use the same endpoint for funds and currencies? If you have any

For currencies I actually use a different website: exchangerates.


  - platform: command_line
    name: 'EUR/USD'
    command: curl -s -XGET 'https://api.exchangerate.host/latest?base=EUR&symbols=USD'
    scan_interval: 600
    unit_of_measurement: 'USD'
    value_template: "{{ value_json.rates.USD | round(4) }}"

1 Like

Just released v1.1.0 that uses the new api. State and the change/changePercent attributes should at least work now :slight_smile:

Please let me know if you find issues!

I got a strange issue with this component.
There is different behavior based on what card am using.

First we have a standard entity card.
No issues here, the attribute value is presented without problem.

type: entity
entity: sensor.lansforsakringar_global_indexnara
attribute: changePercentOneWeek

Next we have the entities card and here it is not working.
Any other attribute value then “change” or “ChangePercent” renders no value.

type: entities
entities:
  - type: attribute
    entity: sensor.lansforsakringar_global_indexnara
    attribute: ChangePercentOneWeek
    name: Fond
    unit: '%'

I know there is value in the entity (obviously) so why is it not working working?
Is it something to do with the API changes as it only works on those two attributes?

This is my component setup:

  - platform: avanza_stock
    stock:
      - id: 417655
        name: 'Länsförsäkringar Global'

No conditions set.

What version of avanza_stock are you using and how does it look in Developer Tools → States?

Using v1.1.2.

States looking fine:

Ok, seems like the sensor work as expected. The only thing I can see is that you used a uppercase c in ChangePercentOneWeek, should be lowercase

1 Like

Well this is very strange!

That fixes the issue but I could swear that this is not what it said just a few days ago.
I remember noting a different capitalization between ChangePercentOneWeek and changeOneWeek, that I followed like a good boy :innocent:

I did check and DOUBLE CHECK that the capitilization was correct.
I even ctrl-C ctrl-V between the two different card types at one point (as I know this is sensitive).

Did this change between some version of this component?
I did re-downloaded this component (not an upgrade as it was up to date) after your question regarding my version, that was just before I took the screenshoot of the states and I did not check that page again after.

Not that it matters, except for my own pride :grimacing:

I checked the commits in git and as far as I can tell they have always been with a lowercase c :grinning_face_with_smiling_eyes:

Hi! What about the dividend information for ETFs? Possible to add?

Actually added the needed functionality in pyavanza for ETFs last week (Commits · claha/pyavanza · GitHub) :blush: So I just need to see if there is some way to determine if a stock (i.e. retrieved using get_stock) is actually an ETF or if we need a new config option to tell the component that it is an ETF. Might have some time this weekend :grin:

1 Like

That is great news Claes! :smiley::+1:

Found some time today when the little one was sleeping, so new version out that “magically” finds out if a stock is actually an etf :grin:

1 Like

profitLossPercantage doesnt seem to work for me…

Theres no way the last one has increased 3345% in 1 year. (purchase date). I know for a fact, looking at Avanza, that the % should be around 43%.

What am i doing wrong?
These are the columns and attributes i use in this card.

dataColumns:
  - header: Name
    attr: name
  - header: Change
    attr: change
    format: percentage
    showSummary: true
  - header: '%'
    attr: profitLossPercentage
    format: percentage

image

Seems to work fine for me. Could you check the profitLoss and profitLossPercentage attributes using “Developer tools → States” to rule out that the custom card does something with the value.