https://github.com/mjpalmowski/can-bus-control-r4875g1-with-esphome-and-mqtt
Control and adjust Current and Voltage Parameters on HUAWAI R4875G Battery-Charger via ESP32-hosted Web-Page, MQTT or Homeassistant
https://github.com/mjpalmowski/can-bus-control-r4875g1-with-esphome-and-mqtt
esphome esphome-devices yaml
Last synced: 7 months ago
JSON representation
Control and adjust Current and Voltage Parameters on HUAWAI R4875G Battery-Charger via ESP32-hosted Web-Page, MQTT or Homeassistant
- Host: GitHub
- URL: https://github.com/mjpalmowski/can-bus-control-r4875g1-with-esphome-and-mqtt
- Owner: mjpalmowski
- License: mit
- Created: 2024-10-28T08:44:57.000Z (8 months ago)
- Default Branch: main
- Last Pushed: 2024-11-20T13:40:07.000Z (7 months ago)
- Last Synced: 2024-11-20T13:43:18.094Z (7 months ago)
- Topics: esphome, esphome-devices, yaml
- Homepage:
- Size: 2.1 MB
- Stars: 5
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Project Overview
Upcycling industrial equipment offers a sustainable approach to reusing highly reliable components. Mobile network operators' cell tower equipment is built to operate 24/7 under harsh conditions, making it compact, efficient, and resilient.
This project focuses on the **Huawei R4875G1 48V Rectifier Module**, originally designed to power cell tower equipment and battery banks with dependable DC power. Essentially, this is a robust battery charger that can be adjusted between 45V and 58V, powered by an unstable grid or a dirty AC generator input. The R4875G1 module boasts a "Name Plate Output" of 4000W and an impressive Mean Time Between Failures (MTBF) of 500,000 hours. It supports current adjustments, dynamic control, and features hibernation and wake-up functions.
[View the R4975G1 Datasheet](https://github.com/user-attachments/files/17574446/R4975G1.Datasheet.pdf)
This module is 97% efficient, provides up to 4kW of DC power, and includes short circuit and surge protection, communicating via CAN BUS. These capabilities make it suitable for home battery charging, achieved through reverse-engineering its CAN BUS control.
## Key Features
The ESPHome firmware for this project is built for an ESP32 development board, which natively supports CAN BUS. The ESP32 connects to the R4875G1 via a VP230 CAN-BUS transceiver. Below are the main features:### Supported Sensors
- **AC Power In**
- **DC Power Out**
- **Grid Frequency**
- **Input Current**
- **Output Voltage**
- **Set Maximum Output Current**
- **Input Grid Voltage**
- **Output Temperature**
- **Output Current**### Configuration Settings
- **CAN Voltage Set**
- **CAN Amp Set**
- **Fallback Amp Set**
- **Fallback Voltage Set**### Control Buttons
- **CAN ON Button** (Wake-up feature)
- **CAN OFF Button** (Hibernate feature)
- **Fan Full Speed Button**
- **Fan Auto Mode Button**### Additional Features
- **Over-temperature Shutdown** (Configurable in YAML, does not require Home Assistant or Node-RED)## Use Cases
This setup is ideal for charging common 15s and 16s LiFePO4 packs and 14s NMC batteries, making it useful for home battery systems that store solar or off-peak power. It is particularly useful when backing up solar setups with a generator. Additionally, it can serve as a powerful DC bench power supply when paired with a robust adjustable buck/boost converter, or even as an onboard e-bike charger.For example, the **EG4 Chargeverter** product is essentially two of these 48V telecom units in a box, with buttons for setting maximum voltage and current. [Watch the Chargeverter Teardown](https://www.youtube.com/watch?v=WPEjRtABc2U).
## Hardware Setup
### Module and Connections
The **Huawei R4875G1** power module is controlled as shown below. It can output 35A at 54V continuously at an ambient temperature of 23°C without additional cooling.
PCB edge connectors for the R4875G1 and R4875G5 series are available on AliExpress.

- **ESP32 WROOM** Development Board
- **VP230** CAN-BUS transceiver Board (SN65HVD230)
- **R4875G1/G5 Board Edge Connector**
- **DC Cables**: 8 AWG silicone-insulated, supporting up to 40A continuously.
- **AC Cables**: Rated for continuous 16A supply.
- **CAN BUS Connections**: White (CAN-L) and Black (CAN-H)To connect, ensure the TX pin from the ESP32 is connected to the transceiver's TX pin, and the RX pin is connected to the transceiver's RX pin.

For those not using the adapter board, the module can be manually turned on by shorting specific pads to DC-minus.

Top side view

Bottom Side view (Details in the "YouTube Hardware Overview" link blow)
### Hardware References
- [PCB Adapter Guide](https://endless-sphere.com/sphere/threads/rectifier-huawei-r4850g2-48v-42-58v-3000w.86038/post-1732290)
- [YouTube Hardware Overview](https://www.youtube.com/watch?v=yvtQGEbZ6_c)## Software Configuration
You can use the **ESPHome** plugin in Home Assistant to create a new device and paste the provided YAML configuration.
If you prefer a standalone setup, you can configure the web server component for browser based control.1. **MQTT**: Uncomment the `mqtt:` block if using MQTT.
2. **Home Assistant API**: Uncomment the `api:` block for Home Assistant discovery.
3. **Web Interface**: Uncomment the `webserver:` block if a web interface is needed.[View R4875G CAN Control YAML](./CAN-R4875G1-ESP32.YAML)
## Pre-compiled `.bin` files are available for direct upload to an ESP32 board if you do not wish to modify the YAML file:
https://github.com/mjpalmowski/CAN-BUS-control-R4875G1-with-ESPHome-and-MQTT/releases/tag/v0.9
https://web.esphome.io/?dashboard_wizard to upload the .bin
### Example Screenshots




# MQTT Configuration
## Sensors
### Input AC Power
- **Name:** `01 Input AC Power`
- **State Topic:** `r4875g1-can-web/sensor/01_input_ac_power/state`### Output DC Power
- **Name:** `05 Output DC Power`
- **State Topic:** `r4875g1-can-web/sensor/05_output_dc_power/state`### Input Grid AC Frequency
- **Name:** `02 Input Grid AC Frequency`
- **State Topic:** `r4875g1-can-web/sensor/02_input_grid_ac_frequency/state`### Input AC Current
- **Name:** `03 Input AC Current`
- **State Topic:** `r4875g1-can-web/sensor/03_input_ac_current/state`### Output DC Voltage
- **Name:** `07 Output DC Voltage`
- **State Topic:** `r4875g1-can-web/sensor/07_output_dc_voltage/state`### Input AC Grid Voltage
- **Name:** `04 Input AC Grid Voltage`
- **State Topic:** `r4875g1-can-web/sensor/04_input_ac_grid_voltage/state`### Output Temperature
- **Name:** `08 Output Temperature`
- **State Topic:** `r4875g1-can-web/sensor/08_output_temperature/state`### Output DC Current
- **Name:** `06 Output DC Current`
- **State Topic:** `r4875g1-can-web/sensor/06_output_dc_current/state`### Max Output DC Current
- **Name:** `09 Max Output DC Current`
- **State Topic:** `r4875g1-can-web/sensor/09_max_output_dc_current/state`## Numbers (report human readable value whenever the values are set)

### CAN Voltage Set
- **Name:** `10 CAN Voltage Set`
- **State Topic:** `r4875g1-can-web/number/10_can_voltage_set/state`### Set Output DC Current
- **Name:** `12 Set Output DC Current`
- **State Topic:** `r4875g1-can-web/number/12_set_output_dc_current/state`### Set Fallback Output DC Current
- **Name:** `13 Set Fallback Output DC Current`
- **State Topic:** `r4875g1-can-web/number/13_set_fallback_output_dc_current/state`### Set Fallback Output DC Voltage
- **Name:** `11 Set Fallback Output DC Voltage`
- **State Topic:** `r4875g1-can-web/number/11_set_fallback_output_dc_voltage/state`## Buttons

### CAN ON Button
- **Name:** `001 CAN ON Button`
- **Command Topic:** `r4875g1-can-web/button/001_can_on_button/command`### CAN OFF Button
- **Name:** `002 CAN OFF Button`
- **Command Topic:** `r4875g1-can-web/button/002_can_off_button/command`### Fan Full Speed Button
- **Name:** `Fan Full Speed Button`
- **Command Topic:** `r4875g1-can-web/button/fan_full_speed_button/command`### Fan Auto Mode Button
- **Name:** `Fan Auto Mode Button`
- **Command Topic:** `r4875g1-can-web/button/fan_auto_mode_button/command`## Text Sensors, used to set values by mqtt/NodeRed

### CAN Voltage MQTT
- **Name:** `CAN Voltage MQTT`
- **Topic:** `home/canbus/voltage_set`### CAN Amps MQTT
- **Name:** `CAN Amps MQTT`
- **Topic:** `home/canbus/amp_set`### Fallback Voltage MQTT
- **Name:** `Fallback Voltage MQTT`
- **Topic:** `home/canbus/fallback_voltage_set`### Fallback Amps MQTT
- **Name:** `Fallback Amps MQTT`
- **Topic:** `home/canbus/fallback_amp_set`## Additional Resources
- [Huawei R4875G1 CAN Protocol](https://github.com/user-attachments/files/17571999/Protocol_R4875g.xlsx)
- [Beyond Logic Review](https://www.beyondlogic.org/review-huawei-r4850g2-power-supply-53-5vdc-3kw/)
- [Endless Sphere Forum](https://endless-sphere.com/sphere/threads/rectifier-huawei-r4850g2-48v-42-58v-3000w.86038/)
- [DIY Solar Forum Discussion](https://diysolarforum.com/threads/diy-chargenectifier.56329/)