Replacement for Yahoo Finance

I don’t see any new entities. I’ve installed from HACS and added to configuration.yaml:

sensor:
  - platform: yahoofinance
    show_trending_icon: true
    scan_interval:
      hours: 4
    symbols:
      - ISTNX
      - BTC-USD

as a test. Do I need to install anything else?

This seems to be going outside of the scope for a Home automation system.
Open source projects need to be careful of creeping wider and wider, or you end up with a bloated system that doesn’t suit it’s purpose.
I’m sure there are plenty of apps that will notify you if your share price drops

From what I can tell, the configuration should be similar to this:

yahoofinance:
  show_trending_icon: true
  scan_interval:
    hours: 4
  symbols:
    - ISTNX
    - BTC-USD

It’s not a sensor, it’s a whole different entity.
In Lovelace, you can use the Entity Card or Entities Card to display the entities.
Or use the custom Lovelace card auto-entities as mentioned earlier by @leolite1

An entity can’t be displayed as a graph however, as far as I know, but you can use Template Sensors, to convert a yahoofinance entity attribute to a sensor.

@leolite1’s Yahoo Finance integration is fantastic for tracking share’s. For those questioning it’s place in a home automation system, it definitely has one - getting TTS notifications via speakers, phone notifications, emails and flashing the lights a specific colour to buy or sell when prices hit a specified level is absolutely great and makes looking after a small portfolio a much more automated process. I am using the Mini Graph Card from HACS to build a Lovelace view specifically for monitoring share prices and alerting via my preferred method for each. It’s still very much a work in progress, but I am happy to share what I have so far.

I have an automation that runs every 5 minutes during UK and US market trading times (08:00-21:00 GMT Monday to Friday), and then various automations using the share prices as a trigger for sending notifications. The only thing I would like to do is get rid of the automatic update scan_interval provided by the integration and have the update triggered solely by the automation, hence having set scan_interval: hours: 24 in my configuration entry. @leolite1 maybe you could make this an option in the next release? e.g. setting hours: 0 would switch off automatic updates and allow this to be triggered solely by the automation.

Here’s the required entry in configuration.yaml (with actual shares removed and AMZN and MSFT substituted):

# Yahoo Finance integration
yahoofinance:
  scan_interval:
    hours: 24
  show_trending_icon: true
  symbols:
    - AMZN
    - MSFT
    ...

Then in Lovelace:

type: vertical-stack
cards:
  - type: markdown
    content: >-
      ## MSFT | Microsoft Corporation  

      &nbsp;&nbsp;<ha-icon icon="mdi:basket-outline"></ha-icon>
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Buy at $200
  - type: 'custom:mini-graph-card'
    entities:
      - entity: yahoofinance.msft
    name: Microsoft Corporation (Last 24 Hours)
    font_size_header: 12
    font_size: 90
    hours_to_show: 24
    hour24: true
    points_per_hour: 12
    line_width: 2
    smoothing: false
    show:
      labels: true
    color_thresholds_transition: hard
    color_thresholds:
      - value: 0
        color: '#4fc1ff'
      - value: 200
        color: orange
  - type: 'custom:mini-graph-card'
    entities:
      - entity: yahoofinance.msft
    name: Microsoft Corporation (Last 7 Days)
    font_size_header: 12
    font_size: 90
    hours_to_show: 168
    hour24: true
    points_per_hour: 4
    line_width: 2
    smoothing: false
    show:
      icon: false
      extrema: true
      labels: false
    color_thresholds_transition: hard
    color_thresholds:
      - value: 0
        color: '#4fc1ff'
      - value: 200
        color: orange

This generates a nice looking graph that will change colour dependent on target prices:

Here’s the automation for updating prices:

# Update the share prices every 5 minutes during trading hours
- id: 1209E804-F447-40E9-A310-98B1EEC00D66
  alias: 'Shares: Update prices'
  mode: single
  trigger:
    - platform: time_pattern
      minutes: '/5' # Minutes divisible by 5 i.e. every 5 minutes
  condition:
    - condition: time
      after: '07:59:00'  # UK market opens at 08:00
      before: '21:01:00' # US markets close at 21:00
      weekday:
        - mon
        - tue
        - wed
        - thu
        - fri
  action:
    - service: yahoofinance.refresh_symbols

And the automation for notifying via Alexa Media Player, email and the mobile app:

# Send notifications when Microsoft shares hit the target buy price
- id: 184E5AB9-BC4B-4082-91B8-D8DD0C81D114
  alias: 'Shares: Microsoft'
  mode: single
  trigger:
    - platform: numeric_state
      entity_id: yahoofinance.msft
      below: 200
  action:
    - service: notify.alexa_media
      data:
        target:
          - media_player.echo_show_living_room
          - media_player.echo_show_kitchen
          - media_player.echo_dot_bedroom
        title: Home Assistant
        data:
          type: announce
          method: all
        message: Share alert! Microsoft shares have hit $200. Now is potentially a good time to buy.
    - service: notify.rob_all_devices
      data:
        title: Share Alert for Microsoft
        message: Microsoft shares have hit $200. Now is potentially a good time to buy.
    - service: notify.email
      data:
        title: Share Alert for Microsoft
        message: Microsoft shares have hit $200. Now is potentially a good time to buy.
    - service: automation.turn_off
      entity_id: automation.shares_microsoft

