@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
<ha-icon icon="mdi:basket-outline"></ha-icon>
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!