Home Assistant + Tasmota (Wemos mini R1) + Battery meter KG140F

Hello to all! :slight_smile:
This is my first post and I’ very happy to join this community :slight_smile:
I’m a noob, but I want to share my integration; it works after many tests and searches, but if there are some fix are welcome!

I’ve purchased this battery meter for my little photovoltaic system, 400A shunt version, but it too much for me
KG140F

It has a secondary serial port plug RJ10 (not rs485 modbus), I can read the values throught Tasmota and send them to Home Assistant.
This is the manual: Manual KG-F

The Tasmota firmware is standard, no sensors, display, etc… only config MQTT.
Connect A pin to RX Wemos pin
Connect B pin to TX Wemos pin (if you wont write settings, I want only read the values)
Connect GND pin to GND Wemos pin
PS: hope I’m right, I don’t remember! :thinking:

Set on Tasmota consolle:
Setoption19 1
Baudrate 115200
SendSerial 1

It send a text string like this, we need r50 values.

tele/BatteryMonitor/RESULT = {"SerialReceived":":R50=1,\n:r50=1,243,1242,0,11000,70,63,55062,125,0,0,0,0,0,\r\n"}

on Home Assistant in configuration.yaml, for test, I written this:

mqtt:
   - name: BatteryMonitor
     topic: tele/BatteryMonitor/RESULT

After many searches and study (I’m a noob), I written this:

template:
  - trigger:
      - platform: mqtt
        topic: tele/BatteryMonitor/RESULT
    sensor:
      - name: Temperatura
        unit_of_measurement: "°C"
        state: "{{ (trigger.payload.split(',')[9] | float-100) }}"
      - name: Tensione
        unit_of_measurement: "V"
        state: "{{ (trigger.payload.split(',')[3] | float/100) }}"
      - name: Corrente
        unit_of_measurement: "A"
        state: "{{ (trigger.payload.split(',')[4] | float/100) }}"
      - name: Potenza
        unit_of_measurement: "W"
        state: "{{ (trigger.payload.split(',')[6] | float/100) }}"
      - name: Capacità
        unit_of_measurement: "%"
        state: "{{ (trigger.payload.split(',')[5] | float/11000*100) }}"
      - name: Consumato
        unit_of_measurement: "kWh"
        state: "{{ (trigger.payload.split(',')[6] | float/10000) }}"

According to manual and it show this:


…changed value in red circle with percentage, my test battery is 11Ah

Hope this is usefully to someone and, of course, if anyone want change anything is welcome :slight_smile:

1 Like

hi giro,
I’m also interested in reading the data from the shunt. are you sure you didn’t use an adapter to be able to read data from the rs485 port?
I’m Italian too. if you like we can talk better cinelli92(chiocciola)gmail(punto)com

Hi niurz,
the rs485 on KG-F is a fake rs485.
No need additional hardware, but you must connect the display too :slight_smile:

I did exactly as you described and was able to get it to work. It’s just a pity that, in addition to the r50 information line, the shunt also publishes the r51 line, made up of many 0s, which ruin the reading of the sensor by HA. How did you solve this problem?

Try to use Teleperiod in tasmota consolle.
Teleperiod 10
ever 10 seconds it send the data to mqtt broker

To avoid the r51 line, turn on “monitor” in the display settings. Now the unit will only update the display and send only the r50line when an :R50=1,2,1, command is sent to the serial port. Anyone know how to send this periodically to the ESP from HA over MQTT?

1 Like

You can add this rule in the tasmota consolle

Rule1 on System#Boot do RuleTimer1 10 endon on Rules#Timer=1 do backlog SerialSend :R50=1,2,1,; RuleTimer1 10 endon

Rule1 1

Tasmota will send command every 10 seconds

About “monitor”, on my settings (on the display) I see:
display comm: ON
but the unit sends also r51 string.

I think that only solution is to use another wire plugged with rj10 and to cut A or B (?) pin.
At this time we need a RS485 converter for send command and receive data through tasmota rules.
In HA we can write a different and more stable code.

I will do!

Hi Giro,

I have the same device, and I don’t get this RS232 and RS485 thing.

According to documentation both ports on the device are labeled as RS485, so how did you discovered that the link port is RS232, could you be mistaken?

Hi, any further on with this?

I have two kg140f shunts, but no displays, i just use the app, do i definately need the display?

Also, whats data does the r50 line contain? SOC? - cant do a calculation in HA voltage x current?

Thanks👍

I discovered because I tested it.
I newer written that is RS232 protocol, if you have the display you don’t need any converter (TTL<->RS485), simply connect TX-RX to A B, it works. The display sends the commands and the unit send data through the two ports; tasmota receive the data. But but but …tasmota receive also r51 string and sometimens the data “freez” in home assistant.
So, I added to esp8266 a TTL<->RS485 converter, I have connected A to A, B to B and GND to GND.
I added a micro switch to VCC wire on display and it’s turned off, if I want to see the display, simply turn on the switch manually.
In tasmota consolle I written this rule

Rule1 on System#Boot do RuleTimer1 10 endon on Rules#Timer=1 do backlog SerialSend :R50=1,2,1,; RuleTimer1 10 endon

Rule1 1

…every 10 seconds it sends data over mqtt to HA.

No, you can use it without display.
example string

{"SerialReceived": ":R50=1,\n:r50=1,153,2639,0,186502,113506,18,2894,122,0,99,1,1316,6705,\r\n"}

decoding to

Address:1,
Checksum:153,		HA position split
Volt:2639,			        2
Ampere:0,			        3
CapacityAh:186502,		    4
CapacityCons:113506,	    5
kWh:18,				        6
RunningTime:2894,		    7
C°:122,				        8
Watt:0,				        9
99,				            10
1,				            11
BatteryLifeMinutes:1316,	12
ohm:6705,			        13

:+1::+1::+1:. Thank you for the reply…

I have ordered a display only from junctek to try before i read your reply, but it seems better with the display judging by your answer anyway… Be a couple of weeks to receive it. Going to order a wemos now.

I have ordered the unit also to test. While waiting, has anyone tried this with esphome instead of tasmota?

Mine is up and running. I noted that the initial setting on the console for serial output is “SerialSend 1” NOT “SendSerial 1”.

I also see r51 coming in the console but no issue for me. HA is running smoothly and not freezing.

11:27:23.727 MQT: tele/BatteryMonitor/RESULT = {"SerialReceived":":R50=1,\n:r50=1,224,4979,660,62648,17752,90,79316,131,0,0,0,569,27878,\r\n:R51=1,\n:r51=1,117,0,0,0,0,0,100,0,0,1500,100,100,100,0,0,1,\r\n"}

I also added power (W).

      - name: Battery Power
        unit_of_measurement: "W"
        state: "{{ ((trigger.payload.split(',')[3] | float/100) * (trigger.payload.split(',')[4] | float/100)) | round(2) }}"

Here is my screenshot.

Does anyone know how to get the SOC% ?

How do I make it send every 30 seconds instead of 10?

Hi, sorry i cant answer your question… Really need the SOC myself too, as thats the main reason i want to try this…
But, do you have the display plugged in, or use a TTL<->RS485 converter? How have you set it up? Are you using a d1 mini?
The display arrived today, will have a go at it tomorrow…

I am using an ESP32s and I connect TX, RX, and GND direct to KG140F. The display is plugged in and “on”.

1 Like

I have SCO working, at least matches what they have on the app. SOC = Ah remaining / Battery capacity (Amp) * 100

Anyone can help in reducing the frequency of the serial log from 10s to 30s or 60s? This may be one of the reasons HA is freezing for some people.

1 Like

Hi, i have gotten a d1 mini reading the data from the shunt, but when i add the lines:

mqtt:

  • name: D1_mini_1
    topic: tele/D1_mini_1/RESULT

To my config yaml file, i get this error when checking the config yaml file before i boot: (the topic name in my tasmota config is D1_mini_1). Do i need a ‘full topic’?

Invalid config for [mqtt]: expected dictionary for dictionary value @ data[‘mqtt’]. Got [OrderedDict([(‘name’, ‘D1_mini_1’), (‘topic’, ‘tele/D1_mini_1/RESULT’)])]. (See /config/configuration.yaml, line 198).

Any ideas? (sorry, im new to HA etc)