syssi / esphome-smg-ii

ESPHome configuration to monitor and control a ISolar/EASUN SMG II inverter via RS232
Apache License 2.0
66 stars 12 forks source link

How to combine 3 YAMLs (2x SMG, 1x JK-BMS) to talk to 3 devices using one ESP32 #29

Closed amgstone closed 1 year ago

amgstone commented 1 year ago
substitutions:
  name: jk-bms
  device_description: "Monitor and control a JK-BMS via bluetooth"
  external_components_source: github://syssi/esphome-jk-bms@main
  mac_address: C8:47:8C:E8:FF:73
  # Defaults to "JK02"
  # Please use "JK02_32S" if you own a JK-B2A8S20P >= hardware version 11+ (f.e. JK-B2A8S20P hw 11.XW, sw 11.26)
  # Please use "JK04" if you have some old JK-BMS <= hardware version 3 (f.e. JK-B2A16S hw 3.0, sw. 3.3.0)
  protocol_version: JK02

esphome:
  name: ${name}
  comment: ${device_description}
  project:
    name: "syssi.esphome-jk-bms"
    version: 1.4.0

esp32:
  board: wemos_d1_mini32
  framework:
    type: esp-idf

external_components:
  - source: ${external_components_source}
    refresh: 0s

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

logger:
  level: DEBUG

api:
  encryption:
    key: "eqVtRZEcrMMZUMkO7GvrSCyCe//cZuQnIsvLbIJ2iZQ="

ota:
  password: "e1d447bf8bc832253849bbb3867e6e86"

time:
  - platform: sntp
    id: my_time

esp32_ble_tracker:
  on_ble_advertise:
    then:
      - lambda: |-
          if (x.get_name().rfind("JK-", 0) == 0) {
            ESP_LOGI("ble_adv", "New JK-BMS found");
            ESP_LOGI("ble_adv", "  Name: %s", x.get_name().c_str());
            ESP_LOGI("ble_adv", "  MAC address: %s", x.address_str().c_str());
            ESP_LOGD("ble_adv", "  Advertised service UUIDs:");
            for (auto uuid : x.get_service_uuids()) {
              ESP_LOGD("ble_adv", "    - %s", uuid.to_string().c_str());
            }
          }
ble_client:
  - mac_address: ${mac_address}
    id: client0

jk_bms_ble:
  - ble_client_id: client0
    protocol_version: ${protocol_version}
    throttle: 5s
    id: bms0

binary_sensor:
  - platform: jk_bms_ble
    balancing:
      name: "${name} balancing"
    charging:
      name: "${name} charging"
    discharging:
      name: "${name} discharging"
    online_status:
      name: "${name} online status"

button:
  - platform: jk_bms_ble
    retrieve_settings:
      name: "${name} retrieve settings"
    retrieve_device_info:
      name: "${name} retrieve device info"

number:
  - platform: jk_bms_ble
    jk_bms_ble_id: bms0
    balance_trigger_voltage:
      name: "${name} balance trigger voltage"
    cell_count:
      name: "${name} cell count"
    total_battery_capacity:
      name: "${name} total battery capacity"
    cell_voltage_overvoltage_protection:
      name: "${name} cell voltage overvoltage protection"
    cell_voltage_overvoltage_recovery:
      name: "${name} cell voltage overvoltage recovery"
    cell_voltage_undervoltage_protection:
      name: "${name} cell voltage undervoltage protection"
    cell_voltage_undervoltage_recovery:
      name: "${name} cell voltage undervoltage recovery"
    balance_starting_voltage:
      name: "${name} balance starting voltage"
    voltage_calibration:
      name: "${name} voltage calibration"
    current_calibration:
      name: "${name} current calibration"
    power_off_voltage:
      name: "${name} power off voltage"
    max_balance_current:
      name: "${name} max balance current"
    max_charge_current:
      name: "${name} max charge current"
    max_discharge_current:
      name: "${name} max discharge current"

sensor:
  - platform: jk_bms_ble
    jk_bms_ble_id: bms0
    min_cell_voltage:
      name: "${name} min cell voltage"
    max_cell_voltage:
      name: "${name} max cell voltage"
    min_voltage_cell:
      name: "${name} min voltage cell"
    max_voltage_cell:
      name: "${name} max voltage cell"
    delta_cell_voltage:
      name: "${name} delta cell voltage"
    average_cell_voltage:
      name: "${name} average cell voltage"
    cell_voltage_1:
      name: "${name} cell voltage 1"
    cell_voltage_2:
      name: "${name} cell voltage 2"
    cell_voltage_3:
      name: "${name} cell voltage 3"
    cell_voltage_4:
      name: "${name} cell voltage 4"
    cell_voltage_5:
      name: "${name} cell voltage 5"
    cell_voltage_6:
      name: "${name} cell voltage 6"
    cell_voltage_7:
      name: "${name} cell voltage 7"
    cell_voltage_8:
      name: "${name} cell voltage 8"
    cell_voltage_9:
      name: "${name} cell voltage 9"
    cell_voltage_10:
      name: "${name} cell voltage 10"
    cell_voltage_11:
      name: "${name} cell voltage 11"
    cell_voltage_12:
      name: "${name} cell voltage 12"
    cell_voltage_13:
      name: "${name} cell voltage 13"
    cell_voltage_14:
      name: "${name} cell voltage 14"
    cell_resistance_1:
      name: "${name} cell resistance 1"
    cell_resistance_2:
      name: "${name} cell resistance 2"
    cell_resistance_3:
      name: "${name} cell resistance 3"
    cell_resistance_4:
      name: "${name} cell resistance 4"
    cell_resistance_5:
      name: "${name} cell resistance 5"
    cell_resistance_6:
      name: "${name} cell resistance 6"
    cell_resistance_7:
      name: "${name} cell resistance 7"
    cell_resistance_8:
      name: "${name} cell resistance 8"
    cell_resistance_9:
      name: "${name} cell resistance 9"
    cell_resistance_10:
      name: "${name} cell resistance 10"
    cell_resistance_11:
      name: "${name} cell resistance 11"
    cell_resistance_12:
      name: "${name} cell resistance 12"
    cell_resistance_13:
      name: "${name} cell resistance 13"
    cell_resistance_14:
      name: "${name} cell resistance 14"
    total_voltage:
      name: "${name} total voltage"
    current:
      name: "${name} current"
    power:
      name: "${name} power"
    charging_power:
      name: "${name} charging power"
      id: bms0_charging_power
    discharging_power:
      name: "${name} discharging power"
      id: bms0_discharging_power
    temperature_sensor_1:
      name: "${name} temperature sensor 1"
    temperature_sensor_2:
      name: "${name} temperature sensor 2"
    power_tube_temperature:
      name: "${name} power tube temperature"
    state_of_charge:
      name: "${name} state of charge"
    capacity_remaining:
      name: "${name} capacity remaining"
    total_battery_capacity_setting:
      name: "${name} total battery capacity setting"
    charging_cycles:
      name: "${name} charging cycles"
    total_charging_cycle_capacity:
      name: "${name} total charging cycle capacity"
    total_runtime:
      name: "${name} total runtime"
    balancing_current:
      name: "${name} balancing current"
    errors_bitmask:
      name: "${name} errors bitmask"

  - platform: total_daily_energy
    name: "bms0 charging energy today"
    icon: mdi:counter
    power_id: bms0_charging_power
    accuracy_decimals: 3
    unit_of_measurement: kWh
    restore: true
    filters:
      - multiply: 0.001

  - platform: total_daily_energy
    name: "bms0 discharging energy today"
    icon: mdi:counter
    power_id: bms0_discharging_power
    accuracy_decimals: 3
    unit_of_measurement: kWh
    restore: true
    filters:
      - multiply: 0.001

switch:
  - platform: jk_bms_ble
    charging:
      name: "${name} charging"
    discharging:
      name: "${name} discharging"
    balancer:
      name: "${name} balancer"

  - platform: ble_client
    ble_client_id: client0
    name: "${name} enable bluetooth connection"

text_sensor:
  - platform: jk_bms_ble
    errors:
      name: "${name} errors"
    total_runtime_formatted:
      name: "${name} total runtime formatted"
amgstone commented 1 year ago
substitutions:
  name: smg-ii
  device_description: "Monitor and control a ISolar/EASUN SMG II inverter via RS232"
  tx_pin: GPIO16
  rx_pin: GPIO17

esphome:
  name: ${name}
  comment: ${device_description}
  project:
    name: "syssi.esphome-smg-ii"
    version: 1.0.0

esp32:
  board: wemos_d1_mini32
  framework:
    type: esp-idf

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

# Enable logging
logger:
  level: DEBUG

# Enable Home Assistant API
api:
  encryption:
    key: "4m2EggYGb4SL4AG4jGkp0YsyshrkdTKISvgIne14bu4="

ota:
  password: "725ac907d02728b8aca84711b3c4fecc"

uart:
  - id: uart_0
    baud_rate: 9600
    tx_pin: ${tx_pin}
    rx_pin: ${rx_pin}
    debug:
      direction: BOTH
      dummy_receiver: false

