A daemon to fetch data from HTTP and publish to MQTT
Project description
hyponcloud2mqtt
A bridge to connect the Hypon Cloud API to an MQTT broker. This application periodically fetches data from your Hypon system and publishes it to your MQTT broker, allowing for easy integration with home automation systems like Home Assistant.
[!NOTE] This project was developed and tested using data from an HMS800-C inverter. If you are using a different Hypon inverter model and find that some data points are missing or incorrectly mapped, please open an issue on the GitHub repository.
Features
- Fetches the latest data from the Hypon Cloud API.
- Publishes data to a configurable MQTT topic.
- Publishes service status (online/offline) using MQTT Last Will and Testament (LWT).
- Automatically handles API token acquisition and renewal.
- Configuration via a simple config.yaml file.
- Support for environment variables for Dockerized deployments.
- Can be run directly with Python or as a Docker container.
- Installable via PyPI.
Prerequisites
- Python 3.11 or later
- A Hypon Cloud account
- An MQTT broker
- Docker (optional, for containerized deployment)
Quick Start
Docker (Recommended)
docker run -d \
--name hyponcloud2mqtt \
--restart unless-stopped \
-e HTTP_URL="http://192.168.1.100" \
-e SYSTEM_IDS="12345,67890" \
-e API_USERNAME="your_username" \
-e API_PASSWORD="your_password" \
-e MQTT_BROKER="192.168.1.10" \
-e MQTT_TOPIC="solar/inverter" \
fligneul/hyponcloud2mqtt:latest
Docker Compose
# Copy example and customize
cp docker-compose.yml.example docker-compose.yml
# Edit docker-compose.yml with your settings
docker-compose up -d
Python (PyPI)
pip install hyponcloud2mqtt
# Create config file
cp config.yaml.example config.yaml
# Edit config.yaml with your settings
# Run
hyponcloud2mqtt
Configuration
Configuration can be provided via environment variables or a YAML config file. Environment variables take precedence over config file values.
Environment Variables
[!NOTE] Variables marked as Config* are required only if they are not provided in the
config.yamlfile. If no configuration file is used, these environment variables must be set.
| Variable | Required | Default | Description |
|---|---|---|---|
HTTP_URL |
Config* | - | Base URL of the API (e.g., http://192.168.1.100) |
SYSTEM_IDS |
Config* | - | Comma-separated list of system IDs to monitor |
API_USERNAME |
Config* | - | API username for authentication |
API_PASSWORD |
Config* | - | API password for authentication |
HTTP_INTERVAL |
No | 60 |
Fetch interval in seconds |
MQTT_BROKER |
No | localhost |
MQTT broker address |
MQTT_PORT |
No | 1883 |
MQTT broker port |
MQTT_TOPIC |
No | home/data |
MQTT topic to publish to |
MQTT_USERNAME |
No | - | MQTT username (optional) |
MQTT_PASSWORD |
No | - | MQTT password (optional) |
MQTT_CLIENT_ID |
No | hyponcloud2mqtt |
MQTT client ID (optional) |
MQTT_AVAILABILITY_TOPIC |
No | {MQTT_TOPIC}/status |
MQTT availability topic |
HA_DISCOVERY_ENABLED |
No | true |
Enable Home Assistant discovery |
HA_DISCOVERY_PREFIX |
No | homeassistant |
Home Assistant discovery prefix |
DEVICE_NAME |
No | hyponcloud2mqtt |
Device name for Home Assistant |
VERIFY_SSL |
No | true |
Verify SSL certificates (set to false for self-signed certs) |
DRY_RUN |
No | false |
If true, log MQTT messages instead of publishing |
CONFIG_FILE |
No | config.yaml |
Path to config file |
LOG_LEVEL |
No | INFO |
Logging level (DEBUG, INFO, WARNING, ERROR) |
MQTT_TLS_ENABLED |
No | false |
Enable MQTT TLS |
MQTT_TLS_INSECURE |
No | false |
Disable TLS certificate verification |
MQTT_CA_PATH |
No | - | Path to custom CA certificate for MQTT |
Configuration File
See config.yaml.example for a complete example with Home Assistant sensor definitions.
http_url: "http://192.168.1.100"
api_username: "your_username"
api_password: "your_password"
http_interval: 60
mqtt_broker: "localhost"
mqtt_port: 1883
mqtt_topic: "solar/inverter"
ha_discovery_prefix: "homeassistant"
device_name: "Solar Inverter"
Secrets Management
Option 1: Environment File (Recommended for Docker Compose)
Use a .env file that is not committed to version control:
Step 1: Create .env file
# Create .env file with your secrets
cat > .env << 'EOF'
HTTP_URL=http://192.168.1.100
API_USERNAME=your_username
API_PASSWORD=your_password
MQTT_BROKER=192.168.1.10
MQTT_USERNAME=mqtt_user
MQTT_PASSWORD=mqtt_pass
EOF
# Secure the file (Linux/Mac)
chmod 600 .env
# Add to .gitignore
echo ".env" >> .gitignore
Step 2: Update docker-compose.yml
services:
hyponcloud2mqtt:
image: fligneul/hyponcloud2mqtt:latest
env_file:
- .env # Loads all variables from .env file
restart: unless-stopped
Step 3: Deploy
docker-compose up -d
Pros: Simple, works with Docker Compose, secrets not in compose file Cons: Secrets visible in container environment
Option 2: Mounted Configuration File (More Secure)
Mount a configuration file as read-only volume:
Step 1: Create secrets directory
# Create directory for secrets
mkdir -p secrets
chmod 700 secrets
# Create config file
cat > secrets/config.yaml << 'EOF'
http_url: "http://192.168.1.100"
api_username: "your_username"
api_password: "your_password"
mqtt_broker: "192.168.1.10"
mqtt_username: "mqtt_user"
mqtt_password: "mqtt_pass"
EOF
# Secure the file
chmod 600 secrets/config.yaml
# Add to .gitignore
echo "secrets/" >> .gitignore
Step 2: Update docker-compose.yml
services:
hyponcloud2mqtt:
image: fligneul/hyponcloud2mqtt:latest
volumes:
- ./secrets/config.yaml:/app/config.yaml:ro # Read-only mount
environment:
CONFIG_FILE: /app/config.yaml
restart: unless-stopped
Step 3: Deploy
docker-compose up -d
Pros: Secrets not in environment variables, file permissions control access Cons: Secrets still plaintext on disk (use disk encryption for additional security)
Security Best Practices
-
Never commit secrets to git
# Add to .gitignore .env secrets/ config.yaml *.secret -
Use restrictive file permissions
chmod 600 .env secrets/config.yaml # Owner read/write only chmod 700 secrets/ # Owner access only
-
Rotate credentials regularly
- Change API passwords periodically
- Update MQTT credentials
- Restart container after rotation
-
Use separate credentials per environment
- Different secrets for dev/staging/production
- Never reuse production credentials
Home Assistant Integration
The daemon automatically publishes MQTT Discovery messages for configured sensors. Home Assistant will auto-detect and create entities.
Published MQTT Data
| Field | Description | Unit | Decimal Precision |
|---|---|---|---|
percent |
Capacity Factor | % | 2 |
w_cha |
Charging Power | W | 0 |
power_pv |
PV Power | W | 0 |
today_generation |
Today Energy | kWh | 2 |
month_generation |
Month Energy | kWh | 2 |
year_generation |
Year Energy | kWh | 2 |
total_generation |
Total Energy | kWh | 2 |
co2 |
CO2 Saved | kg | 2 |
tree |
Trees Planted | - | 2 |
diesel |
Diesel Saved | L | 2 |
today_revenue |
Today Revenue | - | 2 |
month_revenue |
Month Revenue | - | 2 |
total_revenue |
Total Revenue | - | 2 |
gateway_online |
Gateway Online | - | 0 |
gateway_offline |
Gateway Offline | - | 0 |
inverter_online |
Inverter Online | - | 0 |
inverter_normal |
Inverter Normal | - | 0 |
inverter_offline |
Inverter Offline | - | 0 |
inverter_fault |
Inverter Fault | - | 0 |
inverter_wait |
Inverter Wait | - | 0 |
Example Payload
Example payload for HMS800-C inverter:
{
"percent": 5.39,
"meter_power": 0,
"power_load": 41,
"w_cha": 0,
"power_pv": 41,
"today_generation": 0.02,
"month_generation": 0.09,
"year_generation": 94.42,
"total_generation": 94.42,
"co2": 2.83,
"tree": 0.16,
"diesel": 10.49,
"today_revenue": 0,
"month_revenue": 0.02,
"total_revenue": 16.16,
"gateway_online": 1,
"gateway_offline": 0,
"inverter_online": 1,
"inverter_normal": 1,
"inverter_offline": 0,
"inverter_fault": 0,
"inverter_wait": 0
}
Development
Setup
[!NOTE] This project requires Python 3.11 or higher.
# Clone repository
git clone https://github.com/fligneul/hyponcloud2mqtt.git
cd hyponcloud2mqtt
# Create and activate virtual environment
python3 -m venv .venv
source .venv/bin/activate
# Upgrade pip (required for editable installs with pyproject.toml)
pip install --upgrade pip
# Install with dev dependencies
pip install -e ".[dev]"
# Run tests
pytest
Running Tests
# Run unit tests
pytest
# Run tests with coverage
pytest --cov=hyponcloud2mqtt
Integration Tests
The integration tests verify the daemon's behavior with a real MQTT broker and a mocked API (WireMock).
Automated (Cross-Platform)
The easiest way to run integration tests is using the provided Python script:
# Mac / Linux
python3 scripts/run_integration_tests.py
# Windows
python scripts\run_integration_tests.py
This script will automatically start the required Docker containers, set the environment variables, and run the tests.
Manual
If you prefer to run the steps manually:
-
Start dependencies:
docker compose -f docker-compose.dev.yml up mosquitto wiremock -d
-
Run the test with environment variables:
Mac / Linux:
export HTTP_URL=http://localhost:8080 export SYSTEM_IDS=your_system_id_1 export API_USERNAME=test_user export API_PASSWORD=test_password export MQTT_BROKER=localhost .venv/bin/python -m pytest tests/test_wiremock_integration.py
Windows (PowerShell):
$env:HTTP_URL="http://localhost:8080" $env:SYSTEM_IDS="your_system_id_1" $env:API_USERNAME="test_user" $env:API_PASSWORD="test_password" $env:MQTT_BROKER="localhost" .\.venv\Scripts\python -m pytest tests/test_wiremock_integration.py
Local Development with WireMock
You can run the application locally without external dependencies using WireMock to simulate the API and a local MQTT broker.
Using Docker Compose (Recommended):
# Starts the application, WireMock, and Mosquitto
docker-compose -f docker-compose.dev.yml up
The environment will be pre-configured with:
- WireMock on port 8080 (simulating the API)
- Mosquitto on port 1883 (MQTT broker)
- Application configured to talk to both
Troubleshooting
Authentication Failures
If you see code: 50008 errors:
- Verify
API_USERNAMEandAPI_PASSWORDare correct - Check API logs for authentication issues
- The daemon will automatically retry login
MQTT Connection Issues
- Verify
MQTT_BROKERis reachable - Check
MQTT_USERNAMEandMQTT_PASSWORDif required - Ensure MQTT broker allows connections from daemon's IP
No Data in Home Assistant
- Check MQTT topic in Home Assistant MQTT integration
- Verify
HA_DISCOVERY_ENABLEDis not set tofalse(default:true) - Verify
HA_DISCOVERY_PREFIXmatches Home Assistant config (default:homeassistant) - Check Home Assistant logs for discovery messages
SSL Certificate Errors
If you see SSL certificate verification errors:
- For production: Ensure your API server has a valid SSL certificate
- For self-signed certificates: Set
VERIFY_SSL=falsein environment orverify_ssl: falsein config.yaml - Security note: Only disable SSL verification if you trust the network and understand the security implications
Docker Health Check Failing
The daemon includes a basic health check. If failing:
- Check container logs:
docker logs hyponcloud2mqtt - Verify API is reachable from container
- Ensure MQTT broker is accessible
License
This project is licensed under the GNU Affero General Public License v3.0 - see the LICENSE file for details.
Contributing
Contributions are welcome! Please see CONTRIBUTING.md for:
- Development setup
- Conventional commit guidelines
- Pull request process
- Code style guidelines
Support
- Issues: GitHub Issues
- Discussions: GitHub Discussions
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file hyponcloud2mqtt-1.0.0.tar.gz.
File metadata
- Download URL: hyponcloud2mqtt-1.0.0.tar.gz
- Upload date:
- Size: 51.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ff8440b40c9a819bb3dd7bb21f3512971afcbc0d08319e6edf741e0a5b7d323e
|
|
| MD5 |
8097c81081262c82f217dae0d912528a
|
|
| BLAKE2b-256 |
fa37b764f131ee2ac25ea928eb3b0099ed16fa86e13011d484ec6030003a57cf
|
Provenance
The following attestation bundles were made for hyponcloud2mqtt-1.0.0.tar.gz:
Publisher:
publish.yml on fligneul/hyponcloud2mqtt
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
hyponcloud2mqtt-1.0.0.tar.gz -
Subject digest:
ff8440b40c9a819bb3dd7bb21f3512971afcbc0d08319e6edf741e0a5b7d323e - Sigstore transparency entry: 779617355
- Sigstore integration time:
-
Permalink:
fligneul/hyponcloud2mqtt@f9df49ee1921c3dc5558953a1e165e79892ef29b -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/fligneul
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@f9df49ee1921c3dc5558953a1e165e79892ef29b -
Trigger Event:
release
-
Statement type:
File details
Details for the file hyponcloud2mqtt-1.0.0-py3-none-any.whl.
File metadata
- Download URL: hyponcloud2mqtt-1.0.0-py3-none-any.whl
- Upload date:
- Size: 32.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9e7b911d1b9da70e59349e7e05ef5dbfa94e3ab6505e3788e10290ac458a7f4e
|
|
| MD5 |
c7b71ce0157ef31e75bac53f48171316
|
|
| BLAKE2b-256 |
f1d2e5c9682ce5b244b071d2dc9a99a9c37b6ee53fc68395b1456bd4c7c77205
|
Provenance
The following attestation bundles were made for hyponcloud2mqtt-1.0.0-py3-none-any.whl:
Publisher:
publish.yml on fligneul/hyponcloud2mqtt
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
hyponcloud2mqtt-1.0.0-py3-none-any.whl -
Subject digest:
9e7b911d1b9da70e59349e7e05ef5dbfa94e3ab6505e3788e10290ac458a7f4e - Sigstore transparency entry: 779617357
- Sigstore integration time:
-
Permalink:
fligneul/hyponcloud2mqtt@f9df49ee1921c3dc5558953a1e165e79892ef29b -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/fligneul
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@f9df49ee1921c3dc5558953a1e165e79892ef29b -
Trigger Event:
release
-
Statement type: