{"id":44355057,"url":"https://github.com/tomquist/marsrelay","last_synced_at":"2026-02-11T16:04:51.051Z","repository":{"id":334362211,"uuid":"1138602691","full_name":"tomquist/marsrelay","owner":"tomquist","description":null,"archived":false,"fork":false,"pushed_at":"2026-01-31T14:38:21.000Z","size":111,"stargazers_count":1,"open_issues_count":2,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-02-01T01:57:11.264Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tomquist.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-01-20T22:10:07.000Z","updated_at":"2026-01-25T09:49:05.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/tomquist/marsrelay","commit_stats":null,"previous_names":["tomquist/marsrelay"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/tomquist/marsrelay","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomquist%2Fmarsrelay","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomquist%2Fmarsrelay/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomquist%2Fmarsrelay/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomquist%2Fmarsrelay/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tomquist","download_url":"https://codeload.github.com/tomquist/marsrelay/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomquist%2Fmarsrelay/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29337022,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-11T16:00:30.228Z","status":"ssl_error","status_checked_at":"2026-02-11T16:00:25.398Z","response_time":97,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-02-11T16:04:50.414Z","updated_at":"2026-02-11T16:04:51.039Z","avatar_url":"https://github.com/tomquist.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Marsrelay\n\nMarsrelay is a simple device that lets you use your Marstek Energy Storage system completely offline while still integrating it with your home automation setup.\n\n## What is Marsrelay?\n\nMarsrelay replaces the Marstek cloud service with a small device that runs locally in your home. Instead of your Marstek battery system connecting to the internet, it connects to Marsrelay, which then connects to your home automation system.\n\n## Why Use Marsrelay?\n\n- **Works Offline**: Your Marstek system doesn't need internet access\n- **Privacy**: All data stays in your home network\n- **Home Automation Integration**: Connect your Marstek system to home automation projects like [hm2mqtt](https://github.com/tomquist/hm2mqtt)\n- **No Cloud Dependencies**: No need to rely on Marstek's cloud services\n- **No Device Hacking Required**: The best part? You don't need to modify or hack your Marstek Energy Storage device at all. The only thing you need to do is configure your device to connect to Marsrelay's WiFi access point instead of your regular WiFi network.\n\n## How It Works\n\nWhen you set up Marsrelay:\n\n1. **Creates a WiFi Network**: Marsrelay opens its own WiFi access point that your Marstek Energy Storage device connects to (just like connecting to WiFi)\n2. **Redirects Internet Requests**: When your Marstek device tries to reach the internet, Marsrelay intercepts those requests and redirects them to itself instead\n3. **Acts Like Marstek's Server**: Marsrelay includes a web server that responds to your Marstek device the same way Marstek's cloud service would, so your device thinks it's connected normally\n4. **Forwards Messages**: Marsrelay includes an MQTT broker (a messaging system) that:\n   - Receives messages from your Marstek device\n   - Forwards them to your home automation system's MQTT broker\n   - This allows projects like hm2mqtt to monitor and control your Marstek system\n\n## The Result\n\nYour Marstek Energy Storage system operates completely offline, thinking it's connected to Marstek's cloud, while all its data and controls are available to your home automation system through MQTT.\n\n---\n\n## Getting Started\n\n### Prerequisites\n\n- ESPHome installed (e.g., via the ESPHome addon in Home Assistant)\n- An MQTT broker running on your network\n- A tool like [MQTT Explorer](https://github.com/thomasnordquist/MQTT-Explorer) to monitor MQTT messages\n\n### Step 0: Get an ESP32-S3 Board\n\nYou'll need an ESP32-S3 development board. You can purchase one here:\n\n- Single board: [Amazon](https://amzn.to/429OJDX) with \"octal\" PSRAM\n- 3-pack (better value): [Amazon](https://amzn.to/3PwGRVv)\n- 3-pack mini: [Amazon](https://amzn.to/4qIjp8P) with \"quad\" PSRAM\n\n### Step 1: Configure ESPHome\n\nCopy the following ESPHome configuration and save it as `marsrelay_esp32s3.yaml`.\n\n```yaml\nsubstitutions:\n  device_name: marsrelay-esp32s3\n  friendly_name: Marsrelay ESP32S3\n  wifi_ssid: \"your-home-wifi-ssid\"\n  wifi_password: \"your-home-wifi-password\"\n  ap_ssid: \"marsrelay\"\n  ap_password: \"marsrelay\"\n  mqtt_broker: 192.168.1.100\n  mqtt_username: \"\"\n  mqtt_password: \"\"\n  mqtt_topic_prefix: \"marsrelay\"\n  # UDP proxy port for power meter discovery (see https://github.com/tomquist/b2500-meter)\n  # - Port 1010: Shelly Pro 3EM for B2500 firmware up to v224, Jupiter, Venus\n  # - Port 2220: Shelly Pro 3EM for B2500 firmware v226+\n  # - Port 2222: Shelly 3EM gen3\n  # - Port 2223: Shelly Pro EM50\n  # - Port 12345: CT001/CT002/CT003\n  udp_proxy_port: \"1010\"\n  psram:\n    # Set to true if your ESP32S3 has PSRAM.\n    enabled: true\n    # This needs to be set correctly! See https://esphome.io/components/psram/ for more information.\n    mode: quad\n\nesphome:\n  name: ${device_name}\n  friendly_name: ${friendly_name}\n\npsram:\n  mode: ${psram.mode}\n  disabled: ${false if psram.enabled else true}\n\nesp32:\n  board: esp32-s3-devkitc-1\n  variant: esp32s3\n  framework:\n    type: esp-idf\n    sdkconfig_options:\n      CONFIG_LWIP_IPV6: y\n      CONFIG_ESP_TLS_INSECURE: y  # Allow skipping certificate verification\n      CONFIG_ESP_TLS_SKIP_SERVER_CERT_VERIFY: y  # Skip server certificate verification\n      CONFIG_LWIP_MAX_SOCKETS: \"58\"  # Reduced from 64 to ensure LWIP_SOCKET_OFFSET \u003e= 6 (FD_SETSIZE=64, so offset = 64-58=6)\n      CONFIG_LWIP_TCP_MSL: \"30\"  # Reduce TIME_WAIT timeout from default 60s to 30s (in seconds)\n      CONFIG_LWIP_SOCKET_OFFSET: \"6\"  # Required for esp_vfs_console compatibility (must be \u003e= 6 for esp_vfs_console)\n\nexternal_components:\n  - source:\n      type: git\n      url: https://github.com/tomquist/marsrelay\n      ref: main\n\nlogger:\n\nwifi:\n  ssid: ${wifi_ssid}\n  password: ${wifi_password}\n  ap:\n    ssid: ${ap_ssid}\n    password: ${ap_password}\n  use_psram: ${psram.enabled}\n\ncapture_dns:\n  id: capture_dns_server\n\n# UDP proxy bridges broadcasts between AP and STA networks for power meter discovery\n# Add multiple entries if you need to support different firmware versions\nudp_proxy:\n  - port: ${udp_proxy_port}\n\nmqtt:\n  id: mqtt_client\n  broker: ${mqtt_broker}\n  username: ${mqtt_username}\n  password: ${mqtt_password}\n  on_connect:\n    - lambda: |-\n        id(mqtt_client).subscribe(\"marstek_energy/+/App/+/ctrl\", [=](const std::string \u0026topic, const std::string \u0026payload) {\n          ESP_LOGD(\"MQTT\", \"Received control message: %s\", topic.c_str());\n          if (topic.find(\"/App/\") == std::string::npos) {\n            ESP_LOGD(\"MQTT\", \"Not a control message, skipping\");\n            return;\n          }\n          if (topic.find(\"/ctrl\") == std::string::npos) {\n            ESP_LOGD(\"MQTT\", \"Not a control message, skipping\");\n            return;\n          }\n          id(local_broker).publish_message(topic, payload);\n        });\n\nmosquitto_broker:\n  id: local_broker\n  tls: true\n  tls_skip_verification: true\n  port: 8883\n  max_clients: 5\n  on_message:\n    # Only forward messages containing /device/\n    - if:\n        condition:\n          lambda: 'return topic.find(\"/device/\") != std::string::npos;'\n        then:\n          - mqtt.publish:\n              topic: !lambda |-\n                return topic;\n              payload: !lambda |-\n                return payload;\n\nweb_server:\n  port: 80\n  version: 3\n\nmarstack:\n  id: marstack_http\n  on_request:\n    - logger.log:\n        format: \"HTTP %s %s body=%s\"\n        args: [method.c_str(), url.c_str(), body.c_str()]\n    - mqtt.publish:\n        topic: ${mqtt_topic_prefix}/request\n        payload: !lambda |-\n          return json::build_json([\u0026](JsonObject root) {\n            root[\"source_ip\"] = source_ip;\n            root[\"url\"] = url;\n            root[\"method\"] = method;\n            root[\"body\"] = body;\n          });\n```\n\n### Step 2: Adjust Configuration Values\n\nEdit the `substitutions` section at the top of the configuration file:\n\n- **`wifi_ssid`** and **`wifi_password`**: Your home WiFi network credentials (so Marsrelay can connect to your network)\n- **`ap_ssid`** and **`ap_password`**: The WiFi network name and password that your Marstek device will connect to (default is \"marsrelay\" / \"marsrelay\")\n- **`mqtt_broker`**: The IP address of your MQTT broker (e.g., `192.168.1.100`)\n- **`mqtt_username`** and **`mqtt_password`**: Your MQTT broker credentials (leave empty if not required)\n- **`psram.enabled`** and **`psram.mode`**: Set according to your ESP32-S3 board specifications\n\n### Step 3: Build and Flash\n\n1. Open ESPHome (e.g., via the Home Assistant ESPHome addon)\n2. Upload the configuration file\n3. Build the firmware image\n4. Flash the image to your ESP32-S3 device\n\n### Step 4: Configure Your Marstek Energy Storage Device\n\n1. On your Marstek Energy Storage device, go to the WiFi/Network settings\n2. Configure it to connect to the access point named \"marsrelay\" (or whatever you set as `ap_ssid`)\n3. Enter the password you configured (default is \"marsrelay\")\n4. Save the configuration\n\n**That's it!** No hacking, no firmware modifications, no complicated setup. Just change the WiFi network your Marstek device connects to.\n\n### Step 5: Find Your Device Information\n\n1. Open MQTT Explorer (or another MQTT client) and connect to your MQTT broker\n2. Wait up to 20 minutes for a message to appear on the topic: `marstek_energy/\u003cdeviceType\u003e/device/\u003cdeviceId\u003e/ctrl`\n3. Note down the **`deviceType`** and **`deviceId`** from the topic\n\n### Step 6: Configure hm2mqtt\n\nCopy the `deviceType` and `deviceId` you found into your [hm2mqtt](https://github.com/tomquist/hm2mqtt) configuration file. Your Marstek Energy Storage system is now integrated with your home automation!\n\n---\n\n## Technical Details\n\nThis repository contains ESPHome external components for building Marsrelay:\n\n### Components\n\n- **`mosquitto_broker`**: An embedded MQTT broker that forwards messages from Marstek devices to your main MQTT broker\n- **`marstack`**: A web server component that implements Marstek's API endpoints\n- **`capture_dns`**: DNS redirection component that intercepts DNS queries and redirects them to the device\n- **`udp_proxy`**: UDP proxy component that bridges UDP broadcasts between the AP network (where Marstek devices connect) and the STA network (your home network). This enables zero feed-in control by forwarding UDP discovery/control packets between networks. Supports multiple ports.\n- **`wifi`**: Patched WiFi component to support simultaneous access point while station mode is enabled\n\n### Requirements\n\n- ESP32-S3 device (ESP-IDF framework)\n- ESPHome\n- MQTT broker on your network\n\n## License\n\nMIT License\n\nCopyright (c) 2024\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftomquist%2Fmarsrelay","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftomquist%2Fmarsrelay","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftomquist%2Fmarsrelay/lists"}