Skip to content

Instantly share code, notes, and snippets.

@micw
Created February 6, 2020 19:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save micw/202f9dee5c990f0b0f7e7c36b567d92b to your computer and use it in GitHub Desktop.
Save micw/202f9dee5c990f0b0f7e7c36b567d92b 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()
@lululombard
Copy link

This is no longer working and needs some updates

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment