A Linux application that connects to Trydan EV chargers using the python3-pytrydan package and exposes data to an MQTT broker for integration with home automation systems.
- Real-time Data Monitoring: Continuously monitors Trydan EV charger status, power consumption, energy delivered, and more
- MQTT Integration: Publishes data to MQTT broker with configurable topics
- Remote Control: Accept commands via MQTT to control charging (start/stop, set current, change mode)
- Generic MQTT Topics: Uses standard topic structure compatible with any MQTT-based system
- Robust Error Handling: Automatic reconnection and error recovery
- Systemd Service: Runs as a Linux daemon with automatic startup
- Configurable: Extensive configuration options via YAML files
- Secure: Support for MQTT TLS/SSL authentication
- Linux system (Ubuntu, Debian, CentOS, RHEL, Fedora, Arch Linux)
- Python 3.7 or higher
- Trydan EV charger accessible via network
- MQTT broker (Mosquitto or cloud service)
-
Clone or download the repository:
git clone https://github.com/your-username/trydan2mqtt.git cd trydan2mqtt -
Run the installation script:
sudo ./scripts/install.sh
-
Configure the application:
sudo nano /etc/trydan2mqtt/config.yaml
-
Start the service:
sudo systemctl start trydan2mqtt sudo systemctl status trydan2mqtt
Ubuntu/Debian:
sudo apt-get update
sudo apt-get install python3 python3-pip python3-venv python3-systemdCentOS/RHEL/Fedora:
sudo dnf install python3 python3-pip python3-systemd
# or for older systems:
sudo yum install python3 python3-pip python3-systemdArch Linux:
sudo pacman -S python python-pip python-systemdInstall the Python packages:
pip3 install -r requirements.txtIf python3-pytrydan is available as a system package (recommended):
# Ubuntu/Debian
sudo apt-get install python3-pytrydan
# Or install via pip
pip3 install pytrydan-
Create application user:
sudo useradd --system --home-dir /opt/trydan2mqtt --create-home --shell /bin/false trydan2mqtt
-
Install application files:
sudo cp -r src/ /opt/trydan2mqtt/ sudo mkdir -p /etc/trydan2mqtt sudo cp config/config.yaml /etc/trydan2mqtt/ sudo chown -R trydan2mqtt:trydan2mqtt /opt/trydan2mqtt /etc/trydan2mqtt
-
Install systemd service:
sudo cp systemd/trydan2mqtt.service /etc/systemd/system/ sudo systemctl daemon-reload sudo systemctl enable trydan2mqtt
Edit the configuration file at /etc/trydan2mqtt/config.yaml:
# Trydan EV Charger Configuration
trydan:
host: "192.168.1.100" # Your Trydan IP address
device_id: "74D9TI" # Unique device identifier for MQTT topics
# MQTT Broker Configuration
mqtt:
host: "192.168.1.50" # Your MQTT broker IP
port: 1883 # MQTT port (1883 standard, 8883 SSL)
client_id: "trydan"
topic_prefix: "trydan2mqtt"
username: "mqtt_user" # Optional
password: "mqtt_pass" # Optional
# Bridge Configuration
bridge:
poll_interval: 30 # Data collection interval in seconds# Start the service
sudo systemctl start trydan2mqtt
# Check status
sudo systemctl status trydan2mqtt
# View logs
sudo journalctl -u trydan2mqtt -f
# Stop the service
sudo systemctl stop trydan2mqttFor testing or debugging:
# Run with default config
python3 /opt/trydan2mqtt/src/trydan2mqtt.py
# Run with custom config
python3 /opt/trydan2mqtt/src/trydan2mqtt.py /path/to/custom/config.yamlThe application publishes data to the following MQTT topics:
trydan2mqtt/{device_id}/sensor/status- Charging status (charge_state)trydan2mqtt/{device_id}/sensor/charging_current- Current charging current in Amperes (intensity)trydan2mqtt/{device_id}/sensor/charging_power- Current charging power in Watts (charge_power)trydan2mqtt/{device_id}/sensor/energy_delivered- Total energy delivered in kWh (charge_energy)trydan2mqtt/{device_id}/sensor/charge_time- Current charging session timetrydan2mqtt/{device_id}/sensor/voltage- Installation voltage (voltage_installation)trydan2mqtt/{device_id}/sensor/house_power- House power consumptiontrydan2mqtt/{device_id}/sensor/battery_power- Battery power (if applicable)trydan2mqtt/{device_id}/sensor/fv_power- PV/Solar power generationtrydan2mqtt/{device_id}/sensor/max_intensity- Maximum allowed charging currenttrydan2mqtt/{device_id}/sensor/min_intensity- Minimum allowed charging currenttrydan2mqtt/{device_id}/sensor/ready_state- Device ready statetrydan2mqtt/{device_id}/sensor/locked- Charger lock status (true/false)trydan2mqtt/{device_id}/sensor/paused- Charging pause status (true/false)trydan2mqtt/{device_id}/sensor/dynamic- Dynamic charging mode statustrydan2mqtt/{device_id}/sensor/contracted_power- Contracted power limittrydan2mqtt/{device_id}/sensor/firmware_version- Device firmware versiontrydan2mqtt/{device_id}/sensor/device_id- Unique device identifiertrydan2mqtt/{device_id}/sensor/ip_address- Device IP addresstrydan2mqtt/{device_id}/sensor/signal_status- Communication signal statustrydan2mqtt/{device_id}/data- Complete data as JSON with timestamptrydan2mqtt/{device_id}/availability- Device availability (online/offline)
Send commands to control the charger using JSON payloads (replace {device_id} with your configured device ID):
trydan2mqtt/{device_id}/set- Send control commands with JSON payload
Available JSON commands:
{"charge_current": 16}- Set charging current (amperage value){"paused": "true"}- Control pause state ("true"/"pause" to pause, "false"/"resume" to resume){"locked": "true"}- Control lock state ("true"/"lock" to lock, "false"/"unlock" to unlock)
Resume charging (replace 74D9TI with your device ID):
mosquitto_pub -h localhost -t "trydan2mqtt/74D9TI/set" -m '{"paused": "false"}'Set charging current to 16A:
mosquitto_pub -h localhost -t "trydan2mqtt/74D9TI/set" -m '{"charge_current": 16}'Pause charging:
mosquitto_pub -h localhost -t "trydan2mqtt/74D9TI/set" -m '{"paused": "true"}'Lock charger:
mosquitto_pub -h localhost -t "trydan2mqtt/74D9TI/set" -m '{"locked": "true"}'Unlock charger:
mosquitto_pub -h localhost -t "trydan2mqtt/74D9TI/set" -m '{"locked": "false"}'Lock charger:
mosquitto_pub -h localhost -t "trydan/command/lock" -m ""-
Cannot connect to Trydan device:
- Check IP address in configuration
- Verify network connectivity:
ping <trydan_ip> - Ensure Modbus TCP is enabled on Trydan
- Check firewall settings
-
Cannot connect to MQTT broker:
- Verify MQTT broker is running
- Check credentials and connection settings
- Test with mosquitto client tools
-
Service won't start:
- Check logs:
sudo journalctl -u trydan2mqtt -f - Verify configuration file syntax
- Check file permissions
- Check logs:
-
No data being published:
- Check Trydan connection status in logs
- Verify MQTT topic configuration
- Test with MQTT client:
mosquitto_sub -h <broker> -t "trydan2mqtt/#"
View application logs:
# Service logs
sudo journalctl -u trydan2mqtt -f
# Application log file
sudo tail -f /var/log/trydan2mqtt.logTest Trydan connection:
# Python test script
python3 -c "
import asyncio
from pytrydan import Trydan
async def test():
trydan = Trydan('192.168.1.100')
await trydan.connect()
status = await trydan.get_status()
print(f'Status: {status}')
await trydan.disconnect()
asyncio.run(test())
"Test MQTT connection:
# Subscribe to all topics
mosquitto_sub -h <mqtt_broker> -t "trydan2mqtt/#"
# Publish test message
mosquitto_pub -h <mqtt_broker> -t "test/topic" -m "Hello MQTT"- Network Security: Ensure Trydan device is on a secure network
- MQTT Security: Use TLS/SSL for MQTT connections when possible
- Authentication: Configure MQTT username/password authentication
- Firewall: Restrict access to necessary ports only
- Updates: Keep the application and dependencies updated
Update configuration for secure MQTT:
mqtt:
host: "your-mqtt-broker.com"
port: 8883
tls:
enabled: true
ca_certs: "/etc/ssl/certs/ca-certificates.crt"trydan2mqtt/
├── src/
│ └── trydan2mqtt.py # Main application
├── config/
│ └── config.yaml # Default configuration
├── systemd/
│ └── trydan2mqtt.service # Systemd service file
├── scripts/
│ └── install.sh # Installation script
├── requirements.txt # Python dependencies
└── README.md # This file
- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly
- Submit a pull request
Run basic tests:
# Install development dependencies
pip3 install pytest pytest-asyncio
# Run tests (if available)
pytest tests/To remove the application:
sudo ./scripts/install.sh uninstallOr manually:
sudo systemctl stop trydan2mqtt
sudo systemctl disable trydan2mqtt
sudo rm /etc/systemd/system/trydan2mqtt.service
sudo rm -rf /opt/trydan2mqtt
sudo rm -rf /etc/trydan2mqtt
sudo userdel trydan2mqtt
sudo systemctl daemon-reloadThis project is licensed under the MIT License - see the LICENSE file for details.
- GitHub Issues: Report bugs and request features
- Documentation: Check this README and configuration files
- Community: Join discussions in the repository