Skip to content

Instantly share code, notes, and snippets.

...
async def main():
listen = asyncio.create_task(initSocket())
log = asyncio.create_task(initLogger())
await listen
await log
if __name__ == "__main__":
asyncio.run(main())
async def initLogger():
print("Start logger...")
await asyncio.sleep(1)
while True:
if len(cache) == 0:
await asyncio.sleep(2)
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()
#!/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
@jeroenboumans
jeroenboumans / PiHole Cronjob
Last active September 9, 2018 09:32
Pihole-Counter for Pimononi LED Phat
# run command `$crontab -e` and add command below
0,30 * * * * /home/pi/webrequest.sh
@jeroenboumans
jeroenboumans / DocumentationClass.md
Last active July 3, 2018 07:26
Template for class documentation