MODBUS help needed - Ampinvt solar controller to Home Assistant via ESPhome

Yeah, tried that…

ERROR Error while reading config: Invalid YAML syntax:

Duplicate key "name"
  in "/config/esphome/esp32_barn_controller.yaml", line 436, column 5:
        name: "Ampinvt Battery Status"
        ^
NOTE: Previous declaration here:
  in "/config/esphome/esp32_barn_controller.yaml", line 434, column 5:
        name: "Ampinvt Operating Status"
        ^

Seems the - is there to allow multiple name entries. If I put the - back I get a different error…

ERROR Error while reading config: Invalid YAML syntax:

while parsing a block mapping
  in "/config/esphome/esp32_barn_controller.yaml", line 433, column 5:
      - platform: template
        ^
expected <block end>, but found '-'
  in "/config/esphome/esp32_barn_controller.yaml", line 434, column 5:
        - name: "Ampinvt Operating Status"
        ^

Taking one name: entry is fine. Multiples fail. I wondered if I was using the wrong platform type but I can’t figure out which would be better.

  text_sensor:
    - platform: template
      name: "Ampinvt Operating Status"
      id: "ampinvt_op_status_text_sensor"
    - platform: template
      name: "Ampinvt Battery Status"
      id: "ampinvt_battery_status_text_sensor"

I managed to get the bit values sorted out and I now have regularly updating binary states for the sensors. Now I just need to get them into a human readable form.

As a quick recap, I converged the separate includes into one file again and I have checked the states under dev tools and watched the values change between 1 and 0.

Here is where the fun begins. Esphome wont validate the yaml code under ‘on_value’. I’ve tried numerous was to format the if function and the top one is currently a reflection of what is in the docs for on_value with lambda:

    - name: "Charging Status"
      id: "ampinvt_chg_status"
      icon: mdi:battery-charging
      internal:
      on_value:
        then:
          - if:
              condition:
                lambda: 'return id(ampinvt_chg_status).state < 1;'
              then:  
                - id(ampinvt_chg_status_text_sensor).publish_state("Not Charging");
              else: 
                - id(ampinvt_chg_status_text_sensor).publish_state("Charging");

    - name: "Equal Charging Status"
      id: "ampinvt_equalchg_status"
      # internal:
      # on_value:
      #   then:
      #     - lambda: |-
      #         if(x==0) {
      #           id(ampinvt_equalchg_status_text_sensor).publish_state("Not Equalising");
      #         }
      #         else  {
      #           id(ampinvt_equalchg_status_text_sensor).publish_state("Equalising");
      #         }
    - name: "MPPT Tracking Status"
      id: "ampinvt_track_status"
      internal:
      on_value:
        then:
          - lambda: |-
              if(x == 0) {
                id(ampinvt_track_status_text_sensor).publish_state("Not Tracking");
              }
              else  {
                id(ampinvt_track_status_text_sensor).publish_state("Tracking");
              }
    - name: "Float Charging Status"
      id: "ampinvt_floatchg_status"
      internal:
        on_value:
        then:
          - lambda: |-
              if(x==0) {
                id(ampinvt_floatchg_status_text_sensor).publish_state("Not Float Charging");
              }
              else  {
                id(ampinvt_floatchg_status_text_sensor).publish_state("Float Charging");
              }

The error that keeps coming up is the top one regarding boolean value:

      Expected boolean value, but cannot convert None to a boolean. Please use 'true' or 'false'.
      internal: 
      on_value: 
        then: 
          - lambda: |-
              if(x == 0) {
                id(ampinvt_track_status_text_sensor).publish_state("Not Tracking");
              }
              else  {
                id(ampinvt_track_status_text_sensor).publish_state("Tracking");
              }

I wondered if the issue was coming over from the include file so I tried changing the (bool) function to (int) but that didn’t change anything:

        uint8_t chg_status_byte = (uint8_t)(bytes[4]);
        #define BIT_CHARGING_STATUS        0x1  // 00000001
        #define BIT_EQUALCHG_STATUS        0x2  // 00000010
        #define BIT_TRACK_STATUS           0x4  // 00000100
        #define BIT_FLOATCHG_STATUS        0x8  // 00001000
        #define BIT_CHGCURRENTLIMIT_STATUS 0x10 // 00010000
        #define BIT_CHGDERATING_STATUS     0x20 // 00100000
        #define BIT_REMOTEPROHIBCHG_STATUS 0x40 // 01000000
        #define BIT_PVOVERVOLT_STATUS      0x80 // 10000000
        id(ampinvt_chg_status).publish_state((int)(chg_status_byte & BIT_CHARGING_STATUS));
        id(ampinvt_equalchg_status).publish_state((bool)(chg_status_byte & BIT_EQUALCHG_STATUS));
        id(ampinvt_track_status).publish_state((int)(chg_status_byte & BIT_TRACK_STATUS));
        id(ampinvt_floatchg_status).publish_state((int)(chg_status_byte & BIT_FLOATCHG_STATUS));
        id(ampinvt_chgcurrentlimit_status).publish_state((bool)(chg_status_byte & BIT_CHGCURRENTLIMIT_STATUS));
        id(ampinvt_chgderating_status).publish_state((bool)(chg_status_byte & BIT_CHGDERATING_STATUS));
        id(ampinvt_remoteprohibchg_status).publish_state((bool)(chg_status_byte & BIT_REMOTEPROHIBCHG_STATUS));
        id(ampinvt_pvovervolt_status).publish_state((bool)(chg_status_byte & BIT_PVOVERVOLT_STATUS));   

Any thoughts? It seems esphome is expecting ‘true’ or ‘false’ but what is coming in from the include is 1 and 0. I figure that because esphome doesn’t recognise 1 or 0 it is ignoring the value to achieve ‘none’.

LOL! Not sure what I did to fix it but its working now!

Edit:
It is the internal: on the custom sensors that sets off the error for boolean. If I disable the internal: setting then it works. I found it by accident it seems, when I inadvertantly selected that while block-disabling code.

Perhaps try this:

              if(x) {
                id(ampinvt_track_status_text_sensor).publish_state("Not Tracking");
              }
              else  {
                id(ampinvt_track_status_text_sensor).publish_state("Tracking");
              }

@assembly - see edit above.

Ah. I see now. Internal should be either true or false. In your example it has no value.

Yes, that was it. Just tidying everything up then I need to figure out how to publish something on Github. I’m sure there is a Youtube video for that somewhere.

1 Like

The project is now up on Github here. I have gained much from others over the years and it feels pretty damn good to give back. I’ve learned a lot through this project and once again, I am grateful to those that helped so much. It’s my first repo on Github too!

When I get a moment, I’ll use what I learned to create a similar solution for the Renogy Rover controller as I have one sat here.

All done I guess - Great work :muscle::sunglasses:

hello i am trying to implement the project as well. currently my configuration looks like this. Is this correct because the wifi settings should not run manually but automatically via DHCP. This is how the configuration looks like:

esphome:

    name: "laderegler"

    comment: "mppt auslesen"

    includes:

      - ampinvt.h

 

  esp32:

    board: esp32dev

    framework:

      version: recommended

      type: arduino

 

  logger:

    level: DEBUG

 

  wifi:

    ap:

      ssid: "Fallback_SolarMonitor"

      password: "xxxxxxxx"

      ap_timeout: 1min

    domain: .local

    reboot_timeout: 15min

    power_save_mode: NONE

    fast_connect: false

    output_power: 20.0

    networks:

    - ssid: xxxxxxxxxx

      password: xxxxxxxx

      priority: 0.0

 

  captive_portal:

   

  uart:

    id: uart_bus

    tx_pin: 1 # Yellow Wire - MPPT UART Transmit

    rx_pin: 3 # Green Wire - MPPT UART Receive

    rx_buffer_size: 2048

    baud_rate: 9600

    parity: NONE

    stop_bits: 1

    debug:

 

  time:

    - platform: homeassistant

      id: esptime

      on_time:

        - seconds: 0,30

          then:

            - uart.write: [ 0x01, 0xB3, 0x01, 0x00, 0x00, 0x00, 0x00, 0xB5 ] # Reads only real-time data

  #          - uart.write: [ 0x01, 0xB2, 0x01, 0x00, 0x00, 0x00, 0x00, 0xB4 ] # Reads only parameter settings

 

  sensor:

  - platform: custom

    lambda: |-

      auto ampinvtsensors = new ampinvtsensor(id(uart_bus));

      App.register_component(ampinvtsensors);

      return {\

      ampinvtsensors->ampinvt_op_status, \

      ampinvtsensors->ampinvt_battery_status, \

      ampinvtsensors->ampinvt_fan_status, \

      ampinvtsensors->ampinvt_overheat_status, \

      ampinvtsensors->ampinvt_dcoutput_status, \

      ampinvtsensors->ampinvt_inttemp1_status, \

      ampinvtsensors->ampinvt_inttemp2_status, \

      ampinvtsensors->ampinvt_exttemp_status, \

      ampinvtsensors->ampinvt_chg_status, \

      ampinvtsensors->ampinvt_equalchg_status, \

      ampinvtsensors->ampinvt_track_status, \

      ampinvtsensors->ampinvt_floatchg_status, \

      ampinvtsensors->ampinvt_chgcurrentlimit_status, \

      ampinvtsensors->ampinvt_chgderating_status, \

      ampinvtsensors->ampinvt_remoteprohibchg_status, \

      ampinvtsensors->ampinvt_pvovervolt_status, \

      ampinvtsensors->ampinvt_chgoutputrelay_status, \

      ampinvtsensors->ampinvt_loadoutput_status, \

      ampinvtsensors->ampinvt_fanrelay_status, \

      ampinvtsensors->ampinvt_overchgprotect_status, \

      ampinvtsensors->ampinvt_overvoltprotect_status, \

      ampinvtsensors->ampinvt_pv_voltage, \

      ampinvtsensors->ampinvt_battery_voltage, \

      ampinvtsensors->ampinvt_charge_current, \

      ampinvtsensors->ampinvt_mppt_temperature, \

      ampinvtsensors->ampinvt_battery_temperature, \

      ampinvtsensors->ampinvt_today_yield, \

      ampinvtsensors->ampinvt_generation_total, \

      };

    sensors:

    - name: "Operating Status"

      id: ampinvt_op_status

      on_value:

        then:

          - lambda: |-

              if(x==0) {

                id(ampinvt_op_status_text_sensor).publish_state("Normal");

              }

              else  {

                id(ampinvt_op_status_text_sensor).publish_state("Abnormal");

              }

    - name: "Battery Status"

      id: ampinvt_battery_status

      on_value:

        then:

          - lambda: |-

              if(x==0) {

                id(ampinvt_battery_status_text_sensor).publish_state("Normal");

              }

              else  {

                id(ampinvt_battery_status_text_sensor).publish_state("OD Protection On");

              }

    - name: "Fan Status"

      id: ampinvt_fan_status

      on_value:

        then:

          - lambda: |-

              if(x==0) {

                id(ampinvt_fan_status_text_sensor).publish_state("Normal");

              }

              else  {

                id(ampinvt_fan_status_text_sensor).publish_state("Fan Failure");

              }

    - name: "Overheat Status"

      id: ampinvt_overheat_status

      on_value:

        then:

          - lambda: |-

              if(x==0) {

                id(ampinvt_overheat_status_text_sensor).publish_state("Normal");

              }

              else  {

                id(ampinvt_overheat_status_text_sensor).publish_state("OT Protection On");

              }

    - name: "DC Output Status"

      id: ampinvt_dcoutput_status

      on_value:

        then:

          - lambda: |-

              if(x==0) {

                id(ampinvt_dcoutput_status_text_sensor).publish_state("Normal");

              }

              else  {

                id(ampinvt_dcoutput_status_text_sensor).publish_state("DC Output Short");

              }

    - name: "Internal Temperature 1 Status"

      id: ampinvt_inttemp1_status

      on_value:

        then:

          - lambda: |-

              if(x==0) {

                id(ampinvt_inttemp1_status_text_sensor).publish_state("Normal");

              }

              else  {

                id(ampinvt_inttemp1_status_text_sensor).publish_state("Fault");

              }

    - name: "Internal Temperature 2 Status"

      id: ampinvt_inttemp2_status

      on_value:

        then:

          - lambda: |-

              if(x==0) {

                id(ampinvt_inttemp2_status_text_sensor).publish_state("Normal");

              }

              else  {

                id(ampinvt_inttemp2_status_text_sensor).publish_state("Fault");

              }

    - name: "External Temperature Status"

      id: ampinvt_exttemp_status

      on_value:

        then:

          - lambda: |-

              if(x==0) {

                id(ampinvt_exttemp_status_text_sensor).publish_state("Normal");

              }

              else  {

                id(ampinvt_exttemp_status_text_sensor).publish_state("Fault");

              }

    - name: "Charging Status"

      id: ampinvt_chg_status

      icon: mdi:battery-charging

      on_value:

        then:

          - lambda: |-

              if(x==0) {

                id(ampinvt_chg_status_text_sensor).publish_state("Not Charging");

              }

              else  {

                id(ampinvt_chg_status_text_sensor).publish_state("Charging");

              }

    - name: "Equal Charging Status"

      id: ampinvt_equalchg_status

      on_value:

        then:

          - lambda: |-

              if(x==0) {

                id(ampinvt_equalchg_status_text_sensor).publish_state("Not Equalising");

              }

              else  {

                id(ampinvt_equalchg_status_text_sensor).publish_state("Equalising");

              }

    - name: "MPPT Tracking Status"

      id: ampinvt_track_status

      on_value:

        then:

          - lambda: |-

              if(x==0) {

                id(ampinvt_track_status_text_sensor).publish_state("Not Tracking");

              }

              else  {

                id(ampinvt_track_status_text_sensor).publish_state("Tracking");

              }

    - name: "Float Charging Status"

      id: ampinvt_floatchg_status

      on_value:

        then:

          - lambda: |-

              if(x==0) {

                id(ampinvt_floatchg_status_text_sensor).publish_state("Not Float Charging");

              }

              else  {

                id(ampinvt_floatchg_status_text_sensor).publish_state("Float Charging");

              }

    - name: "Charge Current Limit Status"

      id: ampinvt_chgcurrentlimit_status

      on_value:

        then:

          - lambda: |-

              if(x==0) {

                id(ampinvt_chgcurrentlimit_status_text_sensor).publish_state("Normal");

              }

              else  {

                id(ampinvt_chgcurrentlimit_status_text_sensor).publish_state("Charge Current Limit");

              }

    - name: "Charge Derating Status"

      id: ampinvt_chgderating_status

      on_value:

        then:

          - lambda: |-

              if(x==0) {

                id(ampinvt_chgderating_status_text_sensor).publish_state("Normal");

              }

              else  {

                id(ampinvt_chgderating_status_text_sensor).publish_state("Charge Derated");

              }

    - name: "Remote Prohibit Charging Status"

      id: ampinvt_remoteprohibchg_status

      on_value:

        then:

          - lambda: |-

              if(x==0) {

                id(ampinvt_remoteprohibchg_status_text_sensor).publish_state("Normal");

              }

              else  {

                id(ampinvt_remoteprohibchg_status_text_sensor).publish_state("Remote denial");

              }

    - name: "Panel Overvoltage Status"

      id: ampinvt_pvovervolt_status

      on_value:

        then:

          - lambda: |-

              if(x==0) {

                id(ampinvt_pvovervolt_status_text_sensor).publish_state("Normal");

              }

              else  {

                id(ampinvt_pvovervolt_status_text_sensor).publish_state("PV Overvoltage");

              }

    - name: "Charging Output Relay Status"

      id: ampinvt_chgoutputrelay_status

      on_value:

        then:

          - lambda: |-

              if(x==0) {

                id(ampinvt_chgoutputrelay_status_text_sensor).publish_state("Closed");

              }

              else  {

                id(ampinvt_chgoutputrelay_status_text_sensor).publish_state("Open");

              }

    - name: "Load Output Status"

      id: ampinvt_loadoutput_status

      on_value:

        then:

          - lambda: |-

              if(x==0) {

                id(ampinvt_loadoutput_status_text_sensor).publish_state("Closed");

              }

              else  {

                id(ampinvt_loadoutput_status_text_sensor).publish_state("Open");

              }

    - name: "Fan Relay Status"

      id: ampinvt_fanrelay_status

      on_value:

        then:

          - lambda: |-

              if(x==0) {

                id(ampinvt_fanrelay_status_text_sensor).publish_state("Closed");

              }

              else  {

                id(ampinvt_fanrelay_status_text_sensor).publish_state("Open");

              }

    - name: "Overcharge Protection Status"

      id: ampinvt_overchgprotect_status

      on_value:

        then:

          - lambda: |-

              if(x==0) {

                id(ampinvt_overchgprotect_status_text_sensor).publish_state("Normal");

              }

              else  {

                id(ampinvt_overchgprotect_status_text_sensor).publish_state("Overcharge Protection On");

              }

    - name: "Overvoltage Protection Status"

      id: ampinvt_overvoltprotect_status

      on_value:

        then:

          - lambda: |-

              if(x==0) {

                id(ampinvt_overvoltprotect_status_text_sensor).publish_state("Normal");

              }

              else  {

                id(ampinvt_overvoltprotect_status_text_sensor).publish_state("Overvoltage Protection On");

              }

    - name: "Solar Panel Voltage"

      id: ampinvt_pv_voltage

      unit_of_measurement: V

      accuracy_decimals: 1

      icon: mdi:flash

      filters:

        - multiply: 0.1

    - name: "Solar Battery Voltage"

      id: ampinvt_battery_voltage

      unit_of_measurement: V

      accuracy_decimals: 2

      icon: mdi:flash

      filters:

        - multiply: 0.01

    - name: "Solar Charge Current"

      id: ampinvt_charge_current

      unit_of_measurement: A

      accuracy_decimals: 2

      icon: mdi:current-dc

      filters:

      - multiply: 0.01

    - name: "Solar Controller Internal Temperature"

      id: ampinvt_mppt_temperature

      unit_of_measurement: °C

      accuracy_decimals: 1

      filters:

      - multiply: 0.1

    - name: "Solar Battery Temperature"

      id: ampinvt_battery_temperature

      unit_of_measurement: °C

      accuracy_decimals: 1

      filters:

        - multiply: 0.1

    - name: "Solar Daily Yield"

      id: ampinvt_today_yield

      unit_of_measurement: W

      accuracy_decimals: 1

      icon: mdi:solar-power

    - name: "Solar Total Yield"

      id: ampinvt_generation_total

      unit_of_measurement: KW

      device_class: energy #for use in energy dashboard

      state_class: total_increasing #for use in energy dashboard

      accuracy_decimals: 1

      icon: mdi:solar-power

      filters:

        - multiply: 0.001

  text_sensor:

  - platform: template

    name: "Ampinvt Operating Status"

    id: ampinvt_op_status_text_sensor

  - platform: template

    name: "Ampinvt Battery Status"

    id: ampinvt_battery_status_text_sensor

  - platform: template

    name: "Ampinvt Fan Status"

    id: ampinvt_fan_status_text_sensor

  - platform: template

    name: "Ampinvt Overheat Status"

    id: ampinvt_overheat_status_text_sensor

  - platform: template

    name: "Ampinvt DC Output Status"

    id: ampinvt_dcoutput_status_text_sensor

  - platform: template

    name: "Ampinvt Internal Temp #1 Status"

    id: ampinvt_inttemp1_status_text_sensor

  - platform: template

    name: "Ampinvt Internal Temp #2 Status"

    id: ampinvt_inttemp2_status_text_sensor

  - platform: template

    name: "Ampinvt External Temperature Status"

    id: ampinvt_exttemp_status_text_sensor

  - platform: template

    name: "Ampinvt Charging Status"

    id: ampinvt_chg_status_text_sensor

  - platform: template

    name: "Ampinvt Equalising Status"

    id: ampinvt_equalchg_status_text_sensor

  - platform: template

    name: "Ampinvt MPPT Tracking Status"

    id: ampinvt_track_status_text_sensor

  - platform: template

    name: "Ampinvt Float Charging Status"

    id: ampinvt_floatchg_status_text_sensor

  - platform: template

    name: "Ampinvt Charge Current Limit Status"

    id: ampinvt_chgcurrentlimit_status_text_sensor

  - platform: template

    name: "Ampinvt Charge Derating Status"

    id: ampinvt_chgderating_status_text_sensor

  - platform: template

    name: "Ampinvt Remote Prohib Status"

    id: ampinvt_remoteprohibchg_status_text_sensor

  - platform: template

    name: "Ampinvt Panel Overvoltage Status"

    id: ampinvt_pvovervolt_status_text_sensor

  - platform: template

    name: "Ampinvt Charging Output Relay Status"

    id: ampinvt_chgoutputrelay_status_text_sensor

  - platform: template

    name: "Ampinvt Load Output Status"

    id: ampinvt_loadoutput_status_text_sensor

  - platform: template

    name: "Ampinvt Fan Relay Status"

    id: ampinvt_fanrelay_status_text_sensor

  - platform: template

    name: "Ampinvt Overcharge Protection Status"

    id: ampinvt_overchgprotect_status_text_sensor

  - platform: template

    name: "Ampinvt Overvoltage Protection Status"

    id: ampinvt_overvoltprotect_status_text_sensor

  switch:

    - platform: restart

      name: "Solar Controller Restart"

      id: solar_controller_restart

