Skip to main content

A Python implementation of the new La Marzocco API

Project description

La Marzocco Client

This is a library to interface with La Marzocco's "new" Home machines (currently only the Micra).

It's in experimentals stages and meant mainly to connect to the Micra, as for the other IoT enabled machines you can use the lmdirect library.

Libraries in this project

  • lmlocalapi calls the new local API the Micra exposes, using the Bearer token from the customer cloud endpoint. However, this API currently only supports getting the config, and some status objects (like shottimer) over websockets, but does not support setting anything (to my knowledge). Local settings appear to only happen through Bluetooth connections. If La Marzocco updates the firmware or more endpoints are found this library will be updated to reflect those additional endpoints.
  • lmcloud interacts with gw.lamarzocco.com to send commands. lmcloud can be initialized to only issue remote commands, or to initialize an instance of lmlocalapi for getting the current machine settings. This helps to avoid flooding the cloud API and is faster overall.
  • lmbluetooth provides a bluetooth client to send settings to the machine via bluetooth

Because of that reason the config object self._config in the lmcloud instance without utilizing the local API will always at least be 10 seconds old. This is to avoid automatic property checks (e.g. from HomeAssistant) to spam the cloud API. If you really require a most recent config you can call the method get_config().

Setup

lmcloud

To run lmcloud you will first need to create a dict, containing clientId, clientSecret, username and password.

username and password are easy to get because those are the credentials you're using to sign into the La Marzocco Home app.

clientId and clientSecret are harder to get. The "easiest" way is to configure mitmproxy on a PC, configure your WiFi settings on your phone to use that proxy. Then log out of your La Marzocco App, sign in again and watch for a call to https://cms.lamarzocco.io/oauth/v2/token. The credentials you're looking for will be in that call. More of the calls are documented in remote_rest.

You then need to create a file called config.json looking like this:

{
    "client_id": "long_string",
    "client_secret": "long_string",
    "username": "email",
    "password": "password",
    "host": "192.168.1.123" # optional, only if you want the local API
}

Which then needs to be passed into a dictionary:

with open("config.json") as f:
    data = json.load(f)

creds = {
    "client_id": data["client_id"],
    "client_secret": data["client_secret"],
    "username": data["username"],
    "password": data["password"]
}

lmcloud exposes two classmethods: One to build an instance with the local API, and one to build an instance relying entirely on cloud functions.

It is initialized like this

lm_cloud = await LMCloud.create(creds) # cloud only
lm_cloud = await LMCloud.create_with_local_api(creds, ip=ip) # with local API

lmlocalapi

If you just want to run the local API you need the IP of your machine, the Port it is listening on (8081 by default), the Bearer token (communicationKey) used for local communication. You can obtain that key by inspecting a call to https://cms.lamarzocco.io/api/customer, while connected to mitmproxy (process above), or making a new (authenticated) call to that endpoint. lmcloud will also connect to this endpoint so you could also used a breakpoint there to get this key, which is stored in a key called communicationKey.

Then you can init the class with

lm_local_api = LMLocalAPI(ip, bearer)

Websockets

The local API initiates a websocket connection to

http://{IP}:8081/api/v1/streaming

The packets which are received on that WebSocket are documented in websockets

If WebSockets are enabled the shot timer becomes available to use, however as long as the library is running in WebSocket mode, the App will no longer be able to connect.

To use WebSockets start the integration with

lm = await LMCloud.create_with_local_api(creds, <IP>, port=8081, use_websockets=True)

while True:
    print(lm._lm_local_api.active_brew) # is a brew running at the moment
    print(lm._lm_local_api.active_brew_duration) # the current shot timer returned by the machine

lmbluetooth

Some commands, like turning the machine on and off are always sent through bluetooth whenever possible. The available bluetooth characteristics are described in bluetooth_characteristics. The class LMBluetooth discovers any bluetooth devices with Micra in the name and connects to it. Then we can send local bluetooth commands.

To use Bluetooth you can either init LMCloud with

    lm = await LMCloud.create_with_local_api(creds, <IP>, port=8081, use_bluetooth=True)

or even init the Bluetooth client standalony

    lm_bt = await LMBluetooth.create(username, serial_number, token)

The token is the same token you need to initialize the local API, which you need to get from LM's cloud once. The serial number is your machine's serial number and the username is the email of your LaMarzocco account.

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lmcloud-0.4.4b3.tar.gz (18.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

lmcloud-0.4.4b3-py3-none-any.whl (18.6 kB view details)

Uploaded Python 3

File details

Details for the file lmcloud-0.4.4b3.tar.gz.

File metadata

  • Download URL: lmcloud-0.4.4b3.tar.gz
  • Upload date:
  • Size: 18.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.6

File hashes

Hashes for lmcloud-0.4.4b3.tar.gz
Algorithm Hash digest
SHA256 668677157a9f666d0acc840b1f39e35e3f229e6449ba81706f9743a9dfbcd29f
MD5 20cc1de2473f347929d88da6b5a3ece6
BLAKE2b-256 0b1a08c2eb157063b5d0d9e10d46ce43c80e564f52d1dc0fd79dbc4a40d074a1

See more details on using hashes here.

File details

Details for the file lmcloud-0.4.4b3-py3-none-any.whl.

File metadata

  • Download URL: lmcloud-0.4.4b3-py3-none-any.whl
  • Upload date:
  • Size: 18.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.6

File hashes

Hashes for lmcloud-0.4.4b3-py3-none-any.whl
Algorithm Hash digest
SHA256 6f58e6d3f65815dc133d3114f29a6af3684e19993dfe4abeb69bdd787171c04d
MD5 7bc0cb21975d69efa24094ad55e1a28f
BLAKE2b-256 b3e8401ca7cab401c5b37c70ea20d6e0afb60fb28aaec109a74fd12a6472f0ca

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page