modbus:
  - id: modbus0
    send_wait_time: 200ms

modbus_controller:
  - id: smg0
    address: 0x01
    modbus_id: modbus0
    command_throttle: 200ms
    update_interval: 10s

time:
  - platform: sntp

sensor:
  - platform: total_daily_energy
    name: "${name} PV energy today"
    restore: true
    icon: mdi:counter
    power_id: smg0_pv_average_power
    filters:
      # Multiplication factor from W to kW is 0.001
      - multiply: 0.001
    unit_of_measurement: kWh

  # Fault code                                                    ULong 100 2 R
  - platform: modbus_controller
    modbus_controller_id: smg0
    name: "${name} fault code"
    address: 100
    register_type: holding
    value_type: U_DWORD
    accuracy_decimals: 0

  # Warning code                                                  ULong 108 2 R
  - platform: modbus_controller
    modbus_controller_id: smg0
    name: "${name} warning code"
    address: 108
    register_type: holding
    value_type: U_DWORD
    accuracy_decimals: 0

  # Operation Mode                                                UInt  201 1 R 0: Power On
  #                                                                             1: Standby
  #                                                                             2: Mains
  #                                                                             3: Off-Grid
  #                                                                             4: Bypass
  #                                                                             5: Charging
  #                                                                             6: Fault
  - platform: modbus_controller
    modbus_controller_id: smg0
    name: "${name} operation mode id"
    address: 201
    register_type: holding
    value_type: U_WORD
    accuracy_decimals: 0

  # Effective mains voltage                              0.1V     Int   202 1 R
  - platform: modbus_controller
    modbus_controller_id: smg0
    name: "${name} ac voltage"
    address: 202
    register_type: holding
    value_type: S_WORD
    unit_of_measurement: "V"
    device_class: voltage
    state_class: measurement
    accuracy_decimals: 1
    filters:
      - multiply: 0.1

  # Mains Frequency                                      0.01Hz   Int   203 1 R
  - platform: modbus_controller
    modbus_controller_id: smg0
    name: "${name} ac frequency"
    address: 203
    register_type: holding
    value_type: S_WORD
    unit_of_measurement: "Hz"
    device_class: frequency
    state_class: measurement
    accuracy_decimals: 2
    filters:
      - multiply: 0.01

  # Average mains power                                  1W       Int   204 1 R
  - platform: modbus_controller
    modbus_controller_id: smg0
    name: "${name} average mains power"
    address: 204
    register_type: holding
    value_type: S_WORD
    unit_of_measurement: "W"
    device_class: power
    state_class: measurement
    accuracy_decimals: 0

  # Effective inverter voltage                           0.1V     Int   205 1 R
  - platform: modbus_controller
    modbus_controller_id: smg0
    name: "${name} effective inverter voltage"
    address: 205
    register_type: holding
    value_type: S_WORD
    unit_of_measurement: "V"
    device_class: voltage
    state_class: measurement
    accuracy_decimals: 1
    filters:
      - multiply: 0.1

  # Effective inverter current                           0.1A     Int   206 1 R
  - platform: modbus_controller
    modbus_controller_id: smg0
    name: "${name} effective inverter current"
    address: 206
    register_type: holding
    value_type: S_WORD
    unit_of_measurement: "A"
    device_class: current
    state_class: measurement
    accuracy_decimals: 1
    filters:
      - multiply: 0.1

  # Inverter frequency                                   0.01Hz   Int   207 1 R
  - platform: modbus_controller
    modbus_controller_id: smg0
    name: "${name} inverter frequency"
    address: 207
    register_type: holding
    value_type: S_WORD
    unit_of_measurement: "Hz"
    device_class: frequency
    state_class: measurement
    accuracy_decimals: 2
    filters:
      - multiply: 0.01

  # Average inverter power                               1W       Int   208 1 R Positive numbers indicate inverter output, negative numbers indicate inverter input
  - platform: modbus_controller
    modbus_controller_id: smg0
    name: "${name} average inverter power"
    address: 208
    register_type: holding
    value_type: S_WORD
    unit_of_measurement: "W"
    device_class: power
    state_class: measurement
    accuracy_decimals: 0

  # Inverter charging power                              1W       Int   209 1 R
  - platform: modbus_controller
    modbus_controller_id: smg0
    name: "${name} inverter charging power"
    address: 209
    register_type: holding
    value_type: S_WORD
    unit_of_measurement: "W"
    device_class: power
    state_class: measurement
    accuracy_decimals: 0

  # Output effective voltage                             0.1V     Int   210 1 R
  - platform: modbus_controller
    modbus_controller_id: smg0
    name: "${name} output effective voltage"
    address: 210
    register_type: holding
    value_type: S_WORD
    unit_of_measurement: "V"
    device_class: voltage
    state_class: measurement
    accuracy_decimals: 1
    filters:
      - multiply: 0.1

  # Output effective Current                             0.1A     Int   211 1 R
  - platform: modbus_controller
    modbus_controller_id: smg0
    name: "${name} output effective Current"
    address: 211
    register_type: holding
    value_type: S_WORD
    unit_of_measurement: "A"
    device_class: current
    state_class: measurement
    accuracy_decimals: 1
    filters:
      - multiply: 0.1

  # Output frequency                                     0.01Hz   Int   212 1 R
  - platform: modbus_controller
    modbus_controller_id: smg0
    name: "${name} output frequency"
    address: 212
    register_type: holding
    value_type: S_WORD
    unit_of_measurement: "Hz"
    device_class: frequency
    state_class: measurement
    accuracy_decimals: 2
    filters:
      - multiply: 0.01

  # Output active power                                  1W       Int   213 1 R
  - platform: modbus_controller
    modbus_controller_id: smg0
    name: "${name} output active power"
    address: 213
    register_type: holding
    value_type: S_WORD
    unit_of_measurement: "W"
    device_class: power
    state_class: measurement
    accuracy_decimals: 0

  # Output apparent power                                1VA      Int   214 1 R
  - platform: modbus_controller
    modbus_controller_id: smg0
    name: "${name} output apparent power"
    address: 214
    register_type: holding
    value_type: S_WORD
    unit_of_measurement: "VA"
    device_class: apparent_power
    state_class: measurement
    accuracy_decimals: 0

  # Battery average voltage                              0.1V     Int   215 1 R
  - platform: modbus_controller
    modbus_controller_id: smg0
    name: "${name} battery average voltage"
    address: 215
    register_type: holding
    value_type: S_WORD
    unit_of_measurement: "V"
    device_class: voltage
    state_class: measurement
    accuracy_decimals: 1
    filters:
      - multiply: 0.1

  # Battery average Current                              0.1A     Int   216 1 R
  - platform: modbus_controller
    modbus_controller_id: smg0
    name: "${name} battery average Current"
    address: 216
    register_type: holding
    value_type: S_WORD
    unit_of_measurement: "A"
    device_class: current
    state_class: measurement
    accuracy_decimals: 1
    filters:
      - multiply: 0.1

  # Battery average power                                1W       Int   217 1 R
  - platform: modbus_controller
    modbus_controller_id: smg0
    name: "${name} battery average power"
    address: 217
    register_type: holding
    value_type: S_WORD
    unit_of_measurement: "W"
    device_class: power
    state_class: measurement
    accuracy_decimals: 0

  # PV average voltage                                   0.1V     Int   219 1 R
  - platform: modbus_controller
    modbus_controller_id: smg0
    name: "${name} pv average voltage"
    address: 219
    register_type: holding
    value_type: S_WORD
    unit_of_measurement: "V"
    device_class: voltage
    state_class: measurement
    accuracy_decimals: 1
    filters:
      - multiply: 0.1

  # PV average current                                   0.1A     Int   220 1 R
  - platform: modbus_controller
    modbus_controller_id: smg0
    name: "${name} pv average current"
    address: 220
    register_type: holding
    value_type: S_WORD
    unit_of_measurement: "A"
    device_class: current
    state_class: measurement
    accuracy_decimals: 1
    filters:
      - multiply: 0.1

  # PV average power                                     1W       Int   223 1 R
  - platform: modbus_controller
    modbus_controller_id: smg0
    id: smg0_pv_average_power
    name: "${name} pv average power"
    address: 223
    register_type: holding
    value_type: S_WORD
    unit_of_measurement: "W"
    device_class: power
    state_class: measurement
    accuracy_decimals: 0

  # PV charging average power                            1W       Int   224 1 R
  - platform: modbus_controller
    modbus_controller_id: smg0
    name: "${name} pv charging average power"
    address: 224
    register_type: holding
    value_type: S_WORD
    unit_of_measurement: "W"
    device_class: power
    state_class: measurement
    accuracy_decimals: 0

  # Load percentage                                      1%       Int   225 1 R
  - platform: modbus_controller
    modbus_controller_id: smg0
    name: "${name} load percentage"
    address: 225
    register_type: holding
    value_type: S_WORD
    unit_of_measurement: "%"
    # device_class: battery
    state_class: measurement
    accuracy_decimals: 0

  # DCDC Temperature                                     1°C      Int   226 1 R
  - platform: modbus_controller
    modbus_controller_id: smg0
    name: "${name} dcdc temperature"
    address: 226
    register_type: holding
    value_type: S_WORD
    unit_of_measurement: "°C"
    device_class: temperature
    state_class: measurement
    accuracy_decimals: 0

  # Inverter Temperature                                 1°C      Int   227 1 R
  - platform: modbus_controller
    modbus_controller_id: smg0
    name: "${name} inverter temperature"
    address: 227
    register_type: holding
    value_type: S_WORD
    unit_of_measurement: "°C"
    device_class: temperature
    state_class: measurement
    accuracy_decimals: 0

  # Battery state of charge                              1%       UInt  229 1 R
  - platform: modbus_controller
    modbus_controller_id: smg0
    name: "${name} battery state of charge"
    address: 229
    register_type: holding
    value_type: U_WORD
    unit_of_measurement: "%"
    device_class: battery
    state_class: measurement
    accuracy_decimals: 0

  # Battery average current                              0.1A     Int   232 1 R Positive number means charging, negative number means discharging
  - platform: modbus_controller
    modbus_controller_id: smg0
    name: "${name} battery average current"
    address: 232
    register_type: holding
    value_type: S_WORD
    unit_of_measurement: "A"
    device_class: current
    state_class: measurement
    accuracy_decimals: 1
    filters:
      - multiply: 0.1

  # Inverter charging average current                    0.1A     Int   233 1 R
  - platform: modbus_controller
    modbus_controller_id: smg0
    name: "${name} inverter charging average current"
    address: 233
    register_type: holding
    value_type: S_WORD
    unit_of_measurement: "A"
    device_class: current
    state_class: measurement
    accuracy_decimals: 1
    filters:
      - multiply: 0.1

  # PV charging average current                          0.1A     Int   234 1 R
  - platform: modbus_controller
    modbus_controller_id: smg0
    name: "${name} pv charging average current"
    address: 234
    register_type: holding
    value_type: S_WORD
    unit_of_measurement: "A"
    device_class: current
    state_class: measurement
    accuracy_decimals: 1
    filters:
      - multiply: 0.1

  # Output voltage                                        0.1V    Uint  320 1 R/W
  - platform: modbus_controller
    modbus_controller_id: smg0
    name: "${name} output voltage"
    address: 320
    register_type: holding
    value_type: U_WORD
    unit_of_measurement: "V"
    device_class: voltage
    # state_class: measurement
    accuracy_decimals: 1
    filters:
      - multiply: 0.1

  # Output frequency setting                              0.01Hz  Uint  321 1 R/W
  - platform: modbus_controller
    modbus_controller_id: smg0
    name: "${name} output frequency setting"
    address: 321
    register_type: holding
    value_type: U_WORD
    unit_of_measurement: "Hz"
    device_class: frequency
    # state_class: measurement
    accuracy_decimals: 2
    filters:
      - multiply: 0.01

  # Battery overvoltage protection point                  0.1V    Uint  323 1 R/W
  - platform: modbus_controller
    modbus_controller_id: smg0
    name: "${name} battery overvoltage protection point"
    address: 323
    register_type: holding
    value_type: U_WORD
    unit_of_measurement: "V"
    device_class: voltage
    # state_class: measurement
    accuracy_decimals: 1
    filters:
      - multiply: 0.1

  # Max charging voltage                                  0.1V    Uint  324 1 R/W
  - platform: modbus_controller
    modbus_controller_id: smg0
    name: "${name} max charging voltage"
    address: 324
    register_type: holding
    value_type: U_WORD
    unit_of_measurement: "V"
    device_class: voltage
    # state_class: measurement
    accuracy_decimals: 1
    filters:
      - multiply: 0.1

  # Floating charging voltage                             0.1V    Uint  325 1 R/W
  - platform: modbus_controller
    modbus_controller_id: smg0
    name: "${name} floating charging voltage"
    address: 325
    register_type: holding
    value_type: U_WORD
    unit_of_measurement: "V"
    device_class: voltage
    # state_class: measurement
    accuracy_decimals: 1
    filters:
      - multiply: 0.1

  # Battery discharge recovery point in mains mode        0.1V    Uint  326 1 R/W
  - platform: modbus_controller
    modbus_controller_id: smg0
    name: "${name} battery discharge recovery point in mains mode"
    address: 326
    register_type: holding
    value_type: U_WORD
    unit_of_measurement: "V"
    device_class: voltage
    # state_class: measurement
    accuracy_decimals: 1
    filters:
      - multiply: 0.1

  # Battery low voltage protection point in mains mode    0.1V    Uint  327 1 R/W
  - platform: modbus_controller
    modbus_controller_id: smg0
    name: "${name} battery low voltage protection point in mains mode"
    address: 327
    register_type: holding
    value_type: U_WORD
    unit_of_measurement: "V"
    device_class: voltage
    # state_class: measurement
    accuracy_decimals: 1
    filters:
      - multiply: 0.1

  # Battery low voltage protection point in off-grid mode 0.1V    Uint  329 1 R/W
  - platform: modbus_controller
    modbus_controller_id: smg0
    name: "${name} battery low voltage protection point in off-grid mode"
    address: 329
    register_type: holding
    value_type: U_WORD
    unit_of_measurement: "V"
    device_class: voltage
    # state_class: measurement
    accuracy_decimals: 1
    filters:
      - multiply: 0.1

  # Maximum charging current                              0.1A    Uint  332 1 R/W
  - platform: modbus_controller
    modbus_controller_id: smg0
    name: "${name} maximum charging current"
    address: 332
    register_type: holding
    value_type: U_WORD
    unit_of_measurement: "A"
    device_class: current
    # state_class: measurement
    accuracy_decimals: 1
    filters:
      - multiply: 0.1

  # Maximum mains charging current                        0.1A    Uint  333 1 R/W
  - platform: modbus_controller
    modbus_controller_id: smg0
    name: "${name} maximum mains charging current"
    address: 333
    register_type: holding
    value_type: U_WORD
    unit_of_measurement: "A"
    device_class: current
    # state_class: measurement
    accuracy_decimals: 1
    filters:
      - multiply: 0.1

  # Eq Charging voltage                                   0.1V    Uint  334 1 R/W
  - platform: modbus_controller
    modbus_controller_id: smg0
    name: "${name} Eq Charging voltage"
    address: 334
    register_type: holding
    value_type: U_WORD
    unit_of_measurement: "V"
    device_class: voltage
    # state_class: measurement
    accuracy_decimals: 1
    filters:
      - multiply: 0.1

  # Rated power                                           W       Uint  643 1 R
  - platform: modbus_controller
    modbus_controller_id: smg0
    name: "${name} rated power"
    address: 643
    register_type: holding
    value_type: U_WORD
    unit_of_measurement: "W"
    device_class: power
    # state_class: measurement
    accuracy_decimals: 0