In addition, I could not start with the command “!secret” before SSID, password and api key therefore removed.

when compiling I get only one following error:

INFO Reading configuration /config/esphome/ampinvt.yaml...
Failed config

time.homeassistant: [source /config/esphome/ampinvt.yaml:44]
  
  Component time.homeassistant requires component api.
  platform: homeassistant
  id: esptime
  on_time: 
    - seconds: 0,30
      then: 
        - uart.write: 
            - 1
            - 179
            - 1
            - 0
            - 0
            - 0
            - 0
            - 181

How can I fix this?
Thanks for the great project.

Resolved on Github.

is tomeone can help me on this topic ?

I have no comprehension of what you are asking. Did you post this in the correct thread?

Any idea if this would work with Renogy? I have a 48V 3500W 80A unit I sure would like to integrate into HA.

It is unlikely that this code would work as-is but the principle is the same. All I did for this project was take the work of others and adapt it for the Ampinvt units so you could do the same for Renogy.

Those Renogy units are popular though, I’d be surprised if someone hadn’t already done it in HACS or somewhere on Github.

@TripitakaBC Are you still around these parts? I have spent two days trying to get this wrapped up and im close. There are a few questions I have if you are.

What pin on the RJ45 is considered 1? I get conflicting answers.

Second, I only get Unknown as value for the sensors. I cant tell if it is because of wiring, or because of the H file. If yours is unplugged from your charger, does it drop to zero, or go to unk?

