Skip to content
View in the app

A better way to browse. Learn more.

Power Forum - Renewable Energy Discussion

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

My Sunsynk 8Kw & data collection setup

Featured Replies

On 2023/08/13 at 6:25 PM, slipx said:

Hi, slipx. Thanks a mill for all your work on ESPHome. I got set up pretty easily with an ESP32 and following this forum thread and scoobs' youtube vids. Got data pulling through but it was all jumbled, figured out that it's because I have the Sunsynk 12kva 3ph and the register is different.

My question is:
On your github page there's a yaml for the 8kw inverters that is complete (and is what I got started with) and another yaml file for the 12kw inverters. The 12kw file appears incomplete? How do I go about replacing the relevant parts of the 8kw file?
I've tried just copy pasting everything from the 12kw yaml to the 8kw yaml after the BINARY SENSORS line but it breaks the yaml code. After some fiddling I found that the issue that I thought was spacing or something was actually the ${modbus_controller_id} term that was causing trouble. I replaced all instances with "sunsynk".

Also, there appears to be a lot more sensors in the 8kw file than in the 12kw file, is that correct or do I need to pick each sensor code section out one by one from the 12kw file and replace em in the 8kw file?

Thanks again!

  • Replies 657
  • Views 178.1k
  • Created
  • Last Reply

Top Posters In This Topic

Most Popular Posts

  • If you want to try this card in home assistant follow these steps. 1. Create a new directory under www/community/ and name it sunsynk-card. If you don't have HACS installed you can create directo

  • Hi all. Here is my version to get Sunsynk 8.8 Modbus metrics in Home Assistant: Required Hardware: ESP32 Development Board @R149.95 https://www.diyelectronics.co.za/store/espressif-iot/1495-

  • Thought I would also contribute with something small. Not as impressive as what some of the others here but a contribution nonetheless. The GUI for Sunsynk System Mode, or lack thereof, has reall

Posted Images

Hi. I haven't really looked at the 12kW three phase inverters. That config was copied from another repo just for reference and has not been tested. If I have some time I'll create a proper version. 

On 2023/10/06 at 12:33 PM, slipx said:

Hi. I haven't really looked at the 12kW three phase inverters. That config was copied from another repo just for reference and has not been tested. If I have some time I'll create a proper version. 

OK that makes sense this. I'll do some work on it and if it works I'll post it on here.

On 2023/01/08 at 10:43 PM, Klatremis said:

I only made this user to share this 🤣 Thanks all for the inspiration. 

Exactly as BrettC suggest, I made this in the weekend for my deye :) I have shared it with some hundreds other danish deye owners and waiting for more feedback.

The adresses i use is matching my 12kW 3 phase, low voltage hybrid deye inverter. I seems for me that the modbus adresses does not match your sunsync inverters(deye inverters).

github.com/klatremis/esphome-for-deye

I'd like to power my ESP32 from the Sunsynk's board as well. Do you know the voltage on the CN2 7&8 pins? Would this USB power supply work?

https://make.net.za/product/usb-fast-charge-module-ip6505-single-usb/

On 2022/09/14 at 2:28 PM, Sc00bs said:

@sjlouw I am doing something wrong and I can't figure out what cause I can't get my ESP32 to work!

I have tried 2 different boards and two different RS485 connectors (same models as you specified) but no joy

Have tried different ethernet cables etc, I am using a T568B cable so using the orange/orange&white cables (pin 1&2)

These are the errors I am getting, any idea? 

Settings on the inverter are as specified. 

 

image.png.ee3477e0b2f360838d76488ffc69702d.png

 

 

I am also getting this issue. Did you manage to solve it?

Has anyone tried this on a 5kW Deye? I am struggling to get data from the inverter.

Here is my yaml code:

image.thumb.jpeg.5cc2302a6006793be07a73254fb7ae6f.jpeg

and here is the logs from ESPHome:

image.jpeg.4686939049a5b55e4f3b20b8ba10e320.jpeg

I have checked and rechecked wiring and soldering. It's as if no data is coming through.

@kellerza, so I adjusted the polling rates according to the link provided. It then still crash. I then increased to 20 seconds and it still crashed.
 

here is some of my config. Maybe there is something wrong with the sensors.

SENSOR_DEFINITIONS: single-phase
SENSORS:
  - energy_management
  - power_flow_card
  - pv2_voltage
  - pv2_power
  - pv2_current
  - battery_temperature
  - dc_transformer_temperature
  - radiator_temperature
  - total_load_energy
  - settings
  - load_limit
SENSORS_FIRST_INVERTER:
  - settings
MANUFACTURER: Sunsynk
READ_ALLOW_GAP: 2
READ_SENSORS_BATCH_SIZE: 20
SCHEDULES:
  - KEY: W
    READ_EVERY: 20
    REPORT_EVERY: 60
    CHANGE_BY: 80
  - KEY: RW
    READ_EVERY: 20
    REPORT_EVERY: 60
    CHANGE_ANY: true
  - KEY: any_unit
    READ_EVERY: 30
    REPORT_EVERY: 60
    CHANGE_BY: 80

 

On 2023/10/07 at 4:19 PM, BobTheDinosaur said:

I'd like to power my ESP32 from the Sunsynk's board as well. Do you know the voltage on the CN2 7&8 pins? Would this USB power supply work?

Depending on your inverter (Think the 3phase is 7&8), yes it will work, Make sure you double check positive and negative. Reversing the polarity leads to fubar micro-controllers. Also make sure you insulate it, you do not want positive to short to ground in the inverter case. 

On 2023/10/08 at 4:28 PM, ZippyZappy said:

I have checked and rechecked wiring and soldering. It's as if no data is coming through.

I have a purposefully designed circuit for Deye/Sunsynk/Sol-Ark inverters called the SmartDeyeDongle with custom written firmware (for home assistant) where I actually fixed the quirks in the opensource software. (You can order from me, I ship to all cities/towns in South Africa) smarthomeintegrations(dot)co(dot)za

Considering your time is probably worth more than R250-500p/h most people struggle for days. If you aim is to learn low level electronics, let me not stand in your way. Welcome to the magic realm where the smoke means you lost a life, de-solder, reorder and try again.

If your aim is to get your inverter automated and saving on eskom consumption then getting a ready-made module is probably the way to go. Chances are that you will recoup the cost very quickly in a month or two.   

So I am just going to mention this here. Lots of people are trying to build RS485 circuits designed for 5V that was meant to be used on an Arduino platform. The whole arduino platform is 5V. The ESP32/8266 on the other hand is 3.3V. yrmv

On 2023/08/16 at 5:01 PM, XAB said:

Glad I could help @XianZA. I have now connected both cables on the BMS 485/CAN of my SUNSYNK 5.5KW(newer model) with the below RJ45 Duplicator (Important to get one that does not split the pairs but rather "mirrors" it). I connected Orange to A+ - Orange/WHT to B- and Green/WHT to ground on my USB to RS485. Now I can update settings via HASSIO finally.

Important to note that the RX / TX works on pins 1(Orange/WHT) and 2(Orange) and your battery on pins 4(Blue) and 5 ( Blue/WHT). I tested this first when getting the RJ45 splitter/duplicator.

Prior to this I could receive data via the RS485 port next to the CAN port(left of it) but had to use Blue/WHT(A+) & Blue (B-) from the cable to receive data via the USB to RS485. But could not update as the RS485 port only allowed to receive data.

Image of RJ45 Duplicator into BMS 485/CAN

IMG_0548.thumb.jpg.9690b5f616e62b2e3d65514e67880eb4.jpg

Image of USB to RS485 
IMG_0551.thumb.jpg.3119f76c81709a5e038b446f66e7898f.jpg

I think I've connected my sunsynk 8.8kw via the same method however getting a few errors, anyone have any ideas what I can try to get it working?

 
20231016_184837.thumb.jpg.1084760d861df882dc519dd9ca555620.jpg

20231016_185004.thumb.jpg.32eb0feca36fbba24e1d60b10a91ee85.jpg

MQQT shows this in the logs

image.png.611afa116aac3ce63aaeec6f0b460cf2.png

Sunsynk Multi shows these in the logs:

image.thumb.png.4baacb9e11ed3d39001cac9e18e9254a.png

 

image.thumb.png.b9e4a4e4cf66ae144af71a6e7205f0dc.png

image.thumb.png.4b99cccb76c8055b39610f60b684d5aa.png

 

Appreciate any help getting this working as I'm close to giving up at this stage but feel i'm sooooo close...

12 hours ago, chessmaster said:

I think I've connected my sunsynk 8.8kw via the same method however getting a few errors, anyone have any ideas what I can try to get it working?

 
20231016_184837.thumb.jpg.1084760d861df882dc519dd9ca555620.jpg

20231016_185004.thumb.jpg.32eb0feca36fbba24e1d60b10a91ee85.jpg

MQQT shows this in the logs

image.png.611afa116aac3ce63aaeec6f0b460cf2.png

Sunsynk Multi shows these in the logs:

image.thumb.png.4baacb9e11ed3d39001cac9e18e9254a.png

 

image.thumb.png.b9e4a4e4cf66ae144af71a6e7205f0dc.png

image.thumb.png.4b99cccb76c8055b39610f60b684d5aa.png

 

Appreciate any help getting this working as I'm close to giving up at this stage but feel i'm sooooo close...

Small update, looks like MQTT is looking healthier after installing this https://github.com/SharkyRawr/hass-mqtt-fix

image.thumb.png.30b682af1bf467c3db9bb7fd00f6e6c9.png

However I'm still getting these errors in the sunsynk multi logs:

image.thumb.png.49f8911ad857e8184345c3842975f569.png

Has anyone had this working on a new SunSynk 5.5 Ecco inverter in the UK?

Here are the ports on the UK 5.5 Ecco. I've tried the BMS \ CAN connector and RS485 connectors, I am begining to think that the UK versions do not have the correct pin outs on the BMS \ CAN bus and the RS485 port on the inverter may have a different pin out compared to the BMS \ CAN.

image.png.327c3d10e99d9a672a4f36ad9ff9f961.png

Edited by Ivan Endicott

On 2023/10/17 at 9:35 AM, chessmaster said:

However I'm still getting these errors in the sunsynk multi logs:

I assume the USB-RS485 dongle is on another machine with mbusd running? then your problem sounds/seems like a cable problem, between the dongle and the inverter, could even be a broken conductor in the cable making no contact on either of the 2 needed conductors...

Thanks all the contributors here, certainly a massive help!

I'm doing this slightly differently, and for another use case, using a microchip ATMEGA4809 and common line driver circuitry similar to what most are referencing, all at 5 volts.

To the point: The Deye machine I'm developing off.

MODEL NO:         SUN-5K-SG01LP1-EU

MAIN:            Ver 0-3381-1515

HMI:            Ver 0000-C35D

What I've found: T568B

BMS 485/CAN:

B-/Pin 1(orange/white), A+/Pin 2(orange), Pin3/Gnd(green/white).

METER/METER:

B-/Pin 4(blue), A+/Pin 5(blue/white), Pin3/Gnd(green/white).

Hopefully helps, I doubt this is the latest firmware, so you might have to split out with the battery.

 

 

Edited by Reuf
clarification

Guys, can you help, I see others get this error.

21:51:58][W][modbus_controller:136]: Duplicate modbus command found: type=0x3 address=150 count=1
[21:51:58][W][modbus_controller:136]: Duplicate modbus command found: type=0x3 address=154 count=1
[21:51:58][W][modbus_controller:136]: Duplicate modbus command found: type=0x3 address=160 count=1
[21:51:58][W][modbus_controller:136]: Duplicate modbus command found: type=0x3 address=164 count=1
[21:51:58][W][modbus_controller:136]: Duplicate modbus command found: type=0x3 address=166 count=4
[21:51:58][W][modbus_controller:136]: Duplicate modbus command found: type=0x3 address=172 count=1
[21:51:58][W][modbus_controller:136]: Duplicate modbus command found: type=0x3 address=175 count=4

Also, my sensors is unknown

 

How did you resolve this error,  duplicated Modbus ?

 

 

Guys on the Sunsynk 8KVA what must your MODBUS SN number be to use the ESP32Dev board & RS485 ?

Must it be left as 1 or changed to 0 ?

I struggle to get data from the inverter 

Everything was working fine for months, did ESPhome updates and Slipx updates and now receiving no data. Re-flashed etc a number of times etc. No luck

Thanks

On 2023/10/31 at 11:18 PM, Vaughanza said:

Guys on the Sunsynk 8KVA what must your MODBUS SN number be to use the ESP32Dev board & RS485 ?

Must it be left as 1 or changed to 0 ?

I struggle to get data from the inverter 

Everything was working fine for months, did ESPhome updates and Slipx updates and now receiving no data. Re-flashed etc a number of times etc. No luck

Thanks

I am struggling with the same issue.

I am now trying to figure out what changed, will let you know.

Using a 5kW though.

Perhaps @slipx, do you have any ideas for us, please?

On 2023/10/31 at 11:18 PM, Vaughanza said:

Guys on the Sunsynk 8KVA what must your MODBUS SN number be to use the ESP32Dev board & RS485 ?

Must it be left as 1 or changed to 0 ?

I struggle to get data from the inverter 

Everything was working fine for months, did ESPhome updates and Slipx updates and now receiving no data. Re-flashed etc a number of times etc. No luck

Thanks

I got mine sorted.

I updated ESPHome and HomeAssistant, then played around with the config for ESPHome:

 

substitutions:
  settings_skipped_updates: "30"
  devicename: sunsynk
  device_description: "Sunsynk RS485 Logger"
  friendly_name: "SunSynk"

esphome:
  name: $devicename
  comment: '${device_description}'
  
esp32:
  board: esp32dev
  framework:
    type: arduino

# Enable logging
logger:
  baud_rate: 0

# Enable Home Assistant API
api:
  encryption:
    key: !secret api_encryption_key

ota:
  password: !secret ota_password_sunsynk

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: '${devicename}'
    password: !secret fallback_password

  fast_connect: true
  power_save_mode: none

captive_portal:

# Enable time component to reset energy at midnight
# https://esphome.io/components/time.html#home-assistant-time-source
time:
   - platform: sntp
     id: sntp_time
     timezone: Africa/Johannesburg
     servers:
     - pool.ntp.org
     
uart:
  id: mod_bus
  tx_pin: 17
  rx_pin: 16
  baud_rate: 9600
  stop_bits: 1
 
modbus:
  id: sunsynk_modbus
  flow_control_pin: 4
 
modbus_controller:
  - id: sunsynk
    address: 0x01
    modbus_id: sunsynk_modbus
    setup_priority: -10
    update_interval: "5s"
    command_throttle: "50ms"

############################################### BINARY SENSORS ########################################
binary_sensor:           
  - platform: modbus_controller            # 194 Grid Connected Status
    modbus_controller_id: sunsynk
    name: "${friendly_name} Grid Connected Status"
    id: sunsynk_esphome_grid_connected_status
    register_type: holding
    address: 194

  - platform: modbus_controller           # 280 Gen Peak Shaving Status
    modbus_controller_id: sunsynk
    name: "${friendly_name} Gen Peak Shaving Status"
    id: sunsynk_esphome_gen_peak_shaving_status
    register_type: holding
    address: 280
    bitmask: 0x10

  - platform: modbus_controller           # 280 Grid Peak Shaving Status
    modbus_controller_id: sunsynk
    name: "${friendly_name} Grid Peak Shaving Status"
    id: sunsynk_esphome_grid_peak_shaving_status
    register_type: holding
    address: 280
    bitmask: 0x100

#                                               SENSORS                                               #
#######################################################################################################

############################################### BATTERY ###############################################
sensor:
  - platform: modbus_controller            # 182 Battery Temperature
    modbus_controller_id: sunsynk
    name: "${friendly_name} Battery Temperature"
    id: sunsynk_esphome_battery_temperature
    register_type: holding
    address: 182
    unit_of_measurement: "°C"
    accuracy_decimals: 1
    device_class: temperature
    state_class: measurement
    value_type: U_WORD 
    filters:
      - offset: -1000
      - multiply: 0.1

  - platform: modbus_controller            # 183 Battery Voltage
    modbus_controller_id: sunsynk
    name: "${friendly_name} Battery Voltage"
    id: sunsynk_esphome_battery_voltage
    register_type: holding
    address: 183
    unit_of_measurement: "V"
    accuracy_decimals: 1
    device_class: voltage
    state_class: measurement
    filters:
      - multiply: 0.01
    value_type: U_WORD

  - platform: modbus_controller            # 184 Battery SOC
    modbus_controller_id: sunsynk
    name: "${friendly_name} Battery SOC"
    id: sunsynk_esphome_battery_soc
    register_type: holding
    address: 184
    unit_of_measurement: "%"
    accuracy_decimals: 0
    device_class: battery
    value_type: U_WORD

  - platform: modbus_controller            # 190 Battery Power
    modbus_controller_id: sunsynk
    name: "${friendly_name} Battery Power"
    id: sunsynk_esphome_battery_power
    register_type: holding
    address: 190
    unit_of_measurement: "W"
    accuracy_decimals: 0
    device_class: power
    value_type: S_WORD

  - platform: modbus_controller            # 191 Battery Current
    modbus_controller_id: sunsynk
    name: "${friendly_name} Battery Current"
    id: sunsynk_esphome_battery_current
    register_type: holding
    address: 191
    unit_of_measurement: "A"
    accuracy_decimals: 1
    device_class: current
    state_class: measurement
    value_type: S_WORD
    filters:
      - multiply: 0.01

  - platform: modbus_controller            # 217 Battery Capacity Shutdown
    modbus_controller_id: sunsynk
    name: "${friendly_name} Battery Capacity Shutdown"
    id: sunsynk_esphome_battery_capacity_shutdown
    register_type: holding
    address: 217
    unit_of_measurement: "%"
    accuracy_decimals: 0
    device_class: battery

############################################### INVERTER ##############################################

  - platform: modbus_controller            # 175 Inverter Power
    modbus_controller_id: sunsynk
    name: "${friendly_name} Inverter Power"
    id: sunsynk_esphome_inverter_power
    register_type: holding
    address: 175
    unit_of_measurement: "W"
    accuracy_decimals: 0
    device_class: power
    value_type: S_WORD

  - platform: modbus_controller            # 154 Inverter Voltage
    modbus_controller_id: sunsynk
    name: "${friendly_name} Inverter Voltage"
    id: sunsynk_esphome_inverter_voltage
    register_type: holding
    address: 154
    unit_of_measurement: "V"
    accuracy_decimals: 1
    device_class: voltage
    state_class: measurement
    filters:
      - multiply: 0.1
    value_type: U_WORD 

  - platform: modbus_controller            # 164 Inverter Current
    modbus_controller_id: sunsynk
    name: "${friendly_name} Inverter Current"
    id: sunsynk_esphome_inverter_current
    register_type: holding
    address: 164
    unit_of_measurement: "A"
    accuracy_decimals: 1
    device_class: current
    state_class: measurement
    value_type: S_WORD
    filters:
      - multiply: 0.01

  - platform: modbus_controller            # 193 Inverter Frequency
    modbus_controller_id: sunsynk
    name: "${friendly_name} Inverter Frequency"
    id: sunsynk_esphome_inverter_frequency
    register_type: holding
    address: 193
    unit_of_measurement: "Hz"
    accuracy_decimals: 2
    filters:
      - multiply: 0.01
    value_type: U_WORD
    state_class: measurement

############################################### GRID ##################################################

  - platform: modbus_controller             # 079 Grid Frequency
    modbus_controller_id: sunsynk
    name: "${friendly_name} Grid Frequency"
    id: sunsynk_esphome_grid_frequency
    register_type: holding
    address: 79
    unit_of_measurement: "Hz"
    accuracy_decimals: 2
    filters:
      - multiply: 0.01
    value_type: U_WORD
    state_class: measurement

  - platform: modbus_controller             # 169 Grid Power
    modbus_controller_id: sunsynk
    name: "${friendly_name} Grid Power"
    id: sunsynk_esphome_grid_power_169
    register_type: holding
    address: 169
    unit_of_measurement: "W"
    accuracy_decimals: 0
    device_class: power
    state_class: measurement
    value_type: S_WORD

  - platform: modbus_controller             # 167 Grid LD Power
    modbus_controller_id: sunsynk
    name: "${friendly_name} Grid LD Power 167"
    id: sunsynk_esphome_grid_power_167
    register_type: holding
    address: 167
    unit_of_measurement: "W"
    accuracy_decimals: 0
    device_class: power
    state_class: measurement
    value_type: S_WORD

  - platform: modbus_controller             # 168 Grid L2 Power
    modbus_controller_id: sunsynk
    name: "${friendly_name} Grid L2 Power 168"
    id: sunsynk_esphome_grid_power_168
    register_type: holding
    address: 168
    unit_of_measurement: "W"
    accuracy_decimals: 0
    device_class: power
    state_class: measurement
    value_type: S_WORD

  - platform: modbus_controller             # 150 Grid Voltage
    modbus_controller_id: sunsynk
    name: "${friendly_name} Grid Voltage"
    id: sunsynk_esphome_grid_voltage
    register_type: holding
    address: 150
    unit_of_measurement: "V"
    accuracy_decimals: 1
    device_class: voltage
    state_class: measurement
    filters:
      - multiply: 0.1
    value_type: U_WORD 

  - platform: modbus_controller             # 160 Grid Current
    modbus_controller_id: sunsynk
    name: "${friendly_name} Grid Current"
    id: sunsynk_esphome_grid_current
    register_type: holding
    address: 160
    unit_of_measurement: "A"
    accuracy_decimals: 1
    device_class: current
    state_class: measurement
    value_type: S_WORD
    filters:
      - multiply: 0.01

  - platform: modbus_controller             # 172 Grid CT Power
    modbus_controller_id: sunsynk
    name: "${friendly_name} Grid CT Power"
    id: sunsynk_esphome_grid_ct_power
    register_type: holding
    address: 172
    unit_of_measurement: "W"
    accuracy_decimals: 0
    device_class: power
    state_class: measurement
    value_type: S_WORD

############################################### LOAD ################################################

  - platform: modbus_controller            # 178 Load Power
    modbus_controller_id: sunsynk
    name: "${friendly_name} Load Power"
    id: sunsynk_esphome_load_power
    register_type: holding
    address: 178
    unit_of_measurement: "W"
    accuracy_decimals: 0
    device_class: power
    state_class: measurement
    value_type: S_WORD

  - platform: modbus_controller            # 176 Load L1 Power
    modbus_controller_id: sunsynk
    name: "${friendly_name} Load L1 Power"
    id: sunsynk_esphome_load_l1_power
    register_type: holding
    address: 176
    unit_of_measurement: "W"
    accuracy_decimals: 0
    device_class: power
    state_class: measurement
    value_type: S_WORD

  - platform: modbus_controller            # 177 Load L2 Power
    modbus_controller_id: sunsynk
    name: "${friendly_name} Load L2 Power"
    id: sunsynk_esphome_load_l2_power
    register_type: holding
    address: 177
    unit_of_measurement: "W"
    accuracy_decimals: 0
    device_class: power
    state_class: measurement
    value_type: S_WORD

  - platform: modbus_controller            # 192 Load Frequency
    modbus_controller_id: sunsynk
    name: "${friendly_name} Load Frequency"
    id: sunsynk_esphome_load_frequency
    register_type: holding
    address: 192
    unit_of_measurement: "Hz"
    accuracy_decimals: 2
    filters:
      - multiply: 0.01
    value_type: U_WORD
    state_class: measurement

############################################### SOLAR PV1 #############################################

  - platform: modbus_controller            # 186 PV1 Power
    modbus_controller_id: sunsynk
    name: "${friendly_name} PV1 Power"
    id: sunsynk_esphome_pv1_power
    register_type: holding
    address: 186
    unit_of_measurement: "W"
    accuracy_decimals: 0
    device_class: power
    state_class: measurement
    value_type: U_WORD

  - platform: modbus_controller            # 109 PV1 Voltage
    modbus_controller_id: sunsynk
    name: "${friendly_name} PV1 Voltage"
    id: sunsynk_esphome_pv1_voltage
    register_type: holding
    address: 109
    unit_of_measurement: "V"
    device_class: voltage
    state_class: measurement
    accuracy_decimals: 1
    filters:
      - multiply: 0.1
    value_type: U_WORD

  - platform: modbus_controller            # 110 PV1 Current
    modbus_controller_id: sunsynk
    name: "${friendly_name} PV1 Current"
    id: sunsynk_esphome_pv1_current
    register_type: holding
    address: 110
    unit_of_measurement: "A"
    accuracy_decimals: 1
    device_class: current
    state_class: measurement
    filters:
      - multiply: 0.1
    value_type: U_WORD

############################################### SOLAR PV2 #############################################

  - platform: modbus_controller            # 187 PV2 Power
    modbus_controller_id: sunsynk
    name: "${friendly_name} PV2 Power"
    id: sunsynk_esphome_pv2_power
    register_type: holding
    address: 187
    unit_of_measurement: "W"
    accuracy_decimals: 0
    device_class: power
    state_class: measurement
    value_type: U_WORD

  - platform: modbus_controller            # 111 PV2 Voltage
    modbus_controller_id: sunsynk
    name: "${friendly_name} PV2 Voltage"
    id: sunsynk_esphome_pv2_voltage
    register_type: holding
    address: 111
    unit_of_measurement: "V"
    accuracy_decimals: 1
    filters:
      - multiply: 0.1
    device_class: voltage
    state_class: measurement
    value_type: U_WORD

  - platform: modbus_controller            # 112 PV2 Current
    modbus_controller_id: sunsynk
    name: "${friendly_name} PV2 Current"
    id: sunsynk_esphome_pv2_current
    register_type: holding
    address: 112
    unit_of_measurement: "A"
    accuracy_decimals: 1
    device_class: current
    state_class: measurement
    filters:
      - multiply: 0.1
    value_type: U_WORD

############################################### SOLAR TOTAL ###########################################

  - platform: template                   # Sum of PV1 and PV2 to get total PV Power
    name: "${friendly_name} Solar Power"
    unit_of_measurement: "W"
    accuracy_decimals: 0
    device_class: power
    state_class: measurement
    lambda: |-
      return (id(sunsynk_esphome_pv1_power).state + id(sunsynk_esphome_pv2_power).state);
    update_interval: 5s

############################################### OUTPUTS ###############################################

  - platform: modbus_controller            # 166 Aux Power
    modbus_controller_id: sunsynk
    name: "${friendly_name} AUX Power"
    id: sunsynk_esphome_aux_power
    register_type: holding
    address: 166
    unit_of_measurement: "W"
    accuracy_decimals: 0
    device_class: power
    state_class: measurement
    value_type: S_WORD

  - platform: template                   # Essential Power based on register 175 + 167 - 166
    name: "${friendly_name} Essential Power"
    unit_of_measurement: "W"
    accuracy_decimals: 0
    device_class: power
    state_class: measurement
    lambda: |-
      return (id(sunsynk_esphome_inverter_power).state + id(sunsynk_esphome_grid_power_167).state - id(sunsynk_esphome_aux_power).state);
    update_interval: 5s

  - platform: template                   # Essential Power1 based on register 175 + 169 - 166
    name: "${friendly_name} Essential Power 1"
    unit_of_measurement: "W"
    accuracy_decimals: 0
    device_class: power
    state_class: measurement
    lambda: |-
      return (id(sunsynk_esphome_inverter_power).state + id(sunsynk_esphome_grid_power_169).state - id(sunsynk_esphome_aux_power).state);
    update_interval: 5s

  - platform: template                   # Nonessential Power 172 - 167
    name: "${friendly_name} Nonessential Power"
    unit_of_measurement: "W"
    accuracy_decimals: 0
    device_class: power
    state_class: measurement
    lambda: |-
      return (id(sunsynk_esphome_grid_ct_power).state - id(sunsynk_esphome_grid_power_167).state);
    update_interval: 5s

  - platform: template                   # Nonessential Power1 172 - 169
    name: "${friendly_name} Nonessential Power 1"
    unit_of_measurement: "W"
    accuracy_decimals: 0
    device_class: power
    state_class: measurement
    lambda: |-
      return (id(sunsynk_esphome_grid_ct_power).state - id(sunsynk_esphome_grid_power_169).state);
    update_interval: 5s

############################################### ENERGY ################################################

  - platform: modbus_controller            # 070 Day Battery Charge
    modbus_controller_id: sunsynk
    name: "${friendly_name} Day Battery Charge"
    id: sunsynk_esphome_day_battery_charge
    register_type: holding
    address: 70
    unit_of_measurement: "kWh"
    accuracy_decimals: 1
    device_class: energy
    state_class: total_increasing
    value_type: U_WORD
    filters:
      - multiply: 0.1

  - platform: modbus_controller            # 071 Day Battery Discharge
    modbus_controller_id: sunsynk
    name: "${friendly_name} Day Battery Discharge"
    id: sunsynk_esphome_day_battery_discharge
    register_type: holding
    address: 71
    unit_of_measurement: "kWh"
    accuracy_decimals: 1
    device_class: energy
    state_class: total_increasing
    value_type: U_WORD
    filters:
      - multiply: 0.1

  - platform: modbus_controller            # 072 Total Battery Charge
    modbus_controller_id: sunsynk
    name: "${friendly_name} Total Battery Charge"
    id: sunsynk_esphome_total_battery_charge
    register_type: holding
    address: 72
    unit_of_measurement: "kWh"
    accuracy_decimals: 1
    device_class: energy
    state_class: total_increasing
    value_type: U_DWORD_R
    filters:
     - multiply: 0.1

  - platform: modbus_controller            # 074 Total Battery Discharge
    modbus_controller_id: sunsynk
    name: "${friendly_name} Total Battery Discharge"
    id: sunsynk_esphome_total_battery_discharge
    register_type: holding
    address: 74
    unit_of_measurement: "kWh"
    accuracy_decimals: 0
    device_class: energy
    state_class: total_increasing
    value_type: U_DWORD_R
    filters:
     - multiply: 0.1

  - platform: modbus_controller            # 076 Day Grid Import
    modbus_controller_id: sunsynk
    name: "${friendly_name} Day Grid Import"
    id: sunsynk_esphome_day_grid_import
    register_type: holding
    address: 76
    unit_of_measurement: "kWh"
    accuracy_decimals: 1
    device_class: energy
    state_class: total_increasing
    value_type: U_WORD
    filters:
      - multiply: 0.1

  - platform: modbus_controller            # 077 Day Grid Export
    modbus_controller_id: sunsynk
    name: "${friendly_name} Day Grid Export"
    id: sunsynk_esphome_day_grid_export
    register_type: holding
    address: 77
    unit_of_measurement: "kWh"
    accuracy_decimals: 1
    device_class: energy
    state_class: total_increasing
    value_type: U_WORD
    filters:
      - multiply: 0.1

  - platform: modbus_controller            # 078 Total Grid Import
    modbus_controller_id: sunsynk
    name: "${friendly_name} Total Grid Import"
    id: sunsynk_esphome_total_grid_import
    register_type: holding
    address: 78
    unit_of_measurement: "kWh"
    accuracy_decimals: 2
    device_class: energy
    state_class: total_increasing
    value_type: U_WORD
    filters:
      - multiply: 0.1

  - platform: modbus_controller            # 081 Total Grid Export
    modbus_controller_id: sunsynk
    name: "${friendly_name} Total Grid Export"
    id: sunsynk_esphome_total_grid_export
    register_type: holding
    address: 81
    unit_of_measurement: "kWh"
    accuracy_decimals: 2
    device_class: energy
    state_class: total_increasing
    value_type: U_WORD
    filters:
      - multiply: 0.1

  - platform: modbus_controller            # 084 Day Load Energy
    modbus_controller_id: sunsynk
    name: "${friendly_name} Day Load Energy"
    id: sunsynk_esphome_day_load_energy
    register_type: holding
    address: 84
    unit_of_measurement: "kWh"
    accuracy_decimals: 2
    device_class: energy
    state_class: total_increasing
    filters:
      - multiply: 0.1
    value_type: U_WORD

  - platform: modbus_controller            # 085 Total Load Energy
    modbus_controller_id: sunsynk
    name: "${friendly_name} Total Load Energy"
    id: sunsynk_esphome_total_load_energy
    register_type: holding
    address: 85
    unit_of_measurement: "kWh"
    accuracy_decimals: 2
    device_class: energy
    state_class: total_increasing
    value_type: U_DWORD_R
    filters:
      - multiply: 0.1

  - platform: modbus_controller            # 096 Total PV Energy
    modbus_controller_id: sunsynk
    name: "${friendly_name} Total PV Energy"
    id: sunsynk_esphome_total_pv_energy
    register_type: holding
    address: 96
    unit_of_measurement: "kWh"
    accuracy_decimals: 2
    device_class: energy
    state_class: total_increasing
    filters:
      - multiply: 0.1
    value_type: U_DWORD_R  

  - platform: modbus_controller            # 108 Day PV Energy
    modbus_controller_id: sunsynk
    name: "${friendly_name} Day PV Energy"
    id: sunsynk_esphome_day_pv_energy
    register_type: holding
    address: 108
    unit_of_measurement: "kWh"
    accuracy_decimals: 1
    device_class: energy
    state_class: total_increasing
    filters:
      - multiply: 0.1
    value_type: U_WORD

############################################### TEMPERATURE ################################################

  - platform: modbus_controller            # 090 DC Transformer Temperature
    modbus_controller_id: sunsynk
    name: "${friendly_name} DC Transformer Temperature"
    id: sunsynk_esphome_dc_transformer_temperature
    register_type: holding
    address: 090
    unit_of_measurement: "°C"
    accuracy_decimals: 1
    device_class: temperature
    state_class: measurement
    value_type: S_WORD
    filters:
      - offset: -1000
      - multiply:  0.1

  - platform: modbus_controller            # 091 Radiator Temperature
    modbus_controller_id: sunsynk
    name: "${friendly_name} Radiator Temperature"
    id: sunsynk_esphome_radiator_temperature
    register_type: holding
    address: 091
    unit_of_measurement: "°C"
    accuracy_decimals: 1
    device_class: temperature
    state_class: measurement
    value_type: S_WORD
    filters:
      - offset: -1000
      - multiply:  0.1

################################################ READ SETTINGS #############################################

  - platform: modbus_controller          # 250 System Mode Time 1
    modbus_controller_id: sunsynk
    name: "${friendly_name} System Mode Time1"
    id: sunsynk_esphome_system_mode_time1
    register_type: holding
    skip_updates: ${settings_skipped_updates}
    address: 250
    icon: "mdi:clock"

  - platform: modbus_controller          # 251 System Mode Time 2
    modbus_controller_id: sunsynk
    name: "${friendly_name} System Mode Time2"
    id: sunsynk_esphome_system_mode_time2
    register_type: holding
    skip_updates: ${settings_skipped_updates}
    address: 251   
    icon: "mdi:clock"

  - platform: modbus_controller          # 252 System Mode Time 3
    modbus_controller_id: sunsynk
    name: "${friendly_name} System Mode Time3"
    id: sunsynk_esphome_system_mode_time3
    register_type: holding
    skip_updates: ${settings_skipped_updates}
    address: 252
    icon: "mdi:clock"

  - platform: modbus_controller          # 253 System Mode Time 4
    modbus_controller_id: sunsynk
    name: "${friendly_name} System Mode Time4"
    id: sunsynk_esphome_system_mode_time4
    register_type: holding
    skip_updates: ${settings_skipped_updates}
    address: 253
    icon: "mdi:clock"

  - platform: modbus_controller          # 254 System Mode Time 5
    modbus_controller_id: sunsynk
    name: "${friendly_name} System Mode Time5"
    id: sunsynk_esphome_system_mode_time5
    register_type: holding
    skip_updates: ${settings_skipped_updates}
    address: 254
    icon: "mdi:clock"

  - platform: modbus_controller          # 255 System Mode Time 6
    modbus_controller_id: sunsynk
    name: "${friendly_name} System Mode Time6"
    id: sunsynk_esphome_system_mode_time6
    register_type: holding
    skip_updates: ${settings_skipped_updates}
    address: 255
    icon: "mdi:clock"

  - platform: modbus_controller        # 255 Grid Peak Shaving raw register value
    modbus_controller_id: sunsynk
    id: grid_peak_shaving_raw
    register_type: holding
    address: 280
    value_type: U_WORD

################################################ WRITE SETTINGS ############################################

switch:
  - platform: modbus_controller          # 326 Toggle Force Generator
    use_write_multiple: true
    modbus_controller_id: sunsynk
    name: "${friendly_name} Toggle Force Generator"
    id: sunsynk_esphome_toggle_force_generator
    register_type: holding
    address: 326
    bitmask: 8192 # 2^13 to target bit 13
    icon: "mdi:toggle-switch"
    
  - platform: modbus_controller          # 247 Toggle Solar Sell
    use_write_multiple: true
    modbus_controller_id: sunsynk
    name: "${friendly_name} Toggle Solar sell"
    id: sunsynk_esphome_toggle_solar_sell
    register_type: holding
    address: 247
    bitmask: 1
    icon: "mdi:toggle-switch"

  - platform: modbus_controller          # 248 Toggle System Timer
    use_write_multiple: true
    modbus_controller_id: sunsynk
    name: "${friendly_name} Toggle System Timer" 
    id: sunsynk_esphome_toggle_Time_of_Use
    register_type: holding
    address: 248
    bitmask: 1
    icon: "mdi:toggle-switch"

  - platform: modbus_controller          # 243 Priority Load
    use_write_multiple: true
    modbus_controller_id: sunsynk
    name: "${friendly_name} Toggle Priority Load" 
    id: sunsynk_esphome_toggle_priority_load
    register_type: holding
    address: 243
    bitmask: 1
    icon: "mdi:toggle-switch"

  - platform: modbus_controller          # 274 System Mode Grid Charge Time 1
    use_write_multiple: true
    modbus_controller_id: sunsynk
    name: "${friendly_name} System Mode Grid Charge Time1"
    id: sunsynk_esphome_toggle_grid_charge_time1
    register_type: holding
    address: 274
    bitmask: 1
    icon: "mdi:toggle-switch"

  - platform: modbus_controller          # 275 System Mode Grid Charge Time 2
    modbus_controller_id: sunsynk
    use_write_multiple: true
    name: "${friendly_name} System Mode Grid Charge Time2"
    id: sunsynk_esphome_toggle_grid_charge_time2
    register_type: holding
    address: 275
    bitmask: 1
    icon: "mdi:toggle-switch"

  - platform: modbus_controller          # 276 System Mode Grid Charge Time 3
    modbus_controller_id: sunsynk
    use_write_multiple: true
    name: "${friendly_name} System Mode Grid Charge Time3"
    id: sunsynk_esphome_toggle_grid_charge_time3
    register_type: holding
    address: 276
    bitmask: 1
    icon: "mdi:toggle-switch"

  - platform: modbus_controller          # 277 System Mode Grid Charge Time 4
    modbus_controller_id: sunsynk
    use_write_multiple: true
    name: "${friendly_name} System Mode Grid Charge Time4"
    id: sunsynk_esphome_toggle_grid_charge_time4
    register_type: holding
    address: 277
    bitmask: 1
    icon: "mdi:toggle-switch"

  - platform: modbus_controller          # 278 System Mode Grid Charge Time 5
    modbus_controller_id: sunsynk
    use_write_multiple: true
    name: "${friendly_name} System Mode Grid Charge Time5"
    id: sunsynk_esphome_toggle_grid_charge_time5
    register_type: holding
    address: 278
    bitmask: 1
    icon: "mdi:toggle-switch"

  - platform: modbus_controller          # 279 System Mode Grid Charge Time 6
    modbus_controller_id: sunsynk
    use_write_multiple: true
    name: "${friendly_name} System Mode Grid Charge Time6"
    id: sunsynk_esphome_toggle_grid_charge_time6
    register_type: holding
    address: 279
    bitmask: 1
    icon: "mdi:toggle-switch"

number:
  - platform: modbus_controller         # 268 System Mode SoC Time 1
    use_write_multiple: true
    modbus_controller_id: sunsynk
    id: sunsynk_esphome_set_soc_time1
    name: "${friendly_name} System Mode SoC Time1"
    unit_of_measurement: "%"
    address: 268
    min_value: 0
    max_value: 100
    step: 5
    value_type: U_WORD  

  - platform: modbus_controller         # 269 System Mode SoC Time 2
    use_write_multiple: true
    modbus_controller_id: sunsynk
    id: sunsynk_esphome_set_soc_time2
    name: "${friendly_name} System Mode SoC Time2"
    unit_of_measurement: "%"
    address: 269
    min_value: 0
    max_value: 100
    step: 5
    value_type: U_WORD  

  - platform: modbus_controller         # 270 System Mode SoC Time 3
    use_write_multiple: true
    modbus_controller_id: sunsynk
    id: sunsynk_esphome_set_soc_time3
    name: "${friendly_name} System Mode SoC Time3"
    unit_of_measurement: "%"
    address: 270
    min_value: 0
    max_value: 100
    step: 5
    value_type: U_WORD  

  - platform: modbus_controller         # 271 System Mode SoC Time 4
    use_write_multiple: true
    modbus_controller_id: sunsynk
    id: sunsynk_esphome_set_soc_time4
    name: "${friendly_name} System Mode SoC Time4"
    unit_of_measurement: "%"
    address: 271
    min_value: 0
    max_value: 100
    step: 5
    value_type: U_WORD  

  - platform: modbus_controller         # 272 System Mode SoC Time 5
    use_write_multiple: true
    modbus_controller_id: sunsynk
    id: sunsynk_esphome_set_soc_time5
    name: "${friendly_name} System Mode SoC Time5"
    unit_of_measurement: "%"
    address: 272
    min_value: 0
    max_value: 100
    step: 5
    value_type: U_WORD  

  - platform: modbus_controller         # 273 System Mode SoC Time 6
    use_write_multiple: true
    modbus_controller_id: sunsynk
    id: sunsynk_esphome_set_soc_time6
    name: "${friendly_name} System Mode SoC Time6"
    unit_of_measurement: "%"
    address: 273
    min_value: 0
    max_value: 100
    step: 5
    value_type: U_WORD  

  - platform: modbus_controller         # 256 System Mode Power Time 1
    use_write_multiple: true
    modbus_controller_id: sunsynk
    id: sunsynk_esphome_set_power_time1
    name: "${friendly_name} System Mode Power Time1"
    unit_of_measurement: "W"
    address: 256
    min_value: 0
    max_value: 8000
    step: 100
    value_type: U_WORD  

  - platform: modbus_controller         # 257 System Mode Power Time 2
    use_write_multiple: true
    modbus_controller_id: sunsynk
    id: sunsynk_esphome_set_power_time2
    name: "${friendly_name} System Mode Power Time2"
    unit_of_measurement: "W"
    address: 257
    min_value: 0
    max_value: 8000
    step: 100
    value_type: U_WORD  

  - platform: modbus_controller         # 258 System Mode Power Time 3
    use_write_multiple: true
    modbus_controller_id: sunsynk
    id: sunsynk_esphome_set_power_time3
    name: "${friendly_name} System Mode Power Time3"
    unit_of_measurement: "W"
    address: 258
    min_value: 0
    max_value: 8000
    step: 100
    value_type: U_WORD  

  - platform: modbus_controller         # 259 System Mode Power Time 4
    use_write_multiple: true
    modbus_controller_id: sunsynk
    id: sunsynk_esphome_set_power_time4
    name: "${friendly_name} System Mode Power Time4"
    unit_of_measurement: "W"
    address: 259
    min_value: 0
    max_value: 8000
    step: 100
    value_type: U_WORD  

  - platform: modbus_controller         # 260 System Mode Power Time 5
    use_write_multiple: true
    modbus_controller_id: sunsynk
    id: sunsynk_esphome_set_power_time5
    name: "${friendly_name} System Mode Power Time5"
    unit_of_measurement: "W"
    address: 260
    min_value: 0
    max_value: 8000
    step: 100
    value_type: U_WORD  

  - platform: modbus_controller         # 261 System Mode Power Time 6
    use_write_multiple: true
    modbus_controller_id: sunsynk
    id: sunsynk_esphome_set_power_time6
    name: "${friendly_name} System Mode Power Time6"
    unit_of_measurement: "W"
    address: 261
    min_value: 0
    max_value: 8000
    step: 100
    value_type: U_WORD  

  - platform: modbus_controller         # 230 Grid Charge Battery current
    use_write_multiple: true
    modbus_controller_id: sunsynk
    id: sunsynk_esphome_grid_charge_bat_current
    name: "${friendly_name} Grid Charge Battery current"
    unit_of_measurement: "A"
    address: 230
    min_value: 0
    max_value: 185
    step: 5
    value_type: U_WORD  

  - platform: modbus_controller         # 210 Battery Max Charge current
    use_write_multiple: true
    modbus_controller_id: sunsynk
    id: sunsynk_esphome_bat_max_charge_current
    name: "${friendly_name} Battery Max Charge current"
    unit_of_measurement: "A"
    address: 210
    min_value: 0
    max_value: 185
    step: 5
    value_type: U_WORD  

  - platform: modbus_controller         # 211 Battery Max Discharge current
    use_write_multiple: true
    modbus_controller_id: sunsynk
    id: sunsynk_esphome_bat_max_discharge_current
    name: "${friendly_name} Battery Max Discharge current"
    unit_of_measurement: "A"
    address: 211
    min_value: 0
    max_value: 185
    step: 5
    value_type: U_WORD  

  - platform: modbus_controller            # 293 Grid Peak Shaving Power
    use_write_multiple: true
    modbus_controller_id: sunsynk
    name: "${friendly_name} Grid Peak shaving power"
    id: sunsynk_grid_peak_shaving_power
    address: 293
    unit_of_measurement: "W"
    min_value: 0
    max_value: 8000
    step: 500
    value_type: U_WORD

  - platform: modbus_controller            # 245 Max Sell Power
    use_write_multiple: true
    modbus_controller_id: sunsynk
    name: "${friendly_name} Max Sell power"
    id: sunsynk_max_sell_power
    address: 245
    unit_of_measurement: "W"
    min_value: 0
    max_value: 8000
    step: 500
    value_type: U_WORD


################################################ TEXT SENSORS ##################################################

text_sensor:
  - platform: modbus_controller            # 059 Overall State
    modbus_controller_id: sunsynk
    name: "${friendly_name} Overall State"
    id: sunsynk_esphome_overall_state
    register_type: holding
    skip_updates: ${settings_skipped_updates}
    raw_encode: HEXBYTES
    address: 59
    lambda: |- 
      uint16_t value = modbus_controller::word_from_hex_str(x, 0);
      switch (value) {
        case 0: return std::string("standby");
        case 1: return std::string("selftest");
        case 2: return std::string("normal");
        case 3: return std::string("alarm");
        case 4: return std::string("fault");
        default: return std::string("unknown");
      }

  - platform: template
    name: "${friendly_name} Time Slot 1"
    id: sunsynk_esphome_time_slot_1
    icon: "mdi:clock"
    lambda: |-
        int minutes, hours;
        if (id(sunsynk_esphome_system_mode_time1).state) {
        minutes = static_cast<int>(id(sunsynk_esphome_system_mode_time1).state) % 100;
        hours = static_cast<int>(id(sunsynk_esphome_system_mode_time1).state) / 100;
        } else {
          minutes = 0;
          hours = 0;
        }
        char formatted_time[6];
        snprintf(formatted_time, sizeof(formatted_time), "%02d:%02d", hours, minutes);
        return esphome::optional<std::string>(formatted_time);
  - platform: template
    name: "${friendly_name} Time Slot 2"
    id: sunsynk_esphome_time_slot_2
    icon: "mdi:clock"
    lambda: |-
        int minutes, hours;
        if (id(sunsynk_esphome_system_mode_time2).state) {
        minutes = static_cast<int>(id(sunsynk_esphome_system_mode_time2).state) % 100;
        hours = static_cast<int>(id(sunsynk_esphome_system_mode_time2).state) / 100;
        } else {
          minutes = 0;
          hours = 0;
        }
        char formatted_time[6];
        snprintf(formatted_time, sizeof(formatted_time), "%02d:%02d", hours, minutes);
        return esphome::optional<std::string>(formatted_time);
  - platform: template
    name: "${friendly_name} Time Slot 3"
    id: sunsynk_esphome_time_slot_3
    icon: "mdi:clock"
    lambda: |-
        int minutes, hours;
        if (id(sunsynk_esphome_system_mode_time3).state) {
        minutes = static_cast<int>(id(sunsynk_esphome_system_mode_time3).state) % 100;
        hours = static_cast<int>(id(sunsynk_esphome_system_mode_time3).state) / 100;
        } else {
          minutes = 0;
          hours = 0;
        }
        char formatted_time[6];
        snprintf(formatted_time, sizeof(formatted_time), "%02d:%02d", hours, minutes);
        return esphome::optional<std::string>(formatted_time);
  - platform: template
    name: "${friendly_name} Time Slot 4"
    id: sunsynk_esphome_time_slot_4
    icon: "mdi:clock"
    lambda: |-
        int minutes, hours;
        if (id(sunsynk_esphome_system_mode_time4).state) {
        minutes = static_cast<int>(id(sunsynk_esphome_system_mode_time4).state) % 100;
        hours = static_cast<int>(id(sunsynk_esphome_system_mode_time4).state) / 100;
        } else {
          minutes = 0;
          hours = 0;
        }
        char formatted_time[6];
        snprintf(formatted_time, sizeof(formatted_time), "%02d:%02d", hours, minutes);
        return esphome::optional<std::string>(formatted_time);
  - platform: template
    name: "${friendly_name} Time Slot 5"
    id: sunsynk_esphome_time_slot_5
    icon: "mdi:clock"
    lambda: |-
        int minutes, hours;
        if (id(sunsynk_esphome_system_mode_time5).state) {
        minutes = static_cast<int>(id(sunsynk_esphome_system_mode_time5).state) % 100;
        hours = static_cast<int>(id(sunsynk_esphome_system_mode_time5).state) / 100;
        } else {
          minutes = 0;
          hours = 0;
        }
        char formatted_time[6];
        snprintf(formatted_time, sizeof(formatted_time), "%02d:%02d", hours, minutes);
        return esphome::optional<std::string>(formatted_time);
  - platform: template
    name: "${friendly_name} Time Slot 6"
    id: sunsynk_esphome_time_slot_6
    icon: "mdi:clock"
    lambda: |-
        int minutes, hours;
        if (id(sunsynk_esphome_system_mode_time6).state) {
        minutes = static_cast<int>(id(sunsynk_esphome_system_mode_time6).state) % 100;
        hours = static_cast<int>(id(sunsynk_esphome_system_mode_time6).state) / 100;
        } else {
          minutes = 0;
          hours = 0;
        }
        char formatted_time[6];
        snprintf(formatted_time, sizeof(formatted_time), "%02d:%02d", hours, minutes);
        return esphome::optional<std::string>(formatted_time);


################################################ SELECT SENSORS ################################################

select:
  - platform: modbus_controller                   #243 Select Energy Patern
    use_write_multiple: true
    modbus_controller_id: sunsynk
    id: sunsynk_esphome_select_energy_pattern
    name: "${friendly_name} Energy Pattern"
    address: 243
    value_type: U_WORD
    optionsmap:
      "Battery first": 0
      "Load first": 1   
         
  - platform: modbus_controller                   #244 Select Work Mode
    use_write_multiple: true
    modbus_controller_id: sunsynk
    id: sunsynk_esphome_select_work_mode
    name: "${friendly_name} Work Mode"
    address: 244
    value_type: U_WORD
    optionsmap:
      "Selling First": 0
      "Zero Export + Limit to Load Only": 1
      "Limited to Home": 2    

  - platform: modbus_controller                  #280 Select Grid Peak Shaving
    use_write_multiple: true
    modbus_controller_id: sunsynk
    name: "${friendly_name} Grid Peak Shaving"
    id: sunsynk_esphome_select_grid_peak_shaving
    address: 280
    value_type: U_WORD
    optionsmap:
      "Disabled": 0
      "Enabled": 256
    lambda: |-
      // we are only interested in the 8th bit binary 0001 0000 0000 need to map the options 0, 256 in select 
      //ESP_LOGE("main","Modbus Number incoming value = %d",x);
      //ESP_LOGE("main","Modbus eval value = %d",(x & 0x0100));
      if ((x & 0x0100) == 0)
        return  std::string("Disabled");
      if ((x & 0x0100) == 256)
        return  std::string("Enabled");
      return {};
    write_lambda: |-
      //ESP_LOGE("main","Modbus write gets = %d",value);
      uint16_t unmodified =  id(grid_peak_shaving_raw).state;
      //ESP_LOGE("main","Modbus write unmodified = %d", unmodified);
      // optionsmap should only return 2 values... 0 , 256 so bitmask with complement 0x0100 to ensure we keep the original values in register. Then appply OR with the value that was chosen
      uint16_t modified = ((unmodified & ~0x0100) | value);
      //ESP_LOGE("main","Modbus write to write = %d", modified);
      return modified;

 

Guys eventually got my Esp32 & RS485 working again. The problem was the RS485 board not sure what happened to it.  Added a new board and all data started coming through.

Something things I learned.

1. Don't need two pairs of wires coming from the your RS45. Only need the orange ( goes to A on RS485 ) and the orange/white (goes to B on the RS485)

2. If you get this error  " 21:51:58][W][modbus_controller:136]: Duplicate modbus command found: type=0x3 address=150 count=1  "    I was told to increase your Modbus_controller update_interval. When I increased this the error went away.

3. I read that don't add power to the RS485 from the ESP32 only connect the ground and not the 5v.

Hope this all correct but it seems to be working fine now.

What I am concerned about is that I read that you should power the ESP32 Dev board with 3v and not 5v ?

I am using a phone charger and usb cable to power the ESp32 dev board, is this going to cause a problem ?

Thanks  

Well done @McGuywer, excellent. Also got min sorted today by adding a new RS485 board. For some reason the board got damaged even though the RED led lights up. 

I thought the problem was because of all the updates on Esphome and Dashboard updates.

So now I bought extra boards.

What do you power your ESP32 board with ?

  • Author

Hi @Vaughanza

Heinz from Smarthomeintegrations imports a very nice ESP32Shield that includes a power supply and 3.3V RS485/Canbus interface that he uses in his SmartHomeDongle. If you have an 8, 12 or 16kw Sunsynk/Deye inverter (not sure about the 5kw) you can then power the unit from the 12V power supply inside the inverter which is very neat. 

image.png.7bff772aa3be5d01baab49c4aa04ce8d.png

I did a review of the whole package on my Youtube channel and he did say that he would sell them without his firmware for the DIYers if someone wants. Is a very neat solution and gets rid of all of the soldering and most of the wiring issues that seem to plague people's ESP32 installs. 

 

On 2023/11/03 at 8:18 AM, Sc00bs said:

Hi @Vaughanza

Heinz from Smarthomeintegrations imports a very nice ESP32Shield that includes a power supply and 3.3V RS485/Canbus interface that he uses in his SmartHomeDongle. If you have an 8, 12 or 16kw Sunsynk/Deye inverter (not sure about the 5kw) you can then power the unit from the 12V power supply inside the inverter which is very neat. 

image.png.7bff772aa3be5d01baab49c4aa04ce8d.png

I did a review of the whole package on my Youtube channel and he did say that he would sell them without his firmware for the DIYers if someone wants. Is a very neat solution and gets rid of all of the soldering and most of the wiring issues that seem to plague people's ESP32 installs. 

 

Thanks @Sc00bs appreciate it. Was thinking that when I watched your video earlier. 

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.