select:
  # Output Mode                                                   Uint  300 1 R/W 0: Single, 1: Parallel, 2: 3 Phase-P1, 3: 3 Phase-P2, 4: 3 Phase-P3
  - platform: modbus_controller
    modbus_controller_id: smg0
    name: "${name} output mode"
    use_write_multiple: true
    address: 300
    value_type: U_WORD
    optionsmap:
      "Single": 0
      "Parallel": 1
      "Phase P1": 2
      "Phase P2": 3
      "Phase P3": 4

  # Output priority                                               Uint  301 1 R/W 0: Utility-PV-Battery, 1: PV-Utility-Battery, 2: PV-Battery-Utility
  - platform: modbus_controller
    modbus_controller_id: smg0
    name: "${name} output priority"
    use_write_multiple: true
    address: 301
    value_type: U_WORD
    optionsmap:
      "Utility-PV-Battery (UTI)": 0
      "PV-Utility-Battery (SOL)": 1
      "PV-Battery-Utility (SBU)": 2
      "PV-Utility-Battery (SUB)": 3

  # Input voltage range                                           Uint  302 1 R/W 0: Wide range, 1: Narrow range
  - platform: modbus_controller
    modbus_controller_id: smg0
    name: "${name} input voltage range"
    use_write_multiple: true
    address: 302
    value_type: U_WORD
    optionsmap:
      "Wide range": 0
      "Narrow range": 1

  # Buzzer mode                                                   Uint  303 1 R/W 0: Mute in all situations, 1: Sound when the input source is changed or there is a specific warning or fault, 2: Sound when there is aspecific warning or fault, 3: Sound when fault occurs
  - platform: modbus_controller
    modbus_controller_id: smg0
    name: "${name} buzzer mode"
    use_write_multiple: true
    address: 303
    value_type: U_WORD
    optionsmap:
      "Silent": 0
      "Beep on input source changes, warnings and faults": 1
      "Beep on warnings and faults": 2
      "Beep on faults": 3

  # LCD backlight                                                 Uint  305 1 R/W 0: Timed off, 1: Always on
  - platform: modbus_controller
    modbus_controller_id: smg0
    name: "${name} lcd backlight"
    use_write_multiple: true
    address: 305
    value_type: U_WORD
    optionsmap:
      "Timed off": 0
      "Always on": 1

  # Battery charging priority                                     Uint  331 1 R/W 0: Utility priority, 1: PV priority, 2: PV is at the same level as the Utility, 3: Only PV charging is allowed
  - platform: modbus_controller
    modbus_controller_id: smg0
    name: "${name} battery charging priority"
    use_write_multiple: true
    address: 331
    value_type: U_WORD
    optionsmap:
      "Utility priority": 0
      "PV priority": 1
      "PV is at the same level as the Utility": 2
      "Only PV charging is allowed": 3

  # Turn on mode                                                  Uint  406 1 R/W 0: Can be turn-on locally or remotely, 1: Only local turn-on, 2: Only remote turn-on
  - platform: modbus_controller
    modbus_controller_id: smg0
    name: "${name} turn on mode"
    use_write_multiple: true
    address: 406
    value_type: U_WORD
    optionsmap:
      "Local and remotely turn-on allowed": 0
      "Local turn-on only": 1
      "Remote turn-on only": 2