Many thanks.

I’m still around!

I’ll need to revisit to check out the RJ45 question and the whole project in general; it has been sat there chugging away and I’ll need to refresh myself.

You do, however, raise an enlightening issue. My own sensors went to ‘Unknown’ status a while back, right about the same time I had a malfunction with my powerful electric fencing. I figured that I had fried the modbus hardware so I swapped them out with no improvement so I figured that I had fried the interface in the controller. I thought it was a long shot that it had also taken out my DC shunt interface but…it could happen.

With your post, I’m now thinking that it may not be hardware at all, it may be code changes in ESPhome that is causing the issue.

Either way, I’ll have to revisit and get back to you. It may be a while but I’ll see what I can do.

Im glad you are still around. Im new to coding. I have done a lot of tinkering, working on this will be the biggest thing I’m learning. If i figure out anything, Ill update here as well. Thank you so much!

I got it! I’ve tried so many things, but i think in my case TX goes to TX and RX to RX… I watched some obscure Indian video on Youtube and found that this is the case with the RS485 to TTL i have.

image

This is my Yaml. I actually copied it from @kitt2011 comment. The one listed in the project wouldn’t compile for me.

The supplied .H file works fine though.

  esphome:
    name: "solarcharger"
    comment: "Solar Charge Controller"
    includes:
      - ampinvt.h
 

  esp32:
    board: esp32dev
    framework:
      version: recommended
      type: arduino

 

  logger:
    baud_rate: 0
    level: DEBUG

  wifi:
    ssid: Brown Haus 2G
    password: Forreston1
    reboot_timeout: 8hours
    ap:
      ssid: "${devicename}"
      password: fallback_password
    manual_ip:
      static_ip: 192.168.1.100
      gateway: 192.168.1.1
      subnet: 255.255.255.0
    use_address: 192.168.1.100
 

  captive_portal:

  api:
    encryption:
      key: uhKxfrQ8TOE+EpHHJZnas0YINhTkx3RQH2aSp6+gXTY=
  ota:
    - platform: esphome
      password: Netpass1.
      port: 8266
   

  uart:

    id: uart_bus

    tx_pin: 17 # Yellow Wire - MPPT UART Transmit

    rx_pin: 16 # Green Wire - MPPT UART Receive

    rx_buffer_size: 2048

    baud_rate: 9600

    parity: NONE

    stop_bits: 1

    debug:

 

  time:
    - platform: homeassistant
      id: esptime
      on_time:
        - seconds: 0,30
          then:
            - uart.write: [ 0x01, 0xB3, 0x01, 0x00, 0x00, 0x00, 0x00, 0xB5 ] # Reads only real-time data
  #          - uart.write: [ 0x01, 0xB2, 0x01, 0x00, 0x00, 0x00, 0x00, 0xB4 ] # Reads only parameter settings

 

  sensor:
  - platform: custom

    lambda: |-

      auto ampinvtsensors = new ampinvtsensor(id(uart_bus));

      App.register_component(ampinvtsensors);

      return {\

      ampinvtsensors->ampinvt_op_status, \

      ampinvtsensors->ampinvt_battery_status, \

      ampinvtsensors->ampinvt_fan_status, \

      ampinvtsensors->ampinvt_overheat_status, \

      ampinvtsensors->ampinvt_dcoutput_status, \

      ampinvtsensors->ampinvt_inttemp1_status, \

      ampinvtsensors->ampinvt_inttemp2_status, \

      ampinvtsensors->ampinvt_exttemp_status, \

      ampinvtsensors->ampinvt_chg_status, \

      ampinvtsensors->ampinvt_equalchg_status, \

      ampinvtsensors->ampinvt_track_status, \

      ampinvtsensors->ampinvt_floatchg_status, \

      ampinvtsensors->ampinvt_chgcurrentlimit_status, \

      ampinvtsensors->ampinvt_chgderating_status, \

      ampinvtsensors->ampinvt_remoteprohibchg_status, \

      ampinvtsensors->ampinvt_pvovervolt_status, \

      ampinvtsensors->ampinvt_chgoutputrelay_status, \

      ampinvtsensors->ampinvt_loadoutput_status, \

      ampinvtsensors->ampinvt_fanrelay_status, \

      ampinvtsensors->ampinvt_overchgprotect_status, \

      ampinvtsensors->ampinvt_overvoltprotect_status, \

      ampinvtsensors->ampinvt_pv_voltage, \

      ampinvtsensors->ampinvt_battery_voltage, \

      ampinvtsensors->ampinvt_charge_current, \

      ampinvtsensors->ampinvt_mppt_temperature, \

      ampinvtsensors->ampinvt_battery_temperature, \

      ampinvtsensors->ampinvt_today_yield, \

      ampinvtsensors->ampinvt_generation_total, \

      };

    sensors:

    - name: "Operating Status"

      id: ampinvt_op_status

      on_value:

        then:

          - lambda: |-

              if(x==0) {

                id(ampinvt_op_status_text_sensor).publish_state("Normal");

              }

              else  {

                id(ampinvt_op_status_text_sensor).publish_state("Abnormal");

              }

    - name: "Battery Status"

      id: ampinvt_battery_status

      on_value:

        then:

          - lambda: |-

              if(x==0) {

                id(ampinvt_battery_status_text_sensor).publish_state("Normal");

              }

              else  {

                id(ampinvt_battery_status_text_sensor).publish_state("OD Protection On");

              }

    - name: "Fan Status"

      id: ampinvt_fan_status

      on_value:

        then:

          - lambda: |-

              if(x==0) {

                id(ampinvt_fan_status_text_sensor).publish_state("Normal");

              }

              else  {

                id(ampinvt_fan_status_text_sensor).publish_state("Fan Failure");

              }

    - name: "Overheat Status"

      id: ampinvt_overheat_status

      on_value:

        then:

          - lambda: |-

              if(x==0) {

                id(ampinvt_overheat_status_text_sensor).publish_state("Normal");

              }

              else  {

                id(ampinvt_overheat_status_text_sensor).publish_state("OT Protection On");

              }

    - name: "DC Output Status"

      id: ampinvt_dcoutput_status

      on_value:

        then:

          - lambda: |-

              if(x==0) {

                id(ampinvt_dcoutput_status_text_sensor).publish_state("Normal");

              }

              else  {

                id(ampinvt_dcoutput_status_text_sensor).publish_state("DC Output Short");

              }

    - name: "Internal Temperature 1 Status"

      id: ampinvt_inttemp1_status

      on_value:

        then:

          - lambda: |-

              if(x==0) {

                id(ampinvt_inttemp1_status_text_sensor).publish_state("Normal");

              }

              else  {

                id(ampinvt_inttemp1_status_text_sensor).publish_state("Fault");

              }

    - name: "Internal Temperature 2 Status"

      id: ampinvt_inttemp2_status

      on_value:

        then:

          - lambda: |-

              if(x==0) {

                id(ampinvt_inttemp2_status_text_sensor).publish_state("Normal");

              }

              else  {

                id(ampinvt_inttemp2_status_text_sensor).publish_state("Fault");

              }

    - name: "External Temperature Status"

      id: ampinvt_exttemp_status

      on_value:

        then:

          - lambda: |-

              if(x==0) {

                id(ampinvt_exttemp_status_text_sensor).publish_state("Normal");

              }

              else  {

                id(ampinvt_exttemp_status_text_sensor).publish_state("Fault");

              }

    - name: "Charging Status"

      id: ampinvt_chg_status

      icon: mdi:battery-charging

      on_value:

        then:

          - lambda: |-

              if(x==0) {

                id(ampinvt_chg_status_text_sensor).publish_state("Not Charging");

              }

              else  {

                id(ampinvt_chg_status_text_sensor).publish_state("Charging");

              }

    - name: "Equal Charging Status"

      id: ampinvt_equalchg_status

      on_value:

        then:

          - lambda: |-

              if(x==0) {

                id(ampinvt_equalchg_status_text_sensor).publish_state("Not Equalising");

              }

              else  {

                id(ampinvt_equalchg_status_text_sensor).publish_state("Equalising");

              }

    - name: "MPPT Tracking Status"

      id: ampinvt_track_status

      on_value:

        then:

          - lambda: |-

              if(x==0) {

                id(ampinvt_track_status_text_sensor).publish_state("Not Tracking");

              }

              else  {

                id(ampinvt_track_status_text_sensor).publish_state("Tracking");

              }

    - name: "Float Charging Status"

      id: ampinvt_floatchg_status

      on_value:

        then:

          - lambda: |-

              if(x==0) {

                id(ampinvt_floatchg_status_text_sensor).publish_state("Not Float Charging");

              }

              else  {

                id(ampinvt_floatchg_status_text_sensor).publish_state("Float Charging");

              }

    - name: "Charge Current Limit Status"

      id: ampinvt_chgcurrentlimit_status

      on_value:

        then:

          - lambda: |-

              if(x==0) {

                id(ampinvt_chgcurrentlimit_status_text_sensor).publish_state("Normal");

              }

              else  {

                id(ampinvt_chgcurrentlimit_status_text_sensor).publish_state("Charge Current Limit");

              }

    - name: "Charge Derating Status"

      id: ampinvt_chgderating_status

      on_value:

        then:

          - lambda: |-

              if(x==0) {

                id(ampinvt_chgderating_status_text_sensor).publish_state("Normal");

              }

              else  {

                id(ampinvt_chgderating_status_text_sensor).publish_state("Charge Derated");

              }

    - name: "Remote Prohibit Charging Status"

      id: ampinvt_remoteprohibchg_status

      on_value:

        then:

          - lambda: |-

              if(x==0) {

                id(ampinvt_remoteprohibchg_status_text_sensor).publish_state("Normal");

              }

              else  {

                id(ampinvt_remoteprohibchg_status_text_sensor).publish_state("Remote denial");

              }

    - name: "Panel Overvoltage Status"

      id: ampinvt_pvovervolt_status

      on_value:

        then:

          - lambda: |-

              if(x==0) {

                id(ampinvt_pvovervolt_status_text_sensor).publish_state("Normal");

              }

              else  {

                id(ampinvt_pvovervolt_status_text_sensor).publish_state("PV Overvoltage");

              }

    - name: "Charging Output Relay Status"

      id: ampinvt_chgoutputrelay_status

      on_value:

        then:

          - lambda: |-

              if(x==0) {

                id(ampinvt_chgoutputrelay_status_text_sensor).publish_state("Closed");

              }

              else  {

                id(ampinvt_chgoutputrelay_status_text_sensor).publish_state("Open");

              }

    - name: "Load Output Status"

      id: ampinvt_loadoutput_status

      on_value:

        then:

          - lambda: |-

              if(x==0) {

                id(ampinvt_loadoutput_status_text_sensor).publish_state("Closed");

              }

              else  {

                id(ampinvt_loadoutput_status_text_sensor).publish_state("Open");

              }

    - name: "Fan Relay Status"

      id: ampinvt_fanrelay_status

      on_value:

        then:

          - lambda: |-

              if(x==0) {

                id(ampinvt_fanrelay_status_text_sensor).publish_state("Closed");

              }

              else  {

                id(ampinvt_fanrelay_status_text_sensor).publish_state("Open");

              }

    - name: "Overcharge Protection Status"

      id: ampinvt_overchgprotect_status

      on_value:

        then:

          - lambda: |-

              if(x==0) {

                id(ampinvt_overchgprotect_status_text_sensor).publish_state("Normal");

              }

              else  {

                id(ampinvt_overchgprotect_status_text_sensor).publish_state("Overcharge Protection On");

              }

    - name: "Overvoltage Protection Status"

      id: ampinvt_overvoltprotect_status

      on_value:

        then:

          - lambda: |-

              if(x==0) {

                id(ampinvt_overvoltprotect_status_text_sensor).publish_state("Normal");

              }

              else  {

                id(ampinvt_overvoltprotect_status_text_sensor).publish_state("Overvoltage Protection On");

              }

    - name: "Solar Panel Voltage"

      id: ampinvt_pv_voltage

      unit_of_measurement: V

      accuracy_decimals: 1

      icon: mdi:flash

      filters:

        - multiply: 0.1

    - name: "Solar Battery Voltage"

      id: ampinvt_battery_voltage

      unit_of_measurement: V

      accuracy_decimals: 2

      icon: mdi:flash

      filters:

        - multiply: 0.01

    - name: "Solar Charge Current"

      id: ampinvt_charge_current

      unit_of_measurement: A

      accuracy_decimals: 2

      icon: mdi:current-dc

      filters:

      - multiply: 0.01

    - name: "Solar Controller Internal Temperature"

      id: ampinvt_mppt_temperature

      unit_of_measurement: °C

      accuracy_decimals: 1

      filters:

      - multiply: 0.1

    - name: "Solar Battery Temperature"

      id: ampinvt_battery_temperature

      unit_of_measurement: °C

      accuracy_decimals: 1

      filters:

        - multiply: 0.1

    - name: "Solar Daily Yield"

      id: ampinvt_today_yield

      unit_of_measurement: W

      accuracy_decimals: 1

      icon: mdi:solar-power

    - name: "Solar Total Yield"

      id: ampinvt_generation_total

      unit_of_measurement: KW

      device_class: energy #for use in energy dashboard

      state_class: total_increasing #for use in energy dashboard

      accuracy_decimals: 1

      icon: mdi:solar-power

      filters:

        - multiply: 0.001

  text_sensor:

  - platform: template

    name: "Ampinvt Operating Status"

    id: ampinvt_op_status_text_sensor

  - platform: template

    name: "Ampinvt Battery Status"

    id: ampinvt_battery_status_text_sensor

  - platform: template

    name: "Ampinvt Fan Status"

    id: ampinvt_fan_status_text_sensor

  - platform: template

    name: "Ampinvt Overheat Status"

    id: ampinvt_overheat_status_text_sensor

  - platform: template

    name: "Ampinvt DC Output Status"

    id: ampinvt_dcoutput_status_text_sensor

  - platform: template

    name: "Ampinvt Internal Temp #1 Status"

    id: ampinvt_inttemp1_status_text_sensor

  - platform: template

    name: "Ampinvt Internal Temp #2 Status"

    id: ampinvt_inttemp2_status_text_sensor

  - platform: template

    name: "Ampinvt External Temperature Status"

    id: ampinvt_exttemp_status_text_sensor

  - platform: template

    name: "Ampinvt Charging Status"

    id: ampinvt_chg_status_text_sensor

  - platform: template

    name: "Ampinvt Equalising Status"

    id: ampinvt_equalchg_status_text_sensor

  - platform: template

    name: "Ampinvt MPPT Tracking Status"

    id: ampinvt_track_status_text_sensor

  - platform: template

    name: "Ampinvt Float Charging Status"

    id: ampinvt_floatchg_status_text_sensor

  - platform: template

    name: "Ampinvt Charge Current Limit Status"

    id: ampinvt_chgcurrentlimit_status_text_sensor

  - platform: template

    name: "Ampinvt Charge Derating Status"

    id: ampinvt_chgderating_status_text_sensor

  - platform: template

    name: "Ampinvt Remote Prohib Status"

    id: ampinvt_remoteprohibchg_status_text_sensor

  - platform: template

    name: "Ampinvt Panel Overvoltage Status"

    id: ampinvt_pvovervolt_status_text_sensor

  - platform: template

    name: "Ampinvt Charging Output Relay Status"

    id: ampinvt_chgoutputrelay_status_text_sensor

  - platform: template

    name: "Ampinvt Load Output Status"

    id: ampinvt_loadoutput_status_text_sensor

  - platform: template

    name: "Ampinvt Fan Relay Status"

    id: ampinvt_fanrelay_status_text_sensor

  - platform: template

    name: "Ampinvt Overcharge Protection Status"

    id: ampinvt_overchgprotect_status_text_sensor

  - platform: template

    name: "Ampinvt Overvoltage Protection Status"

    id: ampinvt_overvoltprotect_status_text_sensor

  switch:

    - platform: restart

      name: "Solar Controller Restart"

      id: solar_controller_restart