GithubHelp home page GithubHelp logo

asx_sensor's Introduction

Australian Securities Exchange Sensor

hacs_badge hacs_badge

Creates sensors for Home Assistant for each ASX Symbol you provide

Lovelace Examples

Example of the entities in Lovelace

An Entity has 10 days information

Installation

This app is best installed using HACS, so that you can easily track and download updates.

Alternatively, you can download the asx_sensor directory from inside the apps directory here to your local apps directory, then add the configuration to enable the asx_sensor module.

How it works

The yfinance module sources the information from Yahoo Finance and makes the information available as sensors in HA.

This information is only daily information, showing the latest close data, and other relevant information about a stock, it does not provide actual trading information.

As this is non time critical sensor, it only gets the information on a set time schedule, once per day at 5.17am before the opening of the market.

To Run Manually

You will need to create an input_boolean entity to watch for when to update the sensor. When this input_boolean is turned on, whether manually or by another automation you create, the scraping process will be run to create/update the sensor.

AppDaemon Libraries

Please add the following packages to your appdaemon 4 configuration on the supervisor page of the add-on.

system_packages: []
python_packages: ["yfinance"]
init_commands: []

No specific packages are required for this app.

App configuration

In the apps.yaml file in the appdaemon/apps directory -

asx_sensor:
  module: asx_sensor
  class: Get_ASX_info
  TICKER: "CBA,TLS,BHP"
  TICK_FLAG: "input_boolean.check_asx_info"
key optional type default description
module False string asx_sensor
class False string Get_ASX_info
TICKER False string The comma separated symbols for each of the stocks you are interested in
TICK_FLAG False string The name of the flag in HA for triggering this sensor update - e.g. input_boolean.check_asx_info

Sensors Created

This version will create a sensor for each stock you provide

  • sensor.asx_sensor_XXX

Issues/Feature Requests

Please log any issues or feature requests in this GitHub repository for me to review.

asx_sensor's People

Contributors

chriswalker01 avatar simonhq avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

asx_sensor's Issues

Connection error

Hi Simon. Thanks for this project. I wondered whether the API has potentially changed as I am getting the following error after manually installing and configuring it. I am using Core version core-2021.1.4 and Superviser version supervisor-2021.01.5