Hopefully this will help someone. I am pretty new to Home Assistant (been using it for about 2 months), so it would be nice to be able to contribute something useful to the community, as I have been heavily reliant on the numerous posts on here for learning how it works and I have still got a long way to go before I understand all it’s capabilities.

Also, please note that MSFT and the $200 target used in this example are both arbitrary and not a recommendation to buy! :grinning:

9 Likes

I have to agree, having financial data inside a home automation system just allows for more ways to automate mundane tasks. I currently have home assistant placing trades and it makes dollar cost averaging that much easier.

1 Like

@PrairieSnpr Would you mind sharing a little about how you have automated placing trades? That sounds like taking this to the next level!

Certainly, I wrote a custom component to interface with the TDAmeritrade API (github). Example automations are on github, not doing anything fancy at the moment, basically just checking if there is enough available cash in the account and if so placing an order for the appropriate number of shares of a specific index fund.

I created https://github.com/iprak/yahoofinance/issues/22 to track this.

@leolite1 Great. Many thanks for the response. I look forward to the update. Keep up the great work.

@PrairieSnpr Thanks. Pity I can’t really use this as I am in the UK and the extra costs associated with not using the brokers I am already using wouldn’t make it worth my while. Nice for anyone using them already though. :slight_smile:

Great stuff !

I have done this integration last 2 days I`m also using influx.db and then import everything in Grafana …

You should try it … there are some nice graphs you can do and also link them to a monitor running under a pi let`s say …

I have set my scan interval to 0.01 so it wills can approx every 6 mins … even though I would like it to scan faster as there is a slight delay comparing to the trading platform … but nevertheless it`s a really nice option to get alerted using the automations :slight_smile:

I`m just wondering tho how beneficial is when you start loosing money for Alexa to keep telling you that and also that red bulb in your eyes all the time :slight_smile:

1 Like

it appears that in what regards the mini graph cards there is an issue

Logger: homeassistant.components.frontend
Source: components/frontend/init.py:253
Integration: Home Assistant Frontend (documentation, issues)
First occurred: 9:04:59 PM (1 occurrences)
Last logged: 9:04:59 PM

I don’t get any errors with the mini graph card.

You can use the automation I posted to update every 5 minutes on the dot, or increase it to every minute if you really wanted to. However, 5 minutes works fine for me.

I have yet to install and dabble with Grafana. I have seen some videos about it and it looks useful for this sort of thing. I will look into it futher down the line as I’ve got too many other automations to build first and even this one is still a work in progress.

Thanks for the new release with this in it. :grinning:

Many thanks for sharing your code. I re-used it to see how it works. Great so far.

Did anyone respond to your question?

I also wonder how to show the attributes of the stock.

You can simply create a template sensor, like any other template sensor, to use the value of any of the available attributes. In configuration.yaml:

sensor:
  - platform: template
    sensors:
      # MSFT Regular Market Change Percent sensor
      mstft_regular_market_change_percent:
        friendly_name: 'MSFT Regular Market Change Percent'
        icon_template: mdi:label-percent-outline
        unit_of_measurement: '%'
        value_template: "{{ state_attr('yahoofinance.msft', 'regularMarketChangePercent') }}"

The attributes are case sensitive, so they must match what you see under Developer Tools and not what is shown in the Lovelace GUI, which capitalises the first letter (i.e. ‘Regular…’ is actually lowercase ‘regular…’).

2 Likes

Thanks Robert!

May I ask another question? In the HA manual regarding the stocks, a piece of code is shared but I can’t get any result on this. I don’t know what’s wrong with it.

type: ‘custom:auto-entities’
card:
type: entities
title: Financial
filter:
include:
- group: group.stocks
options:
entity: this.entity_id
style: |
:host {
–paper-item-icon-color: {% set value=state_attr(config.entity,“trending”) %}
{% if value==“up” -%} green
{% elif value==“down” -%} red
{% else %} var(–paper-item-icon-color))
{% endif %};

Hi,

I have a question regarding a code snippet up mentioned on your Github page. It seems it doesn’t work so I miss something. I’m a HA newbie, maybe it’s too obvious the answer, sorry for that.

I can’t get a result out of this code. I created a card for this:

  • type: custom:auto-entities
    card:
    type: entities
    title: Financial
    filter:
    include:
    - group: group.stocks
    options:
    entity: this.entity_id
    style: |
    :host {
    –paper-item-icon-color: {% set value=state_attr(config.entity,“trending”) %}
    {% if value==“up” -%} green
    {% elif value==“down” -%} red
    {% else %} var(–paper-item-icon-color))
    {% endif %};

No problem. Nice to be able to help. I am still fairly new to Home Assistant myself. That code relies on the browser_mod HACS integration. Did you install/configure it?

1 Like