I’d love to see what temp my beer is on a lovelace dashboard, anyone managed to integrate this yet?
+1 for this
Me too !
Yes please !
I was hoping to find something ready for the dispenser. My Perfect Draft arrives tomorrow. I’m curious to see if I can get it integrated somehow.
Was looking into these today as they are on black November deals now… is the pro only smart or is the original?
Only the Pro is smart and Iwould recomend it, It’s so much better from many perspectives -
Loading , temp control , smart app.
Unfortunatly we don’t have an integration as yet.
I was pleased to see others here in the community are also PD consumers
I have a PD Pro on order and am looking forward to trying to create an integration for it once it arrives. I made my PD Standard pretty smart with the help of an energy plug and some HA magic. The PD unit/machine lives inside a cupboard, and after little modification I was able to connect the keg adapter to a beer tap I fitted on top of the worktop. It looks fantastic and works amazingly well.
Leveraging a counter helper, which I reset with each keg change, I’m able to track how many pints are remaining by detecting the energy spikes from the smart plug when pulling a beer.
I also use the new Todo list (2023.11) to track the kegs, I have in stock. Using an automation that catches the event when a todo item is marked as completed, I set that item as the current keg which I use to show the medallions for that beer through a Mushroom card. This looks great on the Android Panels we have installed on the walls.
The last piece I’ve had fun working on is a 2" display, powered by a RP2040 to show the medallion of the current keg on the beer tap. I have a working solution but am exploring alternatives, as I’ve also acquired a 4" LCD. I need to work on a cone like enclosure/mount for it to live on top of the beer tap preferably out of stainless steel to blend in with it too.
Happy to share more for those interested to learning more in what I’ve done.
PS. If anyone is interested in picking up a PD machine, this PDRLNMBHUZT00
referral code will apply some discount for us both
That looks absolutely awesome James!
Yes would be intrested in seeing a PDP integration, if you need any help testing be happy to chip in.
I’ve been wanting to put a ESP32 module and display in my bar for some time now that shows what’s on tap, temp , expiry and UK pints available.
Unfortunately, there is no way to access the dispenser via the IPv4 address. I’m not an expert when it comes to Home Assistant, but I’m almost afraid that this makes integrating it complicated or impossible.
PD’s answer to the question of whether HA integration was planned:
Hi Michael,
so far there are no plans for this. But that will definitely change
Best regards
Lets hope and see
Thats amazing work, i just picked up an original one today which is second hand.
With the remaining left is that calculating whole pints only? Or is it able to calculate halves too? (I.e if pumping for a shorter time period than a whole pint takes)
Hi James, how did you do the counter-top tap? I played with this a couple of years ago, trying to do the same. Any more pics / info you can provide would be great please!
I need to order another smart plug as ones failed… what one are you using on your machine? The one thats faulty is a zigbee one from innr.
Contemplating getting another 2 that also do energy monitoring so i can use one on the PD machine?
Decided to go with localbytes and get a wifi one. Could you help share some of your code with me?
I have been monitoring power consumption for a few days now, the consumption only really kicks in and out when the machine is cooling (you can see it spike) This doesnt help for determining when a pint or half is pulled?
Hi all,
I have started to reverse engineer the Perfect Draft API. It is pretty straightforward. The API URL is https://api.perfectdraft.com/
Step 1 - The app makes a bunch of calls to google’s enterprise recaptcha API, eventually generating a unique key
Step 2 - The app makes a HTTPS GET to /lager-top/status to check the API is healthy and available
Step 3 - The app makes a HTTPS POST to /authentication/sign-in with a JSON Payload:
{
“email”: “your registered email”,
“password”: “your registered password”,
“recaptchaAction”: “Android_recaptchaThatWorks/login”,
“recaptchaToken”: “token code generated by the android recaptcha library”
}
It also has an x-api-key header which I am not going to publish here. If auth is successful the API responds with a JSON payload with 3 key value pairs:
{
“AccessToken”: “”,
“IdToken”: “”,
“RefreshToken”: “”
}
Step 4 - the app makes an HTTPS GET to /api/me with x-access-token header set to the AccessToken field from above. This returns a JSON payload with loads of info in it, including your user id, account details, a JSON collection of the machines you have registered, the temperature, pressure, eco mode settings, and so on.
Once authenticated you can also request /api/perfectdraft_machines/ for more detailed info about the PD machine - firmware version, whether the door is open, duration of last pour, pours since startup, serial number, etc etc etc. Again this requires the AccessToken header to be passed to the API. The machine ID is in the original JSON payload at /api/me and seems to be a 6 digit number.
Despite it having a bunch of cookies set and additional headers, it does seem like the API just works with the x-access-token header and the User-Agent set to PerfectDraftApp.
Hopefully that is some useful info for someone to kick off writing an integration. HTTPS interception I can do - coding I cannot
JSON doc is here https://api.perfectdraft.com/api/docs.jsonld
AI to the rescue I’ll help you create a Python library to interact with the Perfect Draft API based on the steps and information provided. This library will include functionality for generating the reCAPTCHA token, authenticating the user, and retrieving user and machine information. Note that we won’t implement the actual reCAPTCHA generation, as it requires specific interactions with Google’s services, but I’ll structure the code to integrate with it.
Here’s a basic outline of the library:
- Check API Status
- Authenticate User
- Retrieve User Information
- Retrieve Machine Information
We’ll create a class PerfectDraftAPI
to encapsulate these methods. Here is the initial implementation:
import requests
class PerfectDraftAPI:
def __init__(self, email, password, x_api_key):
self.base_url = "https://api.perfectdraft.com"
self.email = email
self.password = password
self.x_api_key = x_api_key
self.access_token = None
self.id_token = None
self.refresh_token = None
def check_status(self):
url = f"{self.base_url}/lager-top/status"
response = requests.get(url)
if response.status_code == 200:
print("API is healthy and available")
else:
print("API status check failed")
def authenticate(self, recaptcha_token):
url = f"{self.base_url}/authentication/sign-in"
headers = {
"x-api-key": self.x_api_key
}
payload = {
"email": self.email,
"password": self.password,
"recaptchaAction": "Android_recaptchaThatWorks/login",
"recaptchaToken": recaptcha_token
}
response = requests.post(url, json=payload, headers=headers)
if response.status_code == 200:
data = response.json()
self.access_token = data.get("AccessToken")
self.id_token = data.get("IdToken")
self.refresh_token = data.get("RefreshToken")
print("Authentication successful")
else:
print("Authentication failed")
def get_user_info(self):
url = f"{self.base_url}/api/me"
headers = {
"x-access-token": self.access_token
}
response = requests.get(url, headers=headers)
if response.status_code == 200:
return response.json()
else:
print("Failed to retrieve user information")
return None
def get_machine_info(self, machine_id):
url = f"{self.base_url}/api/perfectdraft_machines/{machine_id}"
headers = {
"x-access-token": self.access_token
}
response = requests.get(url, headers=headers)
if response.status_code == 200:
return response.json()
else:
print("Failed to retrieve machine information")
return None
Usage
To use the library, you would do something like this:
# Initialize the API client
email = "your_registered_email"
password = "your_registered_password"
x_api_key = "your_x_api_key"
recaptcha_token = "your_recaptcha_token"
pd_api = PerfectDraftAPI(email, password, x_api_key)
# Check API status
pd_api.check_status()
# Authenticate
pd_api.authenticate(recaptcha_token)
# Get user information
user_info = pd_api.get_user_info()
print(user_info)
# Get machine information (replace with actual machine ID)
machine_id = user_info['machines'][0]['id'] # assuming the user has at least one machine
machine_info = pd_api.get_machine_info(machine_id)
print(machine_info)
Notes
- reCAPTCHA Token Generation: You’ll need to integrate with the reCAPTCHA API to generate a valid
recaptchaToken
. This requires specific interactions with Google’s reCAPTCHA services, which is not covered here. - API Key: The
x_api_key
is required for authentication and needs to be kept secure. - Error Handling: The provided code includes basic error handling. You may want to enhance this by raising exceptions or handling different HTTP response codes more gracefully.
- Security: Ensure that sensitive information such as passwords and API keys are handled securely.
This should provide a solid foundation for interacting with the Perfect Draft API using Python.