2021-01-23 05:59:31.936321 INFO AppDaemon: Terminating asx_sensor
2021-01-23 05:59:31.945316 INFO AppDaemon: Initializing app asx_sensor using class Get_ASX_info from module asx_sensor
2021-01-23 05:59:31.973421 WARNING asx_sensor: asx_sensor: Entity sensor.asx_data_last_updated not found in namespace default
2021-01-23 05:59:31.978148 INFO AppDaemon: asx_sensor: Entity sensor.asx_data_last_updated created in namespace: default
2021-01-23 05:59:32.126534 WARNING asx_sensor: ------------------------------------------------------------
2021-01-23 05:59:32.128817 WARNING asx_sensor: Unexpected error running initialize() for asx_sensor
2021-01-23 05:59:32.133753 WARNING asx_sensor: ------------------------------------------------------------
2021-01-23 05:59:32.236846 WARNING asx_sensor: Traceback (most recent call last):
  File "/usr/lib/python3.8/site-packages/urllib3/connection.py", line 159, in _new_conn
    conn = connection.create_connection(
  File "/usr/lib/python3.8/site-packages/urllib3/util/connection.py", line 61, in create_connection
    for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM):
  File "/usr/lib/python3.8/socket.py", line 918, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno -2] Name does not resolve
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/usr/lib/python3.8/site-packages/urllib3/connectionpool.py", line 670, in urlopen
    httplib_response = self._make_request(
  File "/usr/lib/python3.8/site-packages/urllib3/connectionpool.py", line 381, in _make_request
    self._validate_conn(conn)
  File "/usr/lib/python3.8/site-packages/urllib3/connectionpool.py", line 976, in _validate_conn
    conn.connect()
  File "/usr/lib/python3.8/site-packages/urllib3/connection.py", line 308, in connect
    conn = self._new_conn()
  File "/usr/lib/python3.8/site-packages/urllib3/connection.py", line 171, in _new_conn
    raise NewConnectionError(
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPSConnection object at 0x757618f8>: Failed to establish a new connection: [Errno -2] Name does not resolve
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/usr/lib/python3.8/site-packages/requests/adapters.py", line 439, in send
    resp = conn.urlopen(
  File "/usr/lib/python3.8/site-packages/urllib3/connectionpool.py", line 724, in urlopen
    retries = retries.increment(
  File "/usr/lib/python3.8/site-packages/urllib3/util/retry.py", line 439, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='www.asx.com.au', port=443): Max retries exceeded with url: /asx/1/share/WOW/prices?interval=daily&count=1 (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x757618f8>: Failed to establish a new connection: [Errno -2] Name does not resolve'))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/usr/lib/python3.8/site-packages/appdaemon/app_management.py", line 150, in initialize_app
    await utils.run_in_executor(self, init)
  File "/usr/lib/python3.8/site-packages/appdaemon/utils.py", line 290, in run_in_executor
    response = future.result()
  File "/usr/lib/python3.8/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/config/appdaemon/apps/asx_sensor/asx_sensor.py", line 70, in initialize
    self.load()
  File "/config/appdaemon/apps/asx_sensor/asx_sensor.py", line 116, in load
    response = requests.request("GET", url, headers=self.headers, data = self.payload)
  File "/usr/lib/python3.8/site-packages/requests/api.py", line 61, in request
    return session.request(method=method, url=url, **kwargs)
  File "/usr/lib/python3.8/site-packages/requests/sessions.py", line 530, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/lib/python3.8/site-packages/requests/sessions.py", line 643, in send
    r = adapter.send(request, **kwargs)
  File "/usr/lib/python3.8/site-packages/requests/adapters.py", line 516, in send
    raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='www.asx.com.au', port=443): Max retries exceeded with url: /asx/1/share/WOW/prices?interval=daily&count=1 (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x757618f8>: Failed to establish a new connection: [Errno -2] Name does not resolve'))
2021-01-23 05:59:32.239169 WARNING asx_sensor: ------------------------------------------------------------

Adding ASX code A200 creates key error 0

When adding this ASX code to the ticker line of the yaml file the following error occurs:

TICKER: "VGS,VAS,A200"

2023-03-29 10:07:51.880121 WARNING Error: ------------------------------------------------------------
2023-03-29 10:09:17.735538 WARNING asx_sensor: ------------------------------------------------------------
2023-03-29 10:09:17.735861 WARNING asx_sensor: Unexpected error running initialize() for asx_sensor
2023-03-29 10:09:17.736096 WARNING asx_sensor: ------------------------------------------------------------
2023-03-29 10:09:17.736693 WARNING asx_sensor: Traceback (most recent call last):
  File "/usr/lib/python3.10/site-packages/appdaemon/app_management.py", line 165, in initialize_app
    await utils.run_in_executor(self, init)
  File "/usr/lib/python3.10/site-packages/appdaemon/utils.py", line 337, in run_in_executor
    response = future.result()
  File "/usr/lib/python3.10/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/config/appdaemon/apps/utils/asx_sensor.py", line 70, in initialize
    self.load()
  File "/config/appdaemon/apps/utils/asx_sensor.py", line 138, in load
    div_y = jtags[0]['year']
KeyError: 0

It appears to happen when adding any asx code that is alpha numeric.

Request unsuccessful. Incapsula incident

The ASX appear to be blocking automated/bot traffic to their api.

The app is no longer initializing, with errors similar to below in the logs.

Curl'ing https://www.asx.com.au/asx/share-price-research/company/BHP results in a similar error, while putting the url in a browser returns the expected json.

<html style="height:100%"><head><META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW"><meta name="format-detection" content="telephone=no"><meta name="viewport" content="initial-scale=1.0"><meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"><script type="text/javascript" src="/_Incapsula_Resource?SWJIYLWA=719d34d31c8e3a6e6fffd425f7e032f3"></script></head><body style="margin:0px;height:100%"><iframe id="main-iframe" src="/_Incapsula_Resource?SWUDNSAI=31&xinfo=11-20811742-0%200NNN%20RT%281707272883470%20260%29%20q%280%20-1%20-1%20-1%29%20r%280%20-1%29%20B12%284%2c315%2c0%29%20U24&incident_id=312001430051042670-103956453604729803&edet=12&cinfo=04000000&rpinfo=0&cts=9HnUVX%2bAbRhesKw%2bPBQlYcJY%2fqoo8pkO%2f4V83xur8xgbgq5I2ySdLdSlyv90WACi&mth=GET" frameborder=0 width="100%" height="100%" marginheight="0px" marginwidth="0px">Request unsuccessful. Incapsula incident ID: 312001430051042670-103956453604729803</iframe></body></html>

Do we need to change the headers or something?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.