For self-hosted bloggers and developers, keeping an eye on website uptime and audience engagement is crucial. However, checking web dashboards constantly is distracting, and polling local databases for traffic metrics can slow down your site’s performance.
If you use WordPress connected to Jetpack (by Automattic), you can leverage the WordPress.com cloud REST API to pull your daily statistics (pageviews, unique visitors, comment counts) and site uptime directly into your local Home Assistant server and command-line developer tools.
Here is a step-by-step guide to configuring the API, writing a lightweight Python monitoring script, and exposing your site stats to Home Assistant and developer AI assistants like Antigravity (agy).
1. How It Works: The Architecture
Jetpack offloads your self-hosted site’s analytics and downtime monitoring to the WordPress.com cloud infrastructure. This allows you to retrieve telemetry without putting any load on your web server.

Using a long-lived access token, you can query the statistics summary endpoint from your terminal or Home Assistant configuration files.
2. Authentication: Generating the API Token
WordPress.com requires OAuth2 authentication. Since this is for personal monitoring, you can generate a permanent access token using a developer application:
- Go to the WordPress.com Applications Portal.
- Create a new application named
Home Assistant Bridgewith the redirect URL set tohttp://localhost. - Note your Client ID and Client Secret.
- Authorize the application by loading the following URL in your browser (replacing
YOUR_CLIENT_ID):
https://public-api.wordpress.com/oauth2/authorize?client_id=YOUR_CLIENT_ID&redirect_uri=http://localhost&response_type=code
- Click Approve. You will be redirected to
http://localhost/?code=YOUR_AUTHORIZATION_CODE. Copy this code immediately. - Swap the code for your token by running a quick Python script or curl command:
curl -d "client_id=YOUR_CLIENT_ID&client_secret=YOUR_CLIENT_SECRET&grant_type=authorization_code&redirect_uri=http://localhost&code=YOUR_AUTHORIZATION_CODE" https://public-api.wordpress.com/oauth2/token
7. Save the resulting access_token to /home/gvoina/scripts/wp_token.txt.
3. The Python CLI Script (wp_stats.py)
To make these stats accessible to terminal workflows, we write a Python script that polls WordPress.com and outputs site status to standard output:
#!/usr/bin/env python3
import os
import sys
import requests
TOKEN_PATH = "/home/gvoina/scripts/wp_token.txt"
SITE_PATH = "/home/gvoina/scripts/wp_site.txt"
def get_config():
token = os.getenv("WP_JETPACK_TOKEN")
site = os.getenv("WP_SITE_DOMAIN")
if not token and os.path.exists(TOKEN_PATH):
with open(TOKEN_PATH, "r", encoding="utf-8") as f:
token = f.read().strip()
if not site and os.path.exists(SITE_PATH):
with open(SITE_PATH, "r", encoding="utf-8") as f:
site = f.read().strip()
return token, site
def check_uptime(site):
url = site if site.startswith("http") else f"https://{site}"
try:
res = requests.head(url, timeout=10)
if res.status_code == 200:
print(f"🌐 Website status: ONLINE (HTTP {res.status_code})")
else:
print(f"⚠️ Website status: UNSTABLE (HTTP {res.status_code})")
except Exception as e:
print(f"❌ Website status: DOWN ({e})")
def get_stats(token, site):
api_site = site.split("://")[-1] if "://" in site else site
url = f"https://public-api.wordpress.com/rest/v1.1/sites/{api_site}/stats/summary"
headers = {"Authorization": f"Bearer {token}"}
try:
res = requests.get(url, headers=headers, timeout=10)
res.raise_for_status()
data = res.json()
print(f"📈 Jetpack Statistics for {api_site}:")
print(f" • Daily Pageviews: {data.get('views', 0)}")
print(f" • Daily Unique Visitors: {data.get('visitors', 0)}")
print(f" • Comments Today: {data.get('comments', 0)}")
except Exception as e:
print(f"❌ Failed to fetch Jetpack stats: {e}")
if __name__ == "__main__":
token, site = get_config()
if not token or not site:
print("Error: Configuration missing.")
sys.exit(1)
check_uptime(site)
print()
get_stats(token, site)
Running it displays:
🌐 Website status: ONLINE (HTTP 200)
📈 Jetpack Statistics for blog.voina.org:
• Daily Pageviews: 10
• Daily Unique Visitors: 5
• Comments Today: 0
4. Integrating with Home Assistant Dashboards
To make these metrics visible on your smart home dashboard, you can define native REST sensors and a command-line connectivity checker in your Home Assistant configuration.yaml file:
# configuration.yaml entries
sensor:
- platform: rest
name: "Blog Daily Pageviews"
resource: "https://public-api.wordpress.com/rest/v1.1/sites/blog.voina.org/stats/summary"
headers:
Authorization: "Bearer !secret wp_jetpack_token"
value_template: "{{ value_json.views if value_json is defined and value_json is not none and 'views' in value_json else 0 }}"
unit_of_measurement: "views"
scan_interval: 3600
- platform: rest
name: "Blog Daily Visitors"
resource: "https://public-api.wordpress.com/rest/v1.1/sites/blog.voina.org/stats/summary"
headers:
Authorization: "Bearer !secret wp_jetpack_token"
value_template: "{{ value_json.visitors if value_json is defined and value_json is not none and 'visitors' in value_json else 0 }}"
unit_of_measurement: "visitors"
scan_interval: 3600
- platform: rest
name: "Blog Daily Comments"
resource: "https://public-api.wordpress.com/rest/v1.1/sites/blog.voina.org/stats/summary"
headers:
Authorization: "Bearer !secret wp_jetpack_token"
value_template: "{{ value_json.comments if value_json is defined and value_json is not none and 'comments' in value_json else 0 }}"
unit_of_measurement: "comments"
scan_interval: 3600
command_line:
- binary_sensor:
name: "Blog Uptime Status"
command: "curl -I https://blog.voina.org 2>/dev/null | head -n 1 | grep -q '200 OK' && echo 'ON' || echo 'OFF'"
device_class: connectivity
scan_interval: 300
5. Bridging with Developer AI Assistants (agy)
By saving these CLI scripts directly in your project workspace or system directory, you enable developer AI assistants like Antigravity (agy) to monitor the health of your digital presence.
When you ask the agent: “Is my blog running fine and did we get any traction today?”, the agent runs python3 /home/gvoina/scripts/wp_stats.py behind the scenes. It receives the HTTP status check and traffic statistics, parses the output, and prints a helpful summary right in your development chat window. This bridges your code editor workflows with the real-world operational health of your blog.
6. Conclusion
By integrating WordPress Jetpack with Home Assistant, you centralize your digital footprints. Whether you want to view visitor trends on your living room wall tablet, get offline alert notifications on your Meshtastic LoRa node, or let an AI assistant diagnose website connectivity issues directly from your terminal, this lightweight REST-based bridge makes it possible.