How to pass info from one sensor to another?

Hi,
i want to ask for your opinion. I wanted to use the alpha_vantage platform which pulls currency exchange rates as well as stock prices by querying the alpha vantage api.
For stocks you can configure a currency: attribute, but this is only used to display the related icon and to set the unit_of_measurement. It does not mean that the stock price is converted to a desired currency.
For example

symbols:

  • symbol: GOOGL
    name: Google
    currency: EUR

Will show a Euro € in the gui, but the numeric value is still the price in Dollar (or whatever currency the Api returns together with the numeric value)

Now i started to introduce a new attribute convert_currency like this

symbols:

  • symbol: GOOGL
    name: Google
    currency: EUR
  • symbol: FLT.V
    name: Drone Delivery Canada
    currency: EUR
    convert_currency: USD_EUR

foreign_exchange:

  • name: USD_EUR
    from: USD
    to: EUR

This means: Alpha Vantage Api returns the price for FLT.V in USD, the price should be converted to EUR using the conversion rate which the sensor USD_EUR already “knows”.
This happens in the update-method of Entity FLT.V

Now my question: i implemented two methods how the conversion rate is transferred from Entity USD_EUR to Entity FLT.V

  1. Entity FLT.V runs self._hass.states.get(“sensor.usd_eur”)
  2. Entity USD_EUR writes the result of an update to self._hass.data[“DATA_alpha_vantage_USD_EUR”] where entity FLT.V reads it

What would be the proper way in homeassistant? Calling this internal Api or using shared memory?

Gerhard

Personally, I’d go with the first method. States are basically a big global variable. So if the information is already there, why duplicate it in the data dictionary?

Yes, that sounds reasonable. I’ll use the states.get(). My concern was that calls to the “internal api” would put more load on the system than a memory copy, but that’s nonsense for something that happens once a minute or less.
Gerhard