Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mgottholsen/d2ecc2889d5adf7ea093aa67801f6aad to your computer and use it in GitHub Desktop.
Save mgottholsen/d2ecc2889d5adf7ea093aa67801f6aad to your computer and use it in GitHub Desktop.
Getting camera images from esp32cam with esphome and python
#!/usr/bin/env python3
import aioesphomeapi
import asyncio
async def main():
loop = asyncio.get_running_loop()
cli = aioesphomeapi.APIClient(loop, "HOST-OR-IP", 6053, "API-PASSWORD-OR_EMPTY")
await cli.connect(login=True)
def cb(state):
if type(state) == aioesphomeapi.CameraState:
try:
with open('out/x.jpg','wb') as out:
out.write(state.image)
print("Image written")
except Exception as e:
print(e)
await cli.subscribe_states(cb)
l = await cli.list_entities_services()
print(l)
loop = asyncio.get_event_loop()
try:
asyncio.ensure_future(main())
loop.run_forever()
except KeyboardInterrupt:
pass
finally:
loop.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment