Need Modbus help for Varta Battery Active power from experts

I ve got an Varta Battery Pulse Neo - need to get the active power over modbus tcp

Got this config:

# Modbus Varta Speicher
modbus:
  - name: mb_varta       ### or whatever name
    type: tcp
    host: 192.168.123.63        ### ip/hostname your inverter has
    port: 502
    sensors:
### Active Power - positive:charge / negative: discharge
    - name: mb_varta_active_power
      slave: 1
      address: 1066
      count: 1
      data_type: uint
      scan_interval: 5
### Active Power SF
    - name: mb_varta_active_power_sf
      slave: 1
      address: 2066
      count: 1
      scan_interval: 5

and this template sensor:

sensor:
  - platform: template 
    scan_interval: 5
    sensors:
  ### AC power result:
      mb_varta_active_power_ts:
        unit_of_measurement: 'W'
        device_class: power
        value_template: >-
          {{ ((states('sensor.mb_varta_active_power') | int) * (10 ** ((states('sensor.mb_varta_active_power_sf')| int )) )) | int }}

The Varta Register:
1066 active power R SINT16 1 W measured at internal inverter
positive: charge
negative: discharge

What is a SINT16 ? cant find SINT in Modbus Integration - only float int uint … ???

At this config i get returns like “65013” what is in reality -524 W

Varta say at Register 2066 is the Scal Factor : active power = (value in #1066) * 10 ^
(value in #2066)

But it returns only “0” and the return of the template sensor calculation is also “65013”

How can i get the right return ?

I already get the W over an TCL Script that does the job without getting the ScaleFactor:

proc ::modbus::cmd03_unpack {reqCmd rspCmd} {
# response
    #station : 1 byte
    #function : 1 byte (always 0x03)
    #byte count : 1 byte
    #data : N*2 bytes (reg1_low...reg1_hi...reg2_low...reg2_hi...)

    if {[string range $reqCmd 0 1] != [string range $rspCmd 0 1]} {return [list]}
    if {[binary scan [string range $reqCmd 4 5] S reqBytes] == 0} {return [list]}
    set data [string range $rspCmd 3 end]
    set len [string length $data]
    set ret [list]

    for {set i 0} {$i < $len} {incr i} {
        binary scan [string range $data $i [incr i]] S byte
        lappend ret $byte
    }

    return $ret

}

But i dont understand the TCL ?

Can anyone help please ? THX

    - name: mb_varta_active_power
      slave: 1
      address: 1066
      data_type: int16
      precision: 0
      scale: 1

The problem is above FFFF… you may need use your template. If register scale is dynamic…

seems to work! Marvelous !

Don´t need to use the Scale Register - seems it is not dynamic.

thank you very much

now I test a few other registers, if problems arise again I will contact you again :wink: thx

1 Like

Hey guys, is there any documentation available how to integrate your modbus tcp connect? Sorry for the question but I am completly new to home assistant…
Thanks in advance!!

/config/configuration.yaml

Hi, I’m also a beginner using modbus in HA.
Today I’ve copied the config above (and adapted my IP, of course). After restarting, Home Assistent is polling the values once. But after the first polling I’ll get no further values.

In the Log several errors appear:

Pymodbus: mb_varta: Modbus Error: [Connection] ModbusTcpClient(192.168.1.88:502): Connection unexpectedly closed 0.000014 seconds into read of 8 bytes without response from unit before it closed connection

Do you have any idea?

    port: 502
    delay: 1
    timeout: 3
    retries: 3
    retry_on_empty: true
    message_wait_milliseconds: 250

Thank you for the code, works fine…
regarding the energy dashboard, which sensors do I need here?
grafik

I often get sensor “unavailable”?

Moin,
Ich habe alles eingestellt der Homeassistant zählt auch alles was in die Batterie geladen wird.
Allerdings geht der Output nicht.
Kann mir jemand helfen?
Anbei meine configuratin.yaml

Danke