switch:
  # LCD automatically returns to the homepage                     Uint  306 1 R/W 0: Do not return automatically, 1: Automatically return after 1 minute
  - platform: modbus_controller
    modbus_controller_id: smg0
    name: "${name} lcd automatically returns to the homepage"
    use_write_multiple: true
    address: 306
    register_type: holding
    bitmask: 1

  # Energy-saving mode                                            Uint  307 1 R/W 0: Energy-saving mode is off, 1: Energy-saving mode is on
  - platform: modbus_controller
    modbus_controller_id: smg0
    name: "${name} energy-saving mode"
    use_write_multiple: true
    address: 307
    register_type: holding
    bitmask: 1

  # Overload automatic restart                                    Uint  308 1 R/W 0: Overload failure will not restart, 1: Automatic restart after overload failure
  - platform: modbus_controller
    modbus_controller_id: smg0
    name: "${name} overload automatic restart"
    use_write_multiple: true
    address: 308
    register_type: holding
    bitmask: 1

  # Over temperature automatic restart                            Uint  309 1 R/W 0: Over temperature failure will not restart, 1: Automatic restart after over-temperature fault
  - platform: modbus_controller
    modbus_controller_id: smg0
    name: "${name} over temperature automatic restart"
    use_write_multiple: true
    address: 309
    register_type: holding
    bitmask: 1

  # Overload transfer to bypass enabled                           Uint  310 1 R/W 0: Disable, 1: Enable
  - platform: modbus_controller
    modbus_controller_id: smg0
    name: "${name} overload transfer to bypass enabled"
    use_write_multiple: true
    address: 310
    register_type: holding
    bitmask: 1

  # Battery Eq mode is enabled                                    Uint  313 1 R/W 0: Disable, 1: Enable
  - platform: modbus_controller
    modbus_controller_id: smg0
    name: "${name} battery Eq mode is enabled"
    use_write_multiple: true
    address: 313
    register_type: holding
    bitmask: 1

  # Remote switch                                                 Uint  420 1 R/W 0: Remote shutdown, 1: Remote turn-on
  - platform: modbus_controller
    modbus_controller_id: smg0
    name: "${name} remote switch"
    use_write_multiple: true
    address: 420
    register_type: holding
    bitmask: 1

text_sensor:
  # Fault code                                                    ULong 100 2 R
  - platform: modbus_controller
    modbus_controller_id: smg0
    name: "${name} fault"
    address: 100
    register_type: holding
    register_count: 2
    response_size: 4
    raw_encode: HEXBYTES
    lambda: |-
      static const uint8_t FAULTS_SIZE = 27;
      static const char *const FAULTS[FAULTS_SIZE] = {
          "Over temperature of inverter module",                     // 0000 0000 0000 0000 0000 0000 0000 0001 (1)
          "Over temperature of DCDC module",                         // 0000 0000 0000 0000 0000 0000 0000 0010 (2)
          "Battery over voltage",                                    // 0000 0000 0000 0000 0000 0000 0000 0100 (3)
          "PV module over temperature",                              // 0000 0000 0000 0000 0000 0000 0000 1000 (4)
          "Output short circuit",                                    // 0000 0000 0000 0000 0000 0000 0001 0000 (5)
          "Inverter over voltage",                                   // 0000 0000 0000 0000 0000 0000 0010 0000 (6)
          "Output over load",                                        // 0000 0000 0000 0000 0000 0000 0100 0000 (7)
          "Bus over voltage",                                        // 0000 0000 0000 0000 0000 0000 1000 0000 (8)
          "Bus soft start timed out",                                // 0000 0000 0000 0000 0000 0001 0000 0000 (9)
          "PV over current",                                         // 0000 0000 0000 0000 0000 0010 0000 0000 (10)
          "PV over voltage",                                         // 0000 0000 0000 0000 0000 0100 0000 0000 (11)
          "Battery over current",                                    // 0000 0000 0000 0000 0000 1000 0000 0000 (12)
          "Inverter over current",                                   // 0000 0000 0000 0000 0001 0000 0000 0000 (13)
          "Bus low voltage",                                         // 0000 0000 0000 0000 0010 0000 0000 0000 (14)
          "Reserve (Bit 15)",                                        // 0000 0000 0000 0000 0100 0000 0000 0000 (15)
          "Inverter DC component is too high",                       // 0000 0000 0000 0000 1000 0000 0000 0000 (16)
          "Reserve (Bit 17)",                                        // 0000 0000 0000 0001 0000 0000 0000 0000 (17)
          "The zero bias of output current is too large",            // 0000 0000 0000 0010 0000 0000 0000 0000 (18)
          "The zero bias of inverter current is too large",          // 0000 0000 0000 0100 0000 0000 0000 0000 (19)
          "The zero bias of battery current is too large",           // 0000 0000 0000 1000 0000 0000 0000 0000 (20)
          "The zero bias of PV current is too large",                // 0000 0000 0001 0000 0000 0000 0000 0000 (21)
          "Inverter low voltage",                                    // 0000 0000 0010 0000 0000 0000 0000 0000 (22)
          "Inverter negative power protection",                      // 0000 0000 0100 0000 0000 0000 0000 0000 (23)
          "The host in the parallel system is lost",                 // 0000 0000 1000 0000 0000 0000 0000 0000 (24)
          "Synchronization signal abnormal in the parallel system",  // 0000 0001 0000 0000 0000 0000 0000 0000 (25)
          "The battery type is incompatible",                        // 0000 0010 0000 0000 0000 0000 0000 0000 (26)
          "Parallel versions are incompatible",                      // 0000 0100 0000 0000 0000 0000 0000 0000 (27)
      };
      std::string values = "";
      uint32_t mask = modbus_controller::dword_from_hex_str(x, 0);
      if (mask) {
        for (int i = 0; i < FAULTS_SIZE; i++) {
          if (mask & (1 << i)) {
            values.append(FAULTS[i]);
            values.append(";");
          }
        }
        if (!values.empty()) {
          values.pop_back();
        }
      }
      return values;
  # Warning code                                                  ULong 108 2 R
  - platform: modbus_controller
    modbus_controller_id: smg0
    name: "${name} fault"
    address: 100
    register_type: holding
    register_count: 2
    response_size: 4
    raw_encode: HEXBYTES
    lambda: |-
      static const uint8_t WARNINGS_SIZE = 19;
      static const char *const WARNINGS[WARNINGS_SIZE] = {
          "Reserve (Bit 0)",                                             // 0000 0000 0000 0000 0000 0000 0000 0001 (1)
          "Mains waveform abnormal",                                     // 0000 0000 0000 0000 0000 0000 0000 0010 (2)
          "Reserve (Bit 2)",                                             // 0000 0000 0000 0000 0000 0000 0000 0100 (3)
          "Mains low voltage",                                           // 0000 0000 0000 0000 0000 0000 0000 1000 (4)
          "Mains over frequency",                                        // 0000 0000 0000 0000 0000 0000 0001 0000 (5)
          "Mains low frequency",                                         // 0000 0000 0000 0000 0000 0000 0010 0000 (6)
          "PV low voltage",                                              // 0000 0000 0000 0000 0000 0000 0100 0000 (7)
          "Over temperature",                                            // 0000 0000 0000 0000 0000 0000 1000 0000 (8)
          "Battery low voltage",                                         // 0000 0000 0000 0000 0000 0001 0000 0000 (9)
          "Battery is not connected",                                    // 0000 0000 0000 0000 0000 0010 0000 0000 (10)
          "Overload",                                                    // 0000 0000 0000 0000 0000 0100 0000 0000 (11)
          "Battery Eq charging",                                         // 0000 0000 0000 0000 0000 1000 0000 0000 (12)
          "Battery undervoltage",                                        // 0000 0000 0000 0000 0001 0000 0000 0000 (13)
          "Output power derating",                                       // 0000 0000 0000 0000 0010 0000 0000 0000 (14)
          "Fan blocked",                                                 // 0000 0000 0000 0000 0100 0000 0000 0000 (15)
          "PV energy is too low to be use",                              // 0000 0000 0000 0000 1000 0000 0000 0000 (16)
          "Parallel communication interrupted",                          // 0000 0000 0000 0001 0000 0000 0000 0000 (17)
          "Output mode of Single and Parallel systems inconsistent",     // 0000 0000 0000 0010 0000 0000 0000 0000 (18)
          "Battery voltage difference of parallel system is too large",  // 0000 0000 0000 0100 0000 0000 0000 0000 (19)
      };
      std::string values = "";
      uint32_t mask = modbus_controller::dword_from_hex_str(x, 0);
      if (mask) {
        for (int i = 0; i < WARNINGS_SIZE; i++) {
          if (mask & (1 << i)) {
            values.append(WARNINGS[i]);
            values.append(";");
          }
        }
        if (!values.empty()) {
          values.pop_back();
        }
      }
      return values;
  # Operation Mode                                                UInt  201 1 R 0: Power On, 1: Standby, 2: Mains, 3: Off-Grid, 4: Bypass, 5: Charging, 6: Fault
  - platform: modbus_controller
    modbus_controller_id: smg0
    name: "${name} operation mode"
    address: 201
    register_type: holding
    raw_encode: HEXBYTES
    lambda: |-
      uint16_t value = modbus_controller::word_from_hex_str(x, 0);
      switch (value) {
        case 0: return std::string("Power On");
        case 1: return std::string("Standby");
        case 2: return std::string("Mains");
        case 3: return std::string("Off-Grid");
        case 4: return std::string("Bypass");
        case 5: return std::string("Charging");
        case 6: return std::string("Fault");
      }
      return std::string("Unknown");
