| Name | Type | Scope |
|---|---|---|
| ADD_ARTICLE | String | public |
| CHANGE | String | public |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ... | |
| async def main(): | |
| listen = asyncio.create_task(initSocket()) | |
| log = asyncio.create_task(initLogger()) | |
| await listen | |
| await log | |
| if __name__ == "__main__": | |
| asyncio.run(main()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| async def initLogger(): | |
| print("Start logger...") | |
| await asyncio.sleep(1) | |
| while True: | |
| if len(cache) == 0: | |
| await asyncio.sleep(2) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| async def initSocket(): | |
| websocket = await asyncws.connect('ws://{}:{}/api/websocket'.format(host, port)) | |
| await websocket.send(json.dumps({'type': 'auth','access_token': token})) | |
| await websocket.send(json.dumps({'id': 1, 'type': 'subscribe_events', 'event_type': 'state_changed'})) | |
| print("Start socket...") | |
| while True: | |
| message = await websocket.recv() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| import time | |
| import asyncws | |
| import asyncio | |
| import threading | |
| import json | |
| token = HASS_IO_AUTHORIZATION_TOKEN # fill in your token | |
| host = HASS_IO_HOSTNAME_OR_URL # fill in your Home Assistant IP-address or domain |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # run command `$crontab -e` and add command below | |
| 0,30 * * * * /home/pi/webrequest.sh |