Combine Avanza and yahoo stock information

Some stocks are not available from avanza and therefor could not be used in the avanza integration with the entities-table-card.

How would I simulate a new sensor with states/attributes feeded from a yahoofinance sensor and combined with additional static or calculated information to display them in an entities table?

Below my entities table definition.
I assume a sensor with state fro yahoofinanze as state and additional attributes name (constant string), purchaseDate (constant string), profitLossPercentage (Needs to be calculate using state and two constant values), totalProfitLoss (Needs to be calculate using state and two constant values) and totalValue (Needs to be calculate using state and one constant value) would work, but I have no idea how the template(?) has to look like.

dataColumns:
  - header: Name
    attr: name
  - header: Kurs
    source: state
    format: number
  - header: Kaufdatum
    attr: purchaseDate
    format: number
  - header: '%'
    attr: profitLossPercentage
    format: percentage
  - header: Gewinn/Verlust
    attr: totalProfitLoss
    format: currency
    showSummary: true
  - header: Aktueller Wert
    attr: totalValue
    format: currency
    showSummary: true

I would look at the Add Custom Attributes example here https://www.home-assistant.io/integrations/template/#add-custom-attributes

1 Like

Thanks for that hint!

Is there a way to use variables or constants instead of entering the same value several times? As you can see in my example below, I have define the number of share and have entered the same value in purchasePrice. Same with value 5000 used in purchasePrice, totalProfitLoss and profitLossPercentage.

      deka_mdax:
        value_template: >-
          {{ states('yahoofinance.x2hf_de') }}
        attribute_templates:
          name: >-
            Deka MDax
          purchaseDate: >-
            29.10.2020
          shares:  >-
            {{ float(15) }}
          purchasePrice: >-
            {{ float(5000/15) }}
          totalValue: >-
            {{         15 * (states('yahoofinance.x2hf_de') | float) }}
          totalProfitLoss: >-
            {{         15 * (states('yahoofinance.x2hf_de') | float) - 5000 }}
          profitLossPercentage: >-
            {{ (100 * (15 * (states('yahoofinance.x2hf_de') | float) - 5000) / 5000) | round(2) }}