number:
  # Battery equalization time                                     min     Uint  335 1 R/W Range: 0~900
  - platform: modbus_controller
    modbus_controller_id: smg0
    name: "${name} battery equalization time"
    use_write_multiple: true
    address: 335
    register_type: holding
    value_type: U_WORD
    min_value: 0.0
    max_value: 900.0
    step: 1
    unit_of_measurement: "min"

  # Equalization Timeout exit                                     min     Uint  336 1 R/W Range: 0~900
  - platform: modbus_controller
    modbus_controller_id: smg0
    name: "${name} equalization Timeout exit"
    use_write_multiple: true
    address: 336
    register_type: holding
    value_type: U_WORD
    min_value: 0.0
    max_value: 900.0
    step: 1
    unit_of_measurement: "min"

  # Two equalization charging intervals                           day     Uint  337 1 R/W Range: 1~90
  - platform: modbus_controller
    modbus_controller_id: smg0
    name: "${name} two equalization charging intervals"
    use_write_multiple: true
    address: 337
    register_type: holding
    value_type: U_WORD
    min_value: 0.0
    max_value: 90.0
    step: 1
    unit_of_measurement: "day"

# Button entities

  # Exit the fault mode                                           Uint  426   W   1: Exit the fault state(only when the inverter enters the fault mode , it could be available)
amgstone commented 1 year ago
substitutions:
  name: smg-ii-2
  device_description: "Monitor and control a ISolar/EASUN SMG II inverter via RS232"
  tx_pin: GPIO16
  rx_pin: GPIO17

esphome:
  name: ${name}
  comment: ${device_description}
  project:
    name: "syssi.esphome-smg-ii"
    version: 1.0.0

esp32:
  board: wemos_d1_mini32
  framework:
    type: esp-idf

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

# Enable logging
logger:
  level: DEBUG

# Enable Home Assistant API
api:
  encryption:
    key: "L/K1bF+fESSknTrppq6/13lvsAL6Y4++bkScdAQt0Rc="

ota:
  password: "08389f33fb1a436e1cd69e1d83215e92"

uart:
  - id: uart_0
    baud_rate: 9600
    tx_pin: ${tx_pin}
    rx_pin: ${rx_pin}
    debug:
      direction: BOTH
      dummy_receiver: false

modbus:
  - id: modbus0
    send_wait_time: 200ms

modbus_controller:
  - id: smg0
    address: 0x01
    modbus_id: modbus0
    command_throttle: 200ms
    update_interval: 10s

time:
  - platform: sntp

sensor:
  - platform: total_daily_energy
    name: "${name} PV energy today"
    restore: true
    icon: mdi:counter
    power_id: smg0_pv_average_power
    filters:
      # Multiplication factor from W to kW is 0.001
      - multiply: 0.001
    unit_of_measurement: kWh

  # Fault code                                                    ULong 100 2 R
  - platform: modbus_controller
    modbus_controller_id: smg0
    name: "${name} fault code"
    address: 100
    register_type: holding
    value_type: U_DWORD
    accuracy_decimals: 0

  # Warning code                                                  ULong 108 2 R
  - platform: modbus_controller
    modbus_controller_id: smg0
    name: "${name} warning code"
    address: 108
    register_type: holding
    value_type: U_DWORD
    accuracy_decimals: 0

  # Operation Mode                                                UInt  201 1 R 0: Power On
  #                                                                             1: Standby
  #                                                                             2: Mains
  #                                                                             3: Off-Grid
  #                                                                             4: Bypass
  #                                                                             5: Charging
  #                                                                             6: Fault
  - platform: modbus_controller
    modbus_controller_id: smg0
    name: "${name} operation mode id"
    address: 201
    register_type: holding
    value_type: U_WORD
    accuracy_decimals: 0

  # Effective mains voltage                              0.1V     Int   202 1 R
  - platform: modbus_controller
    modbus_controller_id: smg0
    name: "${name} ac voltage"
    address: 202
    register_type: holding
    value_type: S_WORD
    unit_of_measurement: "V"
    device_class: voltage
    state_class: measurement
    accuracy_decimals: 1
    filters:
      - multiply: 0.1

  # Mains Frequency                                      0.01Hz   Int   203 1 R
  - platform: modbus_controller
    modbus_controller_id: smg0
    name: "${name} ac frequency"
    address: 203
    register_type: holding
    value_type: S_WORD
    unit_of_measurement: "Hz"
    device_class: frequency
    state_class: measurement
    accuracy_decimals: 2
    filters:
      - multiply: 0.01

  # Average mains power                                  1W       Int   204 1 R
  - platform: modbus_controller
    modbus_controller_id: smg0
    name: "${name} average mains power"
    address: 204
    register_type: holding
    value_type: S_WORD
    unit_of_measurement: "W"
    device_class: power
    state_class: measurement
    accuracy_decimals: 0

  # Effective inverter voltage                           0.1V     Int   205 1 R
  - platform: modbus_controller
    modbus_controller_id: smg0
    name: "${name} effective inverter voltage"
    address: 205
    register_type: holding
    value_type: S_WORD
    unit_of_measurement: "V"
    device_class: voltage
    state_class: measurement
    accuracy_decimals: 1
    filters:
      - multiply: 0.1

  # Effective inverter current                           0.1A     Int   206 1 R
  - platform: modbus_controller
    modbus_controller_id: smg0
    name: "${name} effective inverter current"
    address: 206
    register_type: holding
    value_type: S_WORD
    unit_of_measurement: "A"
    device_class: current
    state_class: measurement
    accuracy_decimals: 1
    filters:
      - multiply: 0.1

  # Inverter frequency                                   0.01Hz   Int   207 1 R
  - platform: modbus_controller
    modbus_controller_id: smg0
    name: "${name} inverter frequency"
    address: 207
    register_type: holding
    value_type: S_WORD
    unit_of_measurement: "Hz"
    device_class: frequency
    state_class: measurement
    accuracy_decimals: 2
    filters:
      - multiply: 0.01

  # Average inverter power                               1W       Int   208 1 R Positive numbers indicate inverter output, negative numbers indicate inverter input
  - platform: modbus_controller
    modbus_controller_id: smg0
    name: "${name} average inverter power"
    address: 208
    register_type: holding
    value_type: S_WORD
    unit_of_measurement: "W"
    device_class: power
    state_class: measurement
    accuracy_decimals: 0

  # Inverter charging power                              1W       Int   209 1 R
  - platform: modbus_controller
    modbus_controller_id: smg0
    name: "${name} inverter charging power"
    address: 209
    register_type: holding
    value_type: S_WORD
    unit_of_measurement: "W"
    device_class: power
    state_class: measurement
    accuracy_decimals: 0

  # Output effective voltage                             0.1V     Int   210 1 R
  - platform: modbus_controller
    modbus_controller_id: smg0
    name: "${name} output effective voltage"
    address: 210
    register_type: holding
    value_type: S_WORD
    unit_of_measurement: "V"
    device_class: voltage
    state_class: measurement
    accuracy_decimals: 1
    filters:
      - multiply: 0.1

  # Output effective Current                             0.1A     Int   211 1 R
  - platform: modbus_controller
    modbus_controller_id: smg0
    name: "${name} output effective Current"
    address: 211
    register_type: holding
    value_type: S_WORD
    unit_of_measurement: "A"
    device_class: current
    state_class: measurement
    accuracy_decimals: 1
    filters:
      - multiply: 0.1

  # Output frequency                                     0.01Hz   Int   212 1 R
  - platform: modbus_controller
    modbus_controller_id: smg0
    name: "${name} output frequency"
    address: 212
    register_type: holding
    value_type: S_WORD
    unit_of_measurement: "Hz"
    device_class: frequency
    state_class: measurement
    accuracy_decimals: 2
    filters:
      - multiply: 0.01

  # Output active power                                  1W       Int   213 1 R
  - platform: modbus_controller
    modbus_controller_id: smg0
    name: "${name} output active power"
    address: 213
    register_type: holding
    value_type: S_WORD
    unit_of_measurement: "W"
    device_class: power
    state_class: measurement
    accuracy_decimals: 0

  # Output apparent power                                1VA      Int   214 1 R
  - platform: modbus_controller
    modbus_controller_id: smg0
    name: "${name} output apparent power"
    address: 214
    register_type: holding
    value_type: S_WORD
    unit_of_measurement: "VA"
    device_class: apparent_power
    state_class: measurement
    accuracy_decimals: 0

  # Battery average voltage                              0.1V     Int   215 1 R
  - platform: modbus_controller
    modbus_controller_id: smg0
    name: "${name} battery average voltage"
    address: 215
    register_type: holding
    value_type: S_WORD
    unit_of_measurement: "V"
    device_class: voltage
    state_class: measurement
    accuracy_decimals: 1
    filters:
      - multiply: 0.1

  # Battery average Current                              0.1A     Int   216 1 R
  - platform: modbus_controller
    modbus_controller_id: smg0
    name: "${name} battery average Current"
    address: 216
    register_type: holding
    value_type: S_WORD
    unit_of_measurement: "A"
    device_class: current
    state_class: measurement
    accuracy_decimals: 1
    filters:
      - multiply: 0.1

  # Battery average power                                1W       Int   217 1 R
  - platform: modbus_controller
    modbus_controller_id: smg0
    name: "${name} battery average power"
    address: 217
    register_type: holding
    value_type: S_WORD
    unit_of_measurement: "W"
    device_class: power
    state_class: measurement
    accuracy_decimals: 0

  # PV average voltage                                   0.1V     Int   219 1 R
  - platform: modbus_controller
    modbus_controller_id: smg0
    name: "${name} pv average voltage"
    address: 219
    register_type: holding
    value_type: S_WORD
    unit_of_measurement: "V"
    device_class: voltage
    state_class: measurement
    accuracy_decimals: 1
    filters:
      - multiply: 0.1

  # PV average current                                   0.1A     Int   220 1 R
  - platform: modbus_controller
    modbus_controller_id: smg0
    name: "${name} pv average current"
    address: 220
    register_type: holding
    value_type: S_WORD
    unit_of_measurement: "A"
    device_class: current
    state_class: measurement
    accuracy_decimals: 1
    filters:
      - multiply: 0.1

  # PV average power                                     1W       Int   223 1 R
  - platform: modbus_controller
    modbus_controller_id: smg0
    id: smg0_pv_average_power
    name: "${name} pv average power"
    address: 223
    register_type: holding
    value_type: S_WORD
    unit_of_measurement: "W"
    device_class: power
    state_class: measurement
    accuracy_decimals: 0

  # PV charging average power                            1W       Int   224 1 R
  - platform: modbus_controller
    modbus_controller_id: smg0
    name: "${name} pv charging average power"
    address: 224
    register_type: holding
    value_type: S_WORD
    unit_of_measurement: "W"
    device_class: power
    state_class: measurement
    accuracy_decimals: 0

  # Load percentage                                      1%       Int   225 1 R
  - platform: modbus_controller
    modbus_controller_id: smg0
    name: "${name} load percentage"
    address: 225
    register_type: holding
    value_type: S_WORD
    unit_of_measurement: "%"
    # device_class: battery
    state_class: measurement
    accuracy_decimals: 0

  # DCDC Temperature                                     1°C      Int   226 1 R
  - platform: modbus_controller
    modbus_controller_id: smg0
    name: "${name} dcdc temperature"
    address: 226
    register_type: holding
    value_type: S_WORD
    unit_of_measurement: "°C"
    device_class: temperature
    state_class: measurement
    accuracy_decimals: 0

  # Inverter Temperature                                 1°C      Int   227 1 R
  - platform: modbus_controller
    modbus_controller_id: smg0
    name: "${name} inverter temperature"
    address: 227
    register_type: holding
    value_type: S_WORD
    unit_of_measurement: "°C"
    device_class: temperature
    state_class: measurement
    accuracy_decimals: 0

  # Battery state of charge                              1%       UInt  229 1 R
  - platform: modbus_controller
    modbus_controller_id: smg0
    name: "${name} battery state of charge"
    address: 229
    register_type: holding
    value_type: U_WORD
    unit_of_measurement: "%"
    device_class: battery
    state_class: measurement
    accuracy_decimals: 0

  # Battery average current                              0.1A     Int   232 1 R Positive number means charging, negative number means discharging
  - platform: modbus_controller
    modbus_controller_id: smg0
    name: "${name} battery average current"
    address: 232
    register_type: holding
    value_type: S_WORD
    unit_of_measurement: "A"
    device_class: current
    state_class: measurement
    accuracy_decimals: 1
    filters:
      - multiply: 0.1

  # Inverter charging average current                    0.1A     Int   233 1 R
  - platform: modbus_controller
    modbus_controller_id: smg0
    name: "${name} inverter charging average current"
    address: 233
    register_type: holding
    value_type: S_WORD
    unit_of_measurement: "A"
    device_class: current
    state_class: measurement
    accuracy_decimals: 1
    filters:
      - multiply: 0.1

  # PV charging average current                          0.1A     Int   234 1 R
  - platform: modbus_controller
    modbus_controller_id: smg0
    name: "${name} pv charging average current"
    address: 234
    register_type: holding
    value_type: S_WORD
    unit_of_measurement: "A"
    device_class: current
    state_class: measurement
    accuracy_decimals: 1
    filters:
      - multiply: 0.1

  # Output voltage                                        0.1V    Uint  320 1 R/W
  - platform: modbus_controller
    modbus_controller_id: smg0
    name: "${name} output voltage"
    address: 320
    register_type: holding
    value_type: U_WORD
    unit_of_measurement: "V"
    device_class: voltage
    # state_class: measurement
    accuracy_decimals: 1
    filters:
      - multiply: 0.1

  # Output frequency setting                              0.01Hz  Uint  321 1 R/W
  - platform: modbus_controller
    modbus_controller_id: smg0
    name: "${name} output frequency setting"
    address: 321
    register_type: holding
    value_type: U_WORD
    unit_of_measurement: "Hz"
    device_class: frequency
    # state_class: measurement
    accuracy_decimals: 2
    filters:
      - multiply: 0.01

  # Battery overvoltage protection point                  0.1V    Uint  323 1 R/W
  - platform: modbus_controller
    modbus_controller_id: smg0
    name: "${name} battery overvoltage protection point"
    address: 323
    register_type: holding
    value_type: U_WORD
    unit_of_measurement: "V"
    device_class: voltage
    # state_class: measurement
    accuracy_decimals: 1
    filters:
      - multiply: 0.1

  # Max charging voltage                                  0.1V    Uint  324 1 R/W
  - platform: modbus_controller
    modbus_controller_id: smg0
    name: "${name} max charging voltage"
    address: 324
    register_type: holding
    value_type: U_WORD
    unit_of_measurement: "V"
    device_class: voltage
    # state_class: measurement
    accuracy_decimals: 1
    filters:
      - multiply: 0.1

  # Floating charging voltage                             0.1V    Uint  325 1 R/W
  - platform: modbus_controller
    modbus_controller_id: smg0
    name: "${name} floating charging voltage"
    address: 325
    register_type: holding
    value_type: U_WORD
    unit_of_measurement: "V"
    device_class: voltage
    # state_class: measurement
    accuracy_decimals: 1
    filters:
      - multiply: 0.1

  # Battery discharge recovery point in mains mode        0.1V    Uint  326 1 R/W
  - platform: modbus_controller
    modbus_controller_id: smg0
    name: "${name} battery discharge recovery point in mains mode"
    address: 326
    register_type: holding
    value_type: U_WORD
    unit_of_measurement: "V"
    device_class: voltage
    # state_class: measurement
    accuracy_decimals: 1
    filters:
      - multiply: 0.1

  # Battery low voltage protection point in mains mode    0.1V    Uint  327 1 R/W
  - platform: modbus_controller
    modbus_controller_id: smg0
    name: "${name} battery low voltage protection point in mains mode"
    address: 327
    register_type: holding
    value_type: U_WORD
    unit_of_measurement: "V"
    device_class: voltage
    # state_class: measurement
    accuracy_decimals: 1
    filters:
      - multiply: 0.1

  # Battery low voltage protection point in off-grid mode 0.1V    Uint  329 1 R/W
  - platform: modbus_controller
    modbus_controller_id: smg0
    name: "${name} battery low voltage protection point in off-grid mode"
    address: 329
    register_type: holding
    value_type: U_WORD
    unit_of_measurement: "V"
    device_class: voltage
    # state_class: measurement
    accuracy_decimals: 1
    filters:
      - multiply: 0.1

  # Maximum charging current                              0.1A    Uint  332 1 R/W
  - platform: modbus_controller
    modbus_controller_id: smg0
    name: "${name} maximum charging current"
    address: 332
    register_type: holding
    value_type: U_WORD
    unit_of_measurement: "A"
    device_class: current
    # state_class: measurement
    accuracy_decimals: 1
    filters:
      - multiply: 0.1

  # Maximum mains charging current                        0.1A    Uint  333 1 R/W
  - platform: modbus_controller
    modbus_controller_id: smg0
    name: "${name} maximum mains charging current"
    address: 333
    register_type: holding
    value_type: U_WORD
    unit_of_measurement: "A"
    device_class: current
    # state_class: measurement
    accuracy_decimals: 1
    filters:
      - multiply: 0.1

  # Eq Charging voltage                                   0.1V    Uint  334 1 R/W
  - platform: modbus_controller
    modbus_controller_id: smg0
    name: "${name} Eq Charging voltage"
    address: 334
    register_type: holding
    value_type: U_WORD
    unit_of_measurement: "V"
    device_class: voltage
    # state_class: measurement
    accuracy_decimals: 1
    filters:
      - multiply: 0.1

  # Rated power                                           W       Uint  643 1 R
  - platform: modbus_controller
    modbus_controller_id: smg0
    name: "${name} rated power"
    address: 643
    register_type: holding
    value_type: U_WORD
    unit_of_measurement: "W"
    device_class: power
    # state_class: measurement
    accuracy_decimals: 0

select:
  # Output Mode                                                   Uint  300 1 R/W 0: Single, 1: Parallel, 2: 3 Phase-P1, 3: 3 Phase-P2, 4: 3 Phase-P3
  - platform: modbus_controller
    modbus_controller_id: smg0
    name: "${name} output mode"
    use_write_multiple: true
    address: 300
    value_type: U_WORD
    optionsmap:
      "Single": 0
      "Parallel": 1
      "Phase P1": 2
      "Phase P2": 3
      "Phase P3": 4

  # Output priority                                               Uint  301 1 R/W 0: Utility-PV-Battery, 1: PV-Utility-Battery, 2: PV-Battery-Utility
  - platform: modbus_controller
    modbus_controller_id: smg0
    name: "${name} output priority"
    use_write_multiple: true
    address: 301
    value_type: U_WORD
    optionsmap:
      "Utility-PV-Battery (UTI)": 0
      "PV-Utility-Battery (SOL)": 1
      "PV-Battery-Utility (SBU)": 2
      "PV-Utility-Battery (SUB)": 3

  # Input voltage range                                           Uint  302 1 R/W 0: Wide range, 1: Narrow range
  - platform: modbus_controller
    modbus_controller_id: smg0
    name: "${name} input voltage range"
    use_write_multiple: true
    address: 302
    value_type: U_WORD
    optionsmap:
      "Wide range": 0
      "Narrow range": 1

  # Buzzer mode                                                   Uint  303 1 R/W 0: Mute in all situations, 1: Sound when the input source is changed or there is a specific warning or fault, 2: Sound when there is aspecific warning or fault, 3: Sound when fault occurs
  - platform: modbus_controller
    modbus_controller_id: smg0
    name: "${name} buzzer mode"
    use_write_multiple: true
    address: 303
    value_type: U_WORD
    optionsmap:
      "Silent": 0
      "Beep on input source changes, warnings and faults": 1
      "Beep on warnings and faults": 2
      "Beep on faults": 3

  # LCD backlight                                                 Uint  305 1 R/W 0: Timed off, 1: Always on
  - platform: modbus_controller
    modbus_controller_id: smg0
    name: "${name} lcd backlight"
    use_write_multiple: true
    address: 305
    value_type: U_WORD
    optionsmap:
      "Timed off": 0
      "Always on": 1

  # Battery charging priority                                     Uint  331 1 R/W 0: Utility priority, 1: PV priority, 2: PV is at the same level as the Utility, 3: Only PV charging is allowed
  - platform: modbus_controller
    modbus_controller_id: smg0
    name: "${name} battery charging priority"
    use_write_multiple: true
    address: 331
    value_type: U_WORD
    optionsmap:
      "Utility priority": 0
      "PV priority": 1
      "PV is at the same level as the Utility": 2
      "Only PV charging is allowed": 3

  # Turn on mode                                                  Uint  406 1 R/W 0: Can be turn-on locally or remotely, 1: Only local turn-on, 2: Only remote turn-on
  - platform: modbus_controller
    modbus_controller_id: smg0
    name: "${name} turn on mode"
    use_write_multiple: true
    address: 406
    value_type: U_WORD
    optionsmap:
      "Local and remotely turn-on allowed": 0
      "Local turn-on only": 1
      "Remote turn-on only": 2

switch:
  # LCD automatically returns to the homepage                     Uint  306 1 R/W 0: Do not return automatically, 1: Automatically return after 1 minute
  - platform: modbus_controller
    modbus_controller_id: smg0
    name: "${name} lcd automatically returns to the homepage"
    use_write_multiple: true
    address: 306
    register_type: holding
    bitmask: 1

  # Energy-saving mode                                            Uint  307 1 R/W 0: Energy-saving mode is off, 1: Energy-saving mode is on
  - platform: modbus_controller
    modbus_controller_id: smg0
    name: "${name} energy-saving mode"
    use_write_multiple: true
    address: 307
    register_type: holding
    bitmask: 1

  # Overload automatic restart                                    Uint  308 1 R/W 0: Overload failure will not restart, 1: Automatic restart after overload failure
  - platform: modbus_controller
    modbus_controller_id: smg0
    name: "${name} overload automatic restart"
    use_write_multiple: true
    address: 308
    register_type: holding
    bitmask: 1

  # Over temperature automatic restart                            Uint  309 1 R/W 0: Over temperature failure will not restart, 1: Automatic restart after over-temperature fault
  - platform: modbus_controller
    modbus_controller_id: smg0
    name: "${name} over temperature automatic restart"
    use_write_multiple: true
    address: 309
    register_type: holding
    bitmask: 1

  # Overload transfer to bypass enabled                           Uint  310 1 R/W 0: Disable, 1: Enable
  - platform: modbus_controller
    modbus_controller_id: smg0
    name: "${name} overload transfer to bypass enabled"
    use_write_multiple: true
    address: 310
    register_type: holding
    bitmask: 1

  # Battery Eq mode is enabled                                    Uint  313 1 R/W 0: Disable, 1: Enable
  - platform: modbus_controller
    modbus_controller_id: smg0
    name: "${name} battery Eq mode is enabled"
    use_write_multiple: true
    address: 313
    register_type: holding
    bitmask: 1

  # Remote switch                                                 Uint  420 1 R/W 0: Remote shutdown, 1: Remote turn-on
  - platform: modbus_controller
    modbus_controller_id: smg0
    name: "${name} remote switch"
    use_write_multiple: true
    address: 420
    register_type: holding
    bitmask: 1

