Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# Important Notice:
DO NOT USE RS485 ON THE BMS - PORT! This port only has a baudrate of 9600, which is too slow for regular updates.
Use the Modbus port.
Configure it to a baudrate (in the Advanced Menu) of 115200. This allows for updates every second.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't notice that we could reconfigure the Modbus Baudrate to 115200 ...

In that Case we can definitively increase the refresh Rate and avoid that the ESP32 crashes / gets stuck if refreshing too frequently.

On my Side I have them maybe disappearing from my Network for a Minute or Two each Day, but I thought that it was more related to the DHCP Server renewing IP Address rather than a ESP32 Crash / Reboot (and I still don't think it's that !).

Would that be in Page 2? I cannot see that Setting in the Advanced Menu in the Manual of the Deye Inverter.

image

image


# ESPhome for deye
ESPhome configuration for monitoring and control of Deye inverters in Home Assistant.
This include all addresses i could see relevant from the inverter.
Expand Down Expand Up @@ -70,6 +75,7 @@ pip install --upgrade esphome
```

## Hardware diagram

RX / TX between esp and ttl converter way have to be swapped. This seems to be a little different from espboard to espboard.
Check Termination: check that 120 Ohm are between B+ and B- (short wire); for long wire use 120 Ohms on both sides.
If it dosent communicate(RX/TX led both blinking) Try swap rx/tx on the esp.
Expand Down
36 changes: 36 additions & 0 deletions example/ct_ratio_automation.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
alias: Set CT Ratio Based on Netzanschluss Leistung
description: Adjust sun12k_general_ct_ratio based on netzanschluss_leistung
triggers:
- entity_id: sensor.netzanschluss_leistung
below: -8000
for: "00:00:10"
trigger: numeric_state
- entity_id: sensor.netzanschluss_leistung
above: -1000
for: "00:00:10"
trigger: numeric_state
- trigger: time_pattern
seconds: "30"
actions:
- choose:
- conditions:
- condition: numeric_state
entity_id: sensor.netzanschluss_leistung
below: -8000
sequence:
- target:
entity_id: number.sun12k_general_ct_ratio
data:
value: 1000
action: number.set_value
- conditions:
- condition: numeric_state
entity_id: sensor.netzanschluss_leistung
above: -1000
sequence:
- target:
entity_id: number.sun12k_general_ct_ratio
data:
value: 2000
action: number.set_value
mode: restart
87 changes: 87 additions & 0 deletions example/deye.yaml
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is where I am more concerned.

I originally structured the Repository in:

  • esphome-config-common.yaml
  • esphome-config-master.yaml
  • esphome-config-slave.yaml

Your example/deye.yaml is probably esphome-config-common.yaml merged within esphome-config-master.yaml but somewhat on a complementary Side (it's another Implementation for you who is Grid Connected, you also moved several Settings from separate Config Files into the "main" File).

Not sure how / if we should restructure everything to make it a bit more Consistent, since it's a bit of à La Carte Menu, where everybody can choose the different Components they would like. And obviously no 2 Configurations will ever be the same.

Any Tips ?

Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
substitutions:
name: deye #name in ESPhome
esp_name: deye
device_description: "Esphome component for Deye sun-12k-sg04lp3" #Description in ESPhome
modbus_controller_id: deye_modbus_controller #just a random name for the modbus controler - this is the high frequency controller for live values
device_type: sun12k #all entities in Home Assistant will start with this text to help identify the entitys
entities_id_prefix: SUN12K
entities_name_prefix: SUN12K
esphome:
name: ${name}

esp32:
board: wt32-eth01
framework:
type: esp-idf

# Enable logging
logger:
level: INFO
baud_rate: 0

# Enable Home Assistant API
ota:
platform: esphome
password: !secret ota_password

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

ethernet:
type: LAN8720
mdc_pin: GPIO23
mdio_pin: GPIO18
clk_mode: GPIO0_IN
phy_addr: 1
power_pin: GPIO16

time:
- platform: homeassistant

uart:
- id: uart_deye
tx_pin: GPIO17
rx_pin: GPIO05
baud_rate: 115200
stop_bits: 1
rx_buffer_size: 4096

modbus:
- id: modbus_deye
uart_id: uart_deye

modbus_controller:
- id: ${modbus_controller_id}
address: 0x1
modbus_id: modbus_deye
setup_priority: -10
update_interval: 1sec

packages:
# Different modules for the different sections of the inverter
solar: !include esphome-for-deye/modules/solar.yaml
battery: !include esphome-for-deye/modules/battery.yaml

load: !include esphome-for-deye/modules/load.yaml
generator: !include esphome-for-deye/modules/generator.yaml # Generator, Micro Inverter or Smart Load
general: !include esphome-for-deye/modules/general.yaml
status: !include esphome-for-deye/modules/status.yaml
internal: !include esphome-for-deye/modules/internal.yaml # Internal CTs Current/Power Measurement
inverter: !include esphome-for-deye/modules/inverter.yaml
ups: !include esphome-for-deye/modules/ups.yaml
out-of-grid: !include esphome-for-deye/modules/out-of-grid.yaml

#
# Enable for grid-connected systems
grid: !include esphome-for-deye/modules/grid.yaml
external: !include esphome-for-deye/modules/external.yaml # External CTs Current/Power Measurement


advanced: !include esphome-for-deye/modules/advanced_readwrite_select.yaml
# Time of Use for Grid-Connected Systems
time-of-use-common: !include esphome-for-deye/modules/time-of-use-common.yaml
# Only Include ONE of these (select OR number)
time-of-use-time-as-select: !include esphome-for-deye/modules/time-of-use-time-as-select.yaml
#time-of-use-time-as-number: !include modules/time-of-use-time-as-number.yaml
10 changes: 10 additions & 0 deletions example/template_sensor.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
template:
sensor:
- name: "Netzanschluss Leistung"
unit_of_measurement: "W"
state: >
{% set netz_deye = states('sensor.sun12k_external_ct_active_power_total') | float %}
{% set ratio = states('number.sun12k_general_ct_ratio') | float %}

{{ (netz_deye * 2000 / ratio) | round(1, default=0) }}
device_class: power
4 changes: 2 additions & 2 deletions modules/advanced_readwrite_select.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -416,13 +416,13 @@ select:
uint16_t select_value = uint16_t(value);

// Debug
esphome::ESP_LOGI("main","Modbus: Write - Advanced_BMS_Err_Stop set to %d" , select_value);
ESP_LOGI("main","Modbus: Write - Advanced_BMS_Err_Stop set to %d" , select_value);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this Change (just dropping the esphome Namespace ?) ? Were there some breaking Changes in some ESPHome Updates recently ?


// Current Value of the Register (all bits)
uint16_t current_value = id(${entities_id_prefix}_Advanced_Register_178).state;

// Debug
esphome::ESP_LOGI("main","Modbus: Write - Previous Register 178 Value (unmodified) = %d", current_value);
ESP_LOGI("main","Modbus: Write - Previous Register 178 Value (unmodified) = %d", current_value);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this Change (just dropping the esphome Namespace ?) ? Were there some breaking Changes in some ESPHome Updates recently ?


// Declare Variable
uint16_t write_value = 0;
Expand Down
42 changes: 27 additions & 15 deletions modules/battery.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,27 @@ select:
"Lead Acid": 0
"Lithium (BMS)": 1

# To be completed
#- platform: modbus_controller
# use_write_multiple: true
# modbus_controller_id: ${modbus_controller_id}
# id: "${entities_id_prefix}_Battery_Lithium_Type"
# name: "${entities_name_prefix}-Battery Lithium Type"
# address: 223
# bitmask: 0x1
# value_type: U_WORD
# optionsmap:
# "Pylon (CAN)": 0
# "": 1

- platform: modbus_controller
use_write_multiple: true
modbus_controller_id: ${modbus_controller_id}
id: "${entities_id_prefix}_Battery_Lithium_Type"
name: "${entities_name_prefix}-Battery Lithium Type"
address: 223
value_type: U_WORD
optionsmap:
"Pylon / Solax / Universal CAN Protocol (CAN)": 0x0000
"Tianbangda RS485 Modbus": 0x0001
"KOK Protocol": 0x0002
"Keith Protocol": 0x0003
"Topband Protocol": 0x0004
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get Tuopai Xie over Google Translate instaead of Topband. Unsure if anybody will use it but where did you get your Translation ?

"Pylontech 485 Protocol": 0x0005
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get Paineng 485 Assistant over Google Translate instead of Pylontech 485 Protocol. Can you explain a bit ? Thanks 😃

"Jelais 485 Protocol": 0x0006
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get Jerry's 485 Assistant over Google Translate instead of Jelais 485 Protocol. Can you explain a bit ? Thanks 😃

"Sunwoda 485 Protocol": 0x0007
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get Xinwangda 485 Xie over Google Translate instead of Xinruineng 485 Protocol. Can you explain a bit ? Thanks 😃

"Xinruineng 485 Protocol": 0x0008
"Tianbangda 485 Protocol": 0x0009
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get slightly different over Google Translate Tianbangda 485 Assistant instead of Tianbangda 485 Protocol.

"Shenggao Electric CAN Protocol": 0x000A


number:
- platform: modbus_controller
Expand Down Expand Up @@ -90,8 +99,8 @@ number:
modbus_controller_id: ${modbus_controller_id}
id: "${entities_id_prefix}_Battery_capacity"
name: "${entities_name_prefix}-Battery capacity"
address: 101
unit_of_measurement: V
address: 102
unit_of_measurement: Ah
value_type: U_WORD
multiply: 1.0
min_value: 0.00
Expand Down Expand Up @@ -133,6 +142,7 @@ sensor:
value_type: S_WORD
filters:
- multiply: 0.1

- platform: modbus_controller
modbus_controller_id: ${modbus_controller_id}
skip_updates: 10
Expand All @@ -147,6 +157,7 @@ sensor:
value_type: S_WORD
filters:
- multiply: 0.1

- platform: modbus_controller
modbus_controller_id: ${modbus_controller_id}
skip_updates: 5
Expand Down Expand Up @@ -185,7 +196,7 @@ sensor:
address: 586
unit_of_measurement: "°C"
accuracy_decimals: 1
value_type: U_WORD
value_type: S_WORD
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This kinda makes Sense, however the Reference Guide indicates [0,3000] Range with 0.1°C Resolution. Did you have a Chance to Test it yourself ? I don't have/use an external Temperature Sensor and only have a couple of Sensors in each Battery & BMS (no monitoring of the Battery Temperature by the Deye Inverter).

filters:
- offset: -1000
- multiply: 0.1
Expand Down Expand Up @@ -226,6 +237,7 @@ sensor:
accuracy_decimals: 0
value_type: S_WORD


- platform: modbus_controller
modbus_controller_id: ${modbus_controller_id}
name: "${entities_name_prefix}-Battery Output Current"
Expand Down
10 changes: 9 additions & 1 deletion modules/external.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ sensor:
accuracy_decimals: 0
value_type: S_WORD



- platform: modbus_controller
modbus_controller_id: ${modbus_controller_id}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you remove the High Refresh Rate Controller for this Signal ?

skip_updates: 2
Expand All @@ -23,6 +25,8 @@ sensor:
accuracy_decimals: 0
value_type: S_WORD



- platform: modbus_controller
modbus_controller_id: ${modbus_controller_id}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you remove the High Refresh Rate Controller for this Signal ?

skip_updates: 2
Expand All @@ -35,6 +39,8 @@ sensor:
accuracy_decimals: 0
value_type: S_WORD



- platform: modbus_controller
modbus_controller_id: ${modbus_controller_id}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you remove the High Refresh Rate Controller for this Signal ?

skip_updates: 2
Expand All @@ -47,6 +53,8 @@ sensor:
accuracy_decimals: 0
value_type: S_WORD



# External Power Grid - Total Apparent Power
- platform: modbus_controller
modbus_controller_id: ${modbus_controller_id}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you remove the High Refresh Rate Controller for this Signal ?

Expand All @@ -58,4 +66,4 @@ sensor:
unit_of_measurement: "VA"
state_class: "measurement"
accuracy_decimals: 0
value_type: S_WORD
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the Change ? Did you remove an empty NewLine ?

value_type: S_WORD
23 changes: 22 additions & 1 deletion modules/general.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,15 @@ binary_sensor:
bitmask: 0x1

sensor:
# New - To be Tested
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you remove all of these Sensors after you Added them a few Commit earlier ?

- platform: modbus_controller
modbus_controller_id: ${modbus_controller_id}
name: "${entities_name_prefix}-General - Grid check from Meter or CT"
id: "${entities_id_prefix}_General_Grid_Check_Source"
register_type: holding
address: 344
unit_of_measurement: ""
value_type: U_WORD
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't be easier to have an optionsmap here ?


- platform: modbus_controller
modbus_controller_id: ${modbus_controller_id}
name: "${entities_name_prefix}-General - DC Transformer Temperature"
Expand Down Expand Up @@ -138,3 +146,16 @@ select:
"Selling first": 0
"Zero export to load": 1
"Zero export to CT": 2


number:
- platform: modbus_controller
use_write_multiple: true
modbus_controller_id: ${modbus_controller_id}
id: "${entities_id_prefix}_General_CT_Ratio"
name: "${entities_name_prefix}-General - CT Ratio"
address: 347
value_type: U_WORD
multiply: 1.0
min_value: 100.00
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am Off-Grid so I don't know if this is Correct. Are you sure it's Correct ? According to the Reference Guide, they Provide an Example (?) Value of 30 for 30:1. Why is the min_value set to 100 here ? Isn't that a bit too high ?

max_value: 10000.00
22 changes: 16 additions & 6 deletions modules/generator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@ sensor:
unit_of_measurement: "W"
state_class: "measurement"
accuracy_decimals: 1
filters:
- multiply: 0.1
value_type: U_WORD
value_type: S_WORD
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did I get the Data Type wrong ? The Reference Guide didn't specify neither U16 nor S16 and I never tested the Generator, so it could very well be. Did you check your Results ?


- platform: modbus_controller
modbus_controller_id: ${modbus_controller_id}
Expand All @@ -60,7 +58,7 @@ sensor:
unit_of_measurement: "W"
state_class: "measurement"
accuracy_decimals: 1
value_type: U_WORD
value_type: S_WORD
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did I get the Data Type wrong ? The Reference Guide didn't specify neither U16 nor S16 and I never tested the Generator, so it could very well be. Did you check your Results ?


- platform: modbus_controller
modbus_controller_id: ${modbus_controller_id}
Expand All @@ -71,7 +69,7 @@ sensor:
unit_of_measurement: "W"
state_class: "measurement"
accuracy_decimals: 1
value_type: U_WORD
value_type: S_WORD
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did I get the Data Type wrong ? The Reference Guide didn't specify neither U16 nor S16 and I never tested the Generator, so it could very well be. Did you check your Results ?


- platform: modbus_controller
modbus_controller_id: ${modbus_controller_id}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you remove the High Refresh Rate Controller for this Signal ?

Expand All @@ -82,4 +80,16 @@ sensor:
unit_of_measurement: "W"
state_class: "measurement"
accuracy_decimals: 1
value_type: U_WORD
value_type: S_WORD
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you test and check your Results of this new Parameter ?


number:
- platform: modbus_controller
use_write_multiple: true
modbus_controller_id: ${modbus_controller_id}
id: "${entities_id_prefix}_Generator_Minimum_Solar_Power"
name: "${entities_name_prefix}-Generator Minimum Solar Power to Enable"
address: 139
unit_of_measurement: W
value_type: U_WORD
min_value: 0
max_value: 8000
Loading