Jump to content

BrettC

Members
  • Posts

    6
  • Joined

  • Last visited

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

BrettC's Achievements

  1. I've also found another approach that works. Instead of defining settings as "sensors", they can instead be defined as numbers (and probably also switches for binary sensors). Using the same code above, the setting's value updates when you change its value in home assistant. Here is the ESPHome yaml code for a number component. Once again I'm sure this can be neatened up. number: # 219 Setting Low Battery % - platform: modbus_controller modbus_controller_id: sunsynk name: "Low Batt Percent Setting" id: sunsynk_setting_low_batt register_type: holding address: 219 lambda: "return x * 1.0; " write_lambda: |- esphome::modbus_controller::ModbusController *controller = id(sunsynk); std::vector<uint16_t> lowbatt_data = {uint16_t((x))}; esphome::modbus_controller::ModbusCommandItem set_lowbatt_command = esphome::modbus_controller::ModbusCommandItem::create_write_multiple_command(controller, 0x00DB, 0x0001, lowbatt_data); controller->queue_command(set_lowbatt_command); return x;
  2. I have made some progress in writing settings values to the inverter. There are probably multiple ways to do this. For now, I've done this by creating an API service that can be called from Home Assistant. To start, the service gets defined in the esphome yaml. My example. api: services: - service: update_lowbatt variables: lowbatt_value: int then: - lambda: |- esphome::modbus_controller::ModbusController *controller = id(sunsynk); std::vector<uint16_t> lowbatt_data = {uint16_t((lowbatt_value))}; esphome::modbus_controller::ModbusCommandItem set_lowbatt_command = esphome::modbus_controller::ModbusCommandItem::create_write_multiple_command(controller, 0x00DB, 0x0001, lowbatt_data); controller->queue_command(set_lowbatt_command); This service updates the Low Battery % setting (register 219 or 0x00DB). The service is then called from home assistant. service: esphome.sunsynk_update_lowbatt data_template: lowbatt_value: "5" I use this setting to set the minimum SOC of the battery before it starts using grid power. Normally I keep this as something very low (e.g. 5%), unless I need to maintain a higher minimum battery level in anticipation of a loadshedding period. I'm going to write an automation that manages this Low Battery % setting based on load shedding status and upcoming low shedding periods. But that's a job for another day. I'm sure the code for this could be simplified by someone with more skill than me.
  3. Yes, the Esphome Modbus specs do say an ESP32 is preferred although an ESP8266 should work too. https://esphome.io/components/modbus_controller.html
  4. Here is a sample of the code if anyone else wants to try this approach. uart: id: mod_bus tx_pin: 17 rx_pin: 16 baud_rate: 9600 stop_bits: 1 modbus: id: modbus1 modbus_controller: - id: sunsynk address: 0x01 modbus_id: modbus1 setup_priority: -10 update_interval: 20000ms sensor: - platform: modbus_controller modbus_controller_id: sunsynk name: "Grid power" id: grid_power register_type: holding address: 169 unit_of_measurement: W device_class: power state_class: measurement
  5. I went ahead and managed to set this up with an ESP32 and a R30 RS485 to TTL board I ordered off Banggood. The Esphome code was surprisingly easy when I figured it out, and it was quite simple to set up the entities once I figured out how the Esphome modbus setup worked. I am just reading the sensors for now. I still need to working on write updates to the settings.
  6. Would it be possible to set this up using the remote appraoch with an ESP32 and TTL to RS485 module? Does Esphome perhaps have the code for the modbus TCP gateway? Or maybe there is code that can run on the ESP32 to achieve this.
×
×
  • Create New...