text_sensor:
  # Fault code                                                    ULong 100 2 R
  - platform: modbus_controller
    modbus_controller_id: smg0
    name: "${name} fault"
    address: 100
    register_type: holding
    register_count: 2
    response_size: 4
    raw_encode: HEXBYTES
    lambda: |-
      static const uint8_t FAULTS_SIZE = 27;
      static const char *const FAULTS[FAULTS_SIZE] = {
          "Over temperature of inverter module",                     // 0000 0000 0000 0000 0000 0000 0000 0001 (1)
          "Over temperature of DCDC module",                         // 0000 0000 0000 0000 0000 0000 0000 0010 (2)
          "Battery over voltage",                                    // 0000 0000 0000 0000 0000 0000 0000 0100 (3)
          "PV module over temperature",                              // 0000 0000 0000 0000 0000 0000 0000 1000 (4)
          "Output short circuit",                                    // 0000 0000 0000 0000 0000 0000 0001 0000 (5)
          "Inverter over voltage",                                   // 0000 0000 0000 0000 0000 0000 0010 0000 (6)
          "Output over load",                                        // 0000 0000 0000 0000 0000 0000 0100 0000 (7)
          "Bus over voltage",                                        // 0000 0000 0000 0000 0000 0000 1000 0000 (8)
          "Bus soft start timed out",                                // 0000 0000 0000 0000 0000 0001 0000 0000 (9)
          "PV over current",                                         // 0000 0000 0000 0000 0000 0010 0000 0000 (10)
          "PV over voltage",                                         // 0000 0000 0000 0000 0000 0100 0000 0000 (11)
          "Battery over current",                                    // 0000 0000 0000 0000 0000 1000 0000 0000 (12)
          "Inverter over current",                                   // 0000 0000 0000 0000 0001 0000 0000 0000 (13)
          "Bus low voltage",                                         // 0000 0000 0000 0000 0010 0000 0000 0000 (14)
          "Reserve (Bit 15)",                                        // 0000 0000 0000 0000 0100 0000 0000 0000 (15)
          "Inverter DC component is too high",                       // 0000 0000 0000 0000 1000 0000 0000 0000 (16)
          "Reserve (Bit 17)",                                        // 0000 0000 0000 0001 0000 0000 0000 0000 (17)
          "The zero bias of output current is too large",            // 0000 0000 0000 0010 0000 0000 0000 0000 (18)
          "The zero bias of inverter current is too large",          // 0000 0000 0000 0100 0000 0000 0000 0000 (19)
          "The zero bias of battery current is too large",           // 0000 0000 0000 1000 0000 0000 0000 0000 (20)
          "The zero bias of PV current is too large",                // 0000 0000 0001 0000 0000 0000 0000 0000 (21)
          "Inverter low voltage",                                    // 0000 0000 0010 0000 0000 0000 0000 0000 (22)
          "Inverter negative power protection",                      // 0000 0000 0100 0000 0000 0000 0000 0000 (23)
          "The host in the parallel system is lost",                 // 0000 0000 1000 0000 0000 0000 0000 0000 (24)
          "Synchronization signal abnormal in the parallel system",  // 0000 0001 0000 0000 0000 0000 0000 0000 (25)
          "The battery type is incompatible",                        // 0000 0010 0000 0000 0000 0000 0000 0000 (26)
          "Parallel versions are incompatible",                      // 0000 0100 0000 0000 0000 0000 0000 0000 (27)
      };
      std::string values = "";
      uint32_t mask = modbus_controller::dword_from_hex_str(x, 0);
      if (mask) {
        for (int i = 0; i < FAULTS_SIZE; i++) {
          if (mask & (1 << i)) {
            values.append(FAULTS[i]);
            values.append(";");
          }
        }
        if (!values.empty()) {
          values.pop_back();
        }
      }
      return values;
  # Warning code                                                  ULong 108 2 R
  - platform: modbus_controller
    modbus_controller_id: smg0
    name: "${name} fault"
    address: 100
    register_type: holding
    register_count: 2
    response_size: 4
    raw_encode: HEXBYTES
    lambda: |-
      static const uint8_t WARNINGS_SIZE = 19;
      static const char *const WARNINGS[WARNINGS_SIZE] = {
          "Reserve (Bit 0)",                                             // 0000 0000 0000 0000 0000 0000 0000 0001 (1)
          "Mains waveform abnormal",                                     // 0000 0000 0000 0000 0000 0000 0000 0010 (2)
          "Reserve (Bit 2)",                                             // 0000 0000 0000 0000 0000 0000 0000 0100 (3)
          "Mains low voltage",                                           // 0000 0000 0000 0000 0000 0000 0000 1000 (4)
          "Mains over frequency",                                        // 0000 0000 0000 0000 0000 0000 0001 0000 (5)
          "Mains low frequency",                                         // 0000 0000 0000 0000 0000 0000 0010 0000 (6)
          "PV low voltage",                                              // 0000 0000 0000 0000 0000 0000 0100 0000 (7)
          "Over temperature",                                            // 0000 0000 0000 0000 0000 0000 1000 0000 (8)
          "Battery low voltage",                                         // 0000 0000 0000 0000 0000 0001 0000 0000 (9)
          "Battery is not connected",                                    // 0000 0000 0000 0000 0000 0010 0000 0000 (10)
          "Overload",                                                    // 0000 0000 0000 0000 0000 0100 0000 0000 (11)
          "Battery Eq charging",                                         // 0000 0000 0000 0000 0000 1000 0000 0000 (12)
          "Battery undervoltage",                                        // 0000 0000 0000 0000 0001 0000 0000 0000 (13)
          "Output power derating",                                       // 0000 0000 0000 0000 0010 0000 0000 0000 (14)
          "Fan blocked",                                                 // 0000 0000 0000 0000 0100 0000 0000 0000 (15)
          "PV energy is too low to be use",                              // 0000 0000 0000 0000 1000 0000 0000 0000 (16)
          "Parallel communication interrupted",                          // 0000 0000 0000 0001 0000 0000 0000 0000 (17)
          "Output mode of Single and Parallel systems inconsistent",     // 0000 0000 0000 0010 0000 0000 0000 0000 (18)
          "Battery voltage difference of parallel system is too large",  // 0000 0000 0000 0100 0000 0000 0000 0000 (19)
      };
      std::string values = "";
      uint32_t mask = modbus_controller::dword_from_hex_str(x, 0);
      if (mask) {
        for (int i = 0; i < WARNINGS_SIZE; i++) {
          if (mask & (1 << i)) {
            values.append(WARNINGS[i]);
            values.append(";");
          }
        }
        if (!values.empty()) {
          values.pop_back();
        }
      }
      return values;
  # Operation Mode                                                UInt  201 1 R 0: Power On, 1: Standby, 2: Mains, 3: Off-Grid, 4: Bypass, 5: Charging, 6: Fault
  - platform: modbus_controller
    modbus_controller_id: smg0
    name: "${name} operation mode"
    address: 201
    register_type: holding
    raw_encode: HEXBYTES
    lambda: |-
      uint16_t value = modbus_controller::word_from_hex_str(x, 0);
      switch (value) {
        case 0: return std::string("Power On");
        case 1: return std::string("Standby");
        case 2: return std::string("Mains");
        case 3: return std::string("Off-Grid");
        case 4: return std::string("Bypass");
        case 5: return std::string("Charging");
        case 6: return std::string("Fault");
      }
      return std::string("Unknown");
number:
  # Battery equalization time                                     min     Uint  335 1 R/W Range: 0~900
  - platform: modbus_controller
    modbus_controller_id: smg0
    name: "${name} battery equalization time"
    use_write_multiple: true
    address: 335
    register_type: holding
    value_type: U_WORD
    min_value: 0.0
    max_value: 900.0
    step: 1
    unit_of_measurement: "min"

  # Equalization Timeout exit                                     min     Uint  336 1 R/W Range: 0~900
  - platform: modbus_controller
    modbus_controller_id: smg0
    name: "${name} equalization Timeout exit"
    use_write_multiple: true
    address: 336
    register_type: holding
    value_type: U_WORD
    min_value: 0.0
    max_value: 900.0
    step: 1
    unit_of_measurement: "min"

  # Two equalization charging intervals                           day     Uint  337 1 R/W Range: 1~90
  - platform: modbus_controller
    modbus_controller_id: smg0
    name: "${name} two equalization charging intervals"
    use_write_multiple: true
    address: 337
    register_type: holding
    value_type: U_WORD
    min_value: 0.0
    max_value: 90.0
    step: 1
    unit_of_measurement: "day"

# Button entities

  # Exit the fault mode                                           Uint  426   W   1: Exit the fault state(only when the inverter enters the fault mode , it could be available)
syssi commented 1 year ago

Do you need help here? Is the second SMG on the same modbus (with different modbus addresses) or do you want to talk to the device using a second uart?

amgstone commented 1 year ago

I want to transfer from 3 esp to 1.

syssi commented 1 year ago

Are you able to change the modbus address of one of your inverters?

syssi commented 1 year ago

I've merged the three YAMLs into one. The modbuss address of the second inverter should be changed to 0x02. Please attach both inverter to the same modbus. It' possible the ESP32 cannot handle the large amount of entities. Please give it a try.

smg-smg-jk.yaml.txt

amgstone commented 1 year ago

doesn't work like that, you have to split into 2 rx and 2 tx

syssi commented 1 year ago

Please attach the second RS485 converter to GPIO32/GPIO33: smg-smg-jk-v2.yaml.txt

amgstone commented 1 year ago

works great, thank you very much!!!

amgstone commented 1 year ago

Screenshot_2023-06-26-08-48-29-051_io homeassistant companion android but for some reason often esp becomes unavailable

syssi commented 1 year ago

Please plug the ESP32 into a computer and record a log via a serial connection. You should see possible reboots or connection hiccup here.

In general: Doing BLE communication is a heavy task and doesn't harmonize with the WiFi connection. There are ESP32 boards available with an Ethernet module (WT32-ETH01). Avoiding WiFi would provide additional stability.

amgstone commented 1 year ago

Good day. You can make a configuration with two inverters, and then I will make bms on another esp.

amgstone commented 1 year ago

just once a day esp stops sending information from bms to HA, although smg continues to work. only reboot esp helps

syssi commented 1 year ago

smg-smg-v3.yaml.txt

amgstone commented 1 year ago

divided into 2 esp32, one on 2 doruga infertors for bms. Overloaded only where bms.