Foxess Inverter Modbus

Edit, please read first:

  • The working ESPHome custom component can be found here.
  • Additionally @Safs managed to get this working with a Elfin Module

Hello,

i’m trying to read out my Foxess Solar Inverter over Modbus with esphome.
Unfortunately I can’t get it to work and since this is the first time I’m using modbus I don’t know where to start troubleshooting or even interpret the log entries. Perhaps there is someone who can point me in the right direction.

Esphome YAML:

esphome:
  name: wechselrichter

esp32:
  board: esp32dev
  framework:
    type: arduino

# Enable logging
logger:
  level: VERBOSE

# Enable Home Assistant API
api:

ota:
  password: "****************************"

wifi:
  ssid: "**************************"
  password: "*******************************"
  
  manual_ip:
    static_ip: 192.168.178.61
    gateway: 192.168.178.1
    subnet: 255.255.255.0

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Wechselrichter Fallback Hotspot"
    password: "*************************"

captive_portal:

uart:
  id: mod_bus
  tx_pin: 17
  rx_pin: 16
  baud_rate: 9600
  stop_bits: 1

modbus:
  #flow_control_pin: 5 #not needed since there is no writing to the inverter
  id: mod_bus_foxess
  #send_wait_time: 500ms

modbus_controller:
  - id: foxess
    address: 0x1
    modbus_id: mod_bus_foxess
    setup_priority: -10

sensor:
  - platform: modbus_controller
    modbus_controller_id: foxess
    name: "PV1-Voltage"
    id: pv1_voltage
    register_type: read
    address: 10800
    unit_of_measurement: "V"
    value_type: U_WORD
    
  - platform: modbus_controller
    modbus_controller_id: foxess
    name: "PV1-Current"
    id: pv1_current
    register_type: "read"
    address: 11001
    unit_of_measurement: "A"
    value_type: U_WORD
    
#  - platform: modbus_controller
#    modbus_controller_id: foxess
#    name: "PV1-Power"
#    id: pv1_power
#    register_type: "read"
#    address: 11002
#    unit_of_measurement: "W"
#    value_type: U_WORD

button:
  - platform: restart
    name: "Wechselrichter restart"

LOG (verbose):

[11:04:34][C][modbus_controller:276]: ModbusController:
[11:04:34][C][modbus_controller:277]:   Address: 0x01
[11:04:34][C][modbus_controller:283]:  Sensor type=4 start=0x2A30 offset=0x0 count=1 size=2
[11:04:34][C][modbus_controller:283]:  Sensor type=4 start=0x2AF9 offset=0x0 count=1 size=2
[11:04:34][C][modbus_controller:288]:   Range type=4 start=0x2A30 count=1 skip_updates=0
[11:04:34][C][modbus_controller:288]:   Range type=4 start=0x2AF9 count=1 skip_updates=0
[11:05:08][V][modbus_controller:159]: Updating modbus component
[11:05:08][V][modbus_controller:126]: Range : 2A30 Size: 1 (4) skip: 0
[11:05:08][V][modbus_controller:126]: Range : 2AF9 Size: 1 (4) skip: 0
[11:05:08][V][modbus_controller:036]: Sending next modbus command to device 1 register 0x2A30 count 1
[11:05:08][V][modbus:184]: Modbus write: 01.04.2A.30.00.01.39.DD (8)
[11:05:08][V][modbus_controller:465]: Command sent 4 0x2A30 1
[11:05:08][V][modbus:058]: Modbus received Byte  1 (0X1)
[11:05:08][V][modbus:058]: Modbus received Byte  4 (0X4)
[11:05:08][V][modbus:058]: Modbus received Byte  42 (0X2a)
[11:05:08][V][modbus:058]: Modbus received Byte  48 (0X30)
[11:05:08][V][modbus:058]: Modbus received Byte  0 (0X0)
[11:05:08][V][modbus:058]: Modbus received Byte  1 (0X1)
[11:05:08][V][modbus:058]: Modbus received Byte  221 (0Xdd)
[11:05:09][V][modbus_controller:036]: Sending next modbus command to device 1 register 0x2A30 count 1
[11:05:09][V][modbus:184]: Modbus write: 01.04.2A.30.00.01.39.DD (8)
[11:05:09][V][modbus_controller:465]: Command sent 4 0x2A30 1
[11:05:09][V][modbus:058]: Modbus received Byte  1 (0X1)
[11:05:09][V][modbus:058]: Modbus received Byte  4 (0X4)
[11:05:09][V][modbus:058]: Modbus received Byte  42 (0X2a)
[11:05:09][V][modbus:058]: Modbus received Byte  48 (0X30)
[11:05:09][V][modbus:058]: Modbus received Byte  0 (0X0)
[11:05:09][V][modbus:058]: Modbus received Byte  1 (0X1)
[11:05:09][V][modbus:058]: Modbus received Byte  57 (0X39)
[11:05:09][V][modbus:058]: Modbus received Byte  221 (0Xdd)
[11:05:09][V][modbus_controller:036]: Sending next modbus command to device 1 register 0x2A30 count 1
[11:05:09][V][modbus:184]: Modbus write: 01.04.2A.30.00.01.39.DD (8)
[11:05:09][V][modbus_controller:465]: Command sent 4 0x2A30 1
[11:05:09][V][modbus:058]: Modbus received Byte  1 (0X1)
[11:05:09][V][modbus:058]: Modbus received Byte  4 (0X4)
[11:05:09][V][modbus:058]: Modbus received Byte  42 (0X2a)
[11:05:09][V][modbus:058]: Modbus received Byte  48 (0X30)
[11:05:09][V][modbus:058]: Modbus received Byte  0 (0X0)
[11:05:09][V][modbus:058]: Modbus received Byte  1 (0X1)
[11:05:09][V][modbus:058]: Modbus received Byte  57 (0X39)
[11:05:09][V][modbus:058]: Modbus received Byte  221 (0Xdd)
[11:05:09][V][modbus_controller:036]: Sending next modbus command to device 1 register 0x2A30 count 1
[11:05:09][V][modbus:184]: Modbus write: 01.04.2A.30.00.01.39.DD (8)
[11:05:09][V][modbus_controller:465]: Command sent 4 0x2A30 1
[11:05:09][V][modbus:058]: Modbus received Byte  1 (0X1)
[11:05:09][V][modbus:058]: Modbus received Byte  4 (0X4)
[11:05:09][V][modbus:058]: Modbus received Byte  42 (0X2a)
[11:05:09][V][modbus:058]: Modbus received Byte  48 (0X30)
[11:05:09][V][modbus:058]: Modbus received Byte  0 (0X0)
[11:05:09][V][modbus:058]: Modbus received Byte  1 (0X1)
[11:05:09][V][modbus:058]: Modbus received Byte  57 (0X39)
[11:05:09][V][modbus:058]: Modbus received Byte  221 (0Xdd)
[11:05:09][V][modbus_controller:036]: Sending next modbus command to device 1 register 0x2A30 count 1
[11:05:09][V][modbus:184]: Modbus write: 01.04.2A.30.00.01.39.DD (8)
[11:05:09][V][modbus_controller:465]: Command sent 4 0x2A30 1
[11:05:09][V][modbus:058]: Modbus received Byte  1 (0X1)
[11:05:09][V][modbus:058]: Modbus received Byte  4 (0X4)
[11:05:09][V][modbus:058]: Modbus received Byte  42 (0X2a)
[11:05:10][V][modbus:058]: Modbus received Byte  48 (0X30)
[11:05:10][V][modbus:058]: Modbus received Byte  0 (0X0)
[11:05:10][V][modbus:058]: Modbus received Byte  1 (0X1)
[11:05:10][V][modbus:058]: Modbus received Byte  57 (0X39)
[11:05:10][V][modbus:058]: Modbus received Byte  221 (0Xdd)
[11:05:10][D][modbus_controller:032]: Modbus command to device=1 register=0x2A30 countdown=0 no response received - removed from send queue
[11:05:10][V][modbus_controller:036]: Sending next modbus command to device 1 register 0x2AF9 count 1
[11:05:10][V][modbus:184]: Modbus write: 01.04.2A.F9.00.01.E9.E3 (8)
[11:05:10][V][modbus_controller:465]: Command sent 4 0x2AF9 1
[11:05:10][V][modbus:058]: Modbus received Byte  1 (0X1)
[11:05:10][V][modbus:058]: Modbus received Byte  4 (0X4)
[11:05:10][V][modbus:058]: Modbus received Byte  42 (0X2a)
[11:05:10][V][modbus:058]: Modbus received Byte  249 (0Xf9)
[11:05:10][V][modbus:058]: Modbus received Byte  0 (0X0)
[11:05:10][V][modbus:058]: Modbus received Byte  1 (0X1)
[11:05:10][V][modbus:058]: Modbus received Byte  233 (0Xe9)
[11:05:10][V][modbus:058]: Modbus received Byte  227 (0Xe3)
[11:05:10][V][modbus_controller:036]: Sending next modbus command to device 1 register 0x2AF9 count 1
[11:05:10][V][modbus:184]: Modbus write: 01.04.2A.F9.00.01.E9.E3 (8)
[11:05:10][V][modbus_controller:465]: Command sent 4 0x2AF9 1
[11:05:10][V][modbus:058]: Modbus received Byte  1 (0X1)
[11:05:10][V][modbus:058]: Modbus received Byte  4 (0X4)
[11:05:10][V][modbus:058]: Modbus received Byte  42 (0X2a)
[11:05:10][V][modbus:058]: Modbus received Byte  249 (0Xf9)
[11:05:10][V][modbus:058]: Modbus received Byte  0 (0X0)
[11:05:10][V][modbus:058]: Modbus received Byte  1 (0X1)
[11:05:10][V][modbus:058]: Modbus received Byte  233 (0Xe9)
[11:05:10][V][modbus:058]: Modbus received Byte  227 (0Xe3)
[11:05:10][V][modbus_controller:036]: Sending next modbus command to device 1 register 0x2AF9 count 1
[11:05:10][V][modbus:184]: Modbus write: 01.04.2A.F9.00.01.E9.E3 (8)
[11:05:10][V][modbus_controller:465]: Command sent 4 0x2AF9 1
[11:05:10][V][modbus:058]: Modbus received Byte  1 (0X1)
[11:05:10][V][modbus:058]: Modbus received Byte  4 (0X4)
[11:05:10][V][modbus:058]: Modbus received Byte  42 (0X2a)
[11:05:10][V][modbus:058]: Modbus received Byte  249 (0Xf9)
[11:05:10][V][modbus:058]: Modbus received Byte  0 (0X0)
[11:05:10][V][modbus:058]: Modbus received Byte  1 (0X1)
[11:05:10][V][modbus:058]: Modbus received Byte  233 (0Xe9)
[11:05:10][V][modbus:058]: Modbus received Byte  227 (0Xe3)
[11:05:11][V][modbus_controller:036]: Sending next modbus command to device 1 register 0x2AF9 count 1
[11:05:11][V][modbus:184]: Modbus write: 01.04.2A.F9.00.01.E9.E3 (8)
[11:05:11][V][modbus_controller:465]: Command sent 4 0x2AF9 1
[11:05:11][V][modbus:058]: Modbus received Byte  1 (0X1)
[11:05:11][V][modbus:058]: Modbus received Byte  4 (0X4)
[11:05:11][V][modbus:058]: Modbus received Byte  42 (0X2a)
[11:05:11][V][modbus:058]: Modbus received Byte  249 (0Xf9)
[11:05:11][V][modbus:058]: Modbus received Byte  0 (0X0)
[11:05:11][V][modbus:058]: Modbus received Byte  1 (0X1)
[11:05:11][V][modbus:058]: Modbus received Byte  233 (0Xe9)
[11:05:11][V][modbus:058]: Modbus received Byte  227 (0Xe3)
[11:05:11][V][modbus_controller:036]: Sending next modbus command to device 1 register 0x2AF9 count 1
[11:05:11][V][modbus:184]: Modbus write: 01.04.2A.F9.00.01.E9.E3 (8)
[11:05:11][V][modbus_controller:465]: Command sent 4 0x2AF9 1
[11:05:11][V][modbus:058]: Modbus received Byte  1 (0X1)
[11:05:11][V][modbus:058]: Modbus received Byte  4 (0X4)
[11:05:11][V][modbus:058]: Modbus received Byte  42 (0X2a)
[11:05:11][V][modbus:058]: Modbus received Byte  249 (0Xf9)
[11:05:11][V][modbus:058]: Modbus received Byte  0 (0X0)
[11:05:11][V][modbus:058]: Modbus received Byte  1 (0X1)
[11:05:11][V][modbus:058]: Modbus received Byte  233 (0Xe9)
[11:05:11][V][modbus:058]: Modbus received Byte  227 (0Xe3)
[11:05:11][D][modbus_controller:032]: Modbus command to device=1 register=0x2AF9 countdown=0 no response received - removed from send queue

It seems this is the main error message

[11:05:11][D][modbus_controller:032]: Modbus command to device=1 register=0x2AF9 countdown=0 

but I’m not sure what it means.

What I have tried so far:

  • swap RX and TX
  • add send_wait_time: 500ms
  • Tried different addresses, register types and valuetypes

Very thankfull to anyone with some more experience to help me out!

1 Like

You need a ttl rs485 with automatic direction control

Ah sorry. Totally forget to describe my Hardware setup.
I’ve got it setup like this:

Wired like the fritzing diagram On this site

Wired up and powered by the inverter as described in the inverter manual

You need to use flow_control_pin

Hi, thanks for your help!
I’ve enabled the flow control pin on GPIO4 (the connection was allready soldered and i uncommented the line in the YAML).

Unfortunately nothing changes.
I’ve double checked all the wiring and went over the connections with a continuity meter, so i’m fairly certain it has to be something in the software i’m doing wrong.

Buy a rs485 ttl with automatic flow.

Ou check inverter manual for registers

Try with gpio 18 and 19.

I just tested with 18 and 19.

Registers need to be in hex 0x0000, I think

Thanks again for your input!

How would I know the rs485 to ttl converter has automatic flow? I havn’t seen it described in any of the poduct descriptions I’ve seen sofar. I believe the one I’m using does have it, correct me if i’m wrong.

From the log-output it does seem that the ESP is sending and receiving succesfully. It might be that i have the addresses wrong.
I just today found out that my inverter probably uses a different protocol from the (older?) ones.
It can be found here, but I don’t understand how to figure out the addresses. Perhaps you can have a look?

Also I would be interested in what your logs look like for a working connection.

That pdf is for cloud communications.

I need pdf with registers for local modbus communications

us_controller:036]: Sending next modbus command to device 1 register 0x2AF9 count 1
[11:05:11][V][modbus:184]: Modbus write: 01.04.2A.F9.00.01.E9.E3 (8)
[11:05:11][V][modbus_controller:465]: Command sent 4 0x2AF9 1
[11:05:11][V][modbus:058]: Modbus received Byte  1 (0X1)
[11:05:11][V][modbus:058]: Modbus received Byte  4 (0X4)
[11:05:11][V][modbus:058]: Modbus received Byte  42 (0X2a)
[11:05:11][V][modbus:058]: Modbus received Byte  249 (0Xf9)
[11:05:11][V][modbus:058]: Modbus received Byte  0 (0X0)
[11:05:11][V][modbus:058]: Modbus received Byte  1 (0X1)
[11:05:11][V][modbus:058]: Modbus received Byte  233 (0Xe9)
[11:05:11][V][modbus:058]: Modbus received Byte  227 (0Xe3)
[11:05:11][D][modbus_controller:032]: Modbus command to device=1

If you check. The received command is the same as sent.

Flow control is not working

Or bad soldering

Automatic flow direction ttl marked in yellow:

Ok. I’ve ordered the same one you are using. I almost ordered that one back then to begin with, but didn’t know what the pin left of the a and b pins was for (the one which is only labeled in chinese). Is this supposed to be connected to the ground of the modbus device?

Hello!

There is answer from foxess support:
“It is the same data. The inverter sends the same data to the server and on the rs485 port.
This is not a traditional modbus. There is no question-answer communication. RS485 is a standard communication interface which can transmit the real time data from inverter to a PC or other monitoring devices.”

Maybe it helps…

If it use “custom header” it will not work in esphome.

You could try with tasmota. But you need the new ttl rs485.

With Elfin-EW11 modbus to WiFi, it will work?

Elfin is just a bridge. You need at the end a custom parser

Tasmota has multi parsers

https://tasmota.github.io/docs/Smart-Meter-Interface/

You need read raw value to have sure of protocol

I connect inverter with Elfin-EW11, Elfin-EW11 configured as MMQT client and get in HA MMQT mosquito messages like this:

Message 15 received on fox_modbus at 09:05:
b'~~\x02c"zV\x00\xe8\x00\x00\x04\xf8\x00\x00\t4\x00\x13\x13\x87\x01\x99\t.\x00\x14\x13\x87\x01\xae\t@\x00\x14\x13\x87\x01\xb1\x15\xe3\x00\x0e\x00\x00\r\x18\x00\r\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x1e\x00\x1e\x00#\x00\x05\x00\x00T=\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00)\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xda\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x02\x00\x00\x00\x00\x03\x93\xfd\xd0\x05n\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x19\x92\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x14]\xe7\xe7'

Something that begins with x7f\x7f
And ends with xf7\xf7

So… How to decode that?

You need to know where registers start

It’s just hex values

But

aa bb cc dd ee

How do you know if:

  • aa bb
  • bb cc
  • dd ee

If you have a static value in inverter, we can check.

Just convert decimal to hex and compare

From manual:

Data format explanation:
a) Frame Header:indicate the start byte, fixed data:7E7E.
b) Data Length:indicate the data pack length, include user data, data type is Uint16.
c) Function Code:indicate all function requirements and responses, please see below table in detail.
d) Timestamp: indicates the current time, in seconds.
e) User data: represents the monitoring data of the inverter.
f) Check Code:MODBUS CRC16 check, LSB first, don’t contain frame header.
g) Frame End:indicate the end byte for data pack, fixed bytes: E7E7.

https://tasmota.github.io/docs/Smart-Meter-Interface/

1 Like

I’m away from home right now. I’ll definitely have a go at decoding this weekend, though. There should be easy to identify bits (like voltage being close to 230), and then go from there. Seems like the first part of your example message is missing? It ends with e7/e7, but should also start with 7e/7e

I haven’t been able to get any message from my inverter with my esphome setup. Hope the new rs485 module will change that (arrives tomorrow). If not I perhaps will also order a elfin.