Sofar2mqtt - Remote Control for Sofar Solar Inverters
Introduction: Sofar2mqtt - Remote Control for Sofar Solar Inverters
A smart home interface for Sofar solar and battery inverters.
Supported models:
ME3000SP and HYD-xx00
Sofar2mqtt is a remote control interface for Sofar solar and battery inverters. It allows remote control of the inverter and reports the invertor status, power usage, battery state etc for integration with smart home systems such as Open Energy Monitor, Home Assistant and Node-Red.
As a prerequisite, you will need to be running an MQTT broker on your network. A Step 10 details the options for this.
For read only mode, it will send inverter status messages via MQTT with the inverter in any run mode.
To control the inverter, place it in passive mode and send messages to sofar2mqtt/set.
It runs on an ESP8266 microcontroller with a TTL to RS485 module such as MAX485 or MAX3485.
Designed to work with TTL modules with or without the DR and RE flow control pins. If your TTL module does not have these pins then just ignore the wire from D5.
Step 1: Parts List
1. ESP8266 Microcontroller
2. MAX3485 or MAX485 TTL to RS485 board*
3. Wemos 64x48 OLED Screen (optional)
4. A small project board
5. A few wires and a little solder
*The MAX3485 (which is red, not blue like the MAX485 shown here) is preferred as it is much more stable because it uses 3.3v logic, just like the ESP8366. The MAX485 uses 5v logic but is somewhat tolerant of 3.3v and is generally cheaper and more widely available. I use a MAX485 but many people have reported problems with this and if you can find a MAX3485 then you should use that. MAX3485 boards do not have DR and RE flow control pins, so just skip the wire from pin D5 in the wiring diagram below.
Step 2: Cut the Project Board to a Convenient Size.
Optional step. 382
Arrange the components on the board and see what the final size will be. Trim the board if you like.
Step 3: Wiring
Wire the components according to this circuit diagram.
Step 4: More Wiring
I tend to keep the wires on top of the board, poke them through and solder underneath. Your approach may be better and your soldering will almost certainly be better than mine!
Step 5: Finished Wiring
Make sure you connect the DR and RE pins together. The red arrow shows where a single wire from D5 connects to both DR and RE. (If you are using a TTL board without the DR and RE pins, ignore this step.)
Step 6: Add the OLED Screen
The OLED screen is optional but is a nice addition to monitor the run mode of your inverter.
Use long pinned mounts on your ESP8266 if you are stacking the OLED on top. Trim the legs so they fit comfortably into another pair of sockets on the circuit board below.
I don't recommend soldering the ESP8266 directly to your circuit board as it may make debugging more difficult.
Step 7: Finishing
Here's how it looks when completed.
Step 8: Flashing
Download and unzip the code from https://github.com/cmcgerty/Sofar2mqtt
Open either ME3000SP.ino or HYBRID.ino (as appropriate for your inverter model) in the Arduino IDE.
Edit it with your wifi network name and password and your mqtt server details. If you need more than one Sofar2mqtt on your network, make sure you give them unique device names.
You'll need the libraries for the ESP8266. Follow this guide if you haven't completed that step before.
Add a few more libraries using the Manage Libraries menu:
1. PubSubClient
2. Adafruit GFX
3. Adafruit SSD1306 Wemos Mini OLED
(Even if you are not using the OLED screen, you should install the Adafruit libraries or it will not compile.)
...and upload.
Step 9: Testing
Run it on the desktop, not connected to you invertor, to test that wifi and mqtt are connected and see some messages in the serial monitor. The OLED screen should show "Online" to indicate a connection to both WiFi and MQTT. It will alternate between "RS485 Error" and "CRC-FAULT" while the inverter is not connected. 977