Hi,
I’m a noob in home assistant but i want to contribute with this community.
After reading the documentation about the KG140F DC 0-120V 100A and compare it with the information of this thread I got the following information:
The communication channel give me the following:
My shunt has this values:
r50=2,215,2056,200,5408,4592,9437,14353,134,0,0,0,162,30682
Explanation:
position Description
1 2 represents the communication address;
2 215 represents the checksum;
3 2056 represents the voltage of 20.56V;
4 200 represents current 2.00A;
5 5408 represents the remaining battery capacity is 5.408Ah;
6 4593 means the cumulative capacity is 4.593Ah;
7 9437 represents the watt-hour is 0.09437kw.h;
8 14353 represents the running time of 14353s;
9 134 represents the ambient temperature is 34℃;
10 0 means the function is pending;
11 0 means the output status is ON; (0-ON, 1-OVP, 2-OCP, 3-LVP, 4-NCP, 5-OPP, 6-OTP, 255-OFF)
12 0 represents the direction of current, and the current is forward current; (0-forward, 1-reverse)
13 162 means battery life is 162 minutes;
14 30682 represents the internal resistance of the battery is 306.82mΩ.
Decoding:
HA position split
Address(1,2,3,4,5,6,....) 1
Checksum:153, 2
Voltage(V)(2056->20.56) 3
CurrentAmpere(A)(200->2.0) 4
RemainingAh(Ah)(5408->5.408) 5
ElapsedAH(Ah) 6
AccumulatedChargingCapacity(Kwh) 7
RunningTimeSeconds, 8
Temperature(ºC)(134->34ºc->134-100) 9
pending 10
OutputStatus(alarms) 11
CurrentDirection(0/1) 12
BatteryLifeMinutes 13
ohm(30682->306.82->30682/100) 14
After struggling my head with the sensors, templates and so on, i finished with the following package(yaml file): pck_enrgyconsum_battery_control.yaml
input_number:
number_ampere_preset:
name: Number-Ampere-preset
icon: mdi:battery-high
min: 0
max: 360
initial: 127.5
step: 0.1
mode: box
unit_of_measurement: Ah
template:
- trigger:
- platform: mqtt
topic: tele/tasmota_03-ESP32-Shunt-PowerBank/RESULT
sensor:
- name: KG140F-01-Address
# unit_of_measurement: ""
state: "{{ (trigger.payload.split(',')[1] | float) }}"
- name: KG140F-01-Checksum
# unit_of_measurement: "V"
state: "{{ (trigger.payload.split(',')[2] | float) }}"
- name: KG140F-01-Voltage
unit_of_measurement: "V"
state: "{{ (trigger.payload.split(',')[3] | float/100) }}"
- name: KG140F-01-CurrentAmpere
unit_of_measurement: "Ah"
state: "{{ (trigger.payload.split(',')[4] | float/100) }}"
- name: KG140F-01-RemainingAh
unit_of_measurement: "Ah"
state: "{{ (trigger.payload.split(',')[5] | float/1000) }}"
- name: KG140F-01-ElapsedAH
unit_of_measurement: "Ah"
state: "{{ (trigger.payload.split(',')[6] | float/1000) }}"
- name: KG140F-01-AccumChrgCapacity
unit_of_measurement: "Kwh"
state: "{{ (trigger.payload.split(',')[7] | float/100000) }}"
- name: KG140F-01-RunningTimeSeconds
unit_of_measurement: "s"
state: "{{ (trigger.payload.split(',')[8] | float) }}"
- name: KG140F-01-RunningTimeHours
unit_of_measurement: "h"
state: "{{ (trigger.payload.split(',')[8] | float/60/60) }}"
- name: KG140F-01-Temperature
unit_of_measurement: "ºC"
state: "{{ (trigger.payload.split(',')[9] | float-100) }}"
- name: KG140F-01-Pending
# unit_of_measurement: ""
state: "{{ (trigger.payload.split(',')[10] | float) }}"
- name: KG140F-01-OutputStatus
# unit_of_measurement: ""
state: "{{ (trigger.payload.split(',')[11] | float) }}"
- name: KG140F-01-CurrentDirection
# unit_of_measurement: ""
state: "{{ (trigger.payload.split(',')[12] | float) }}"
- name: KG140F-01-BatteryLifeMinutes
unit_of_measurement: "min"
state: "{{ (trigger.payload.split(',')[13] | float) }}"
- name: KG140F-01-BatteryLifeHours
unit_of_measurement: "h"
state: "{{ (trigger.payload.split(',')[13] | float/60) }}"
- name: KG140F-01-Ohm
unit_of_measurement: "mΩ"
state: "{{ (trigger.payload.split(',')[14] | float/100) }}"
sensor:
# Calculate current power
- platform: template
sensors:
kg140f_01_currentpower:
value_template: >
{% set t = states('sensor.kg140f_01_currentdirection') | float(0) %}
{% if t == 0 %}
{{ '%0.1f' | format ( -1 |float *
(
states('sensor.kg140f_01_voltage') | float *
states('sensor.kg140f_01_currentampere') | float
)
)
}}
{% elif t == 1 %}
{{ '%0.1f' | format
(
states('sensor.kg140f_01_voltage') | float *
states('sensor.kg140f_01_currentampere') | float
)
}}
{% else %}
{{ '%0.1f' | format
(
states('sensor.kg140f_01_voltage') | float *
states('sensor.kg140f_01_currentampere') | float
)
}}
{% endif %}
unit_of_measurement: 'W'
friendly_name: KG140F-01 Current Power
kg140f_01_ampereconsumption:
value_template: >
{% set t = states('sensor.kg140f_01_currentdirection') | float(0) %}
{% if t == 0 %}
{{ '%0.1f' | format ( -1 |float * states('sensor.kg140f_01_currentampere') | float ) }}
{% elif t == 1 %}
{{states('sensor.kg140f_01_currentampere')|float }}
{% else %}
{{states('sensor.kg140f_01_currentampere')|float }}
{% endif %}
unit_of_measurement: 'Ah'
friendly_name: KG140F-01 Ampere Consumption
kg140f_01_battery_level:
value_template: >
{{ '%0.1f' | format
(
(states('sensor.kg140f_01_remainingah') | float * 100 ) /
states('input_number.number_ampere_preset') | float
)
}}
unit_of_measurement: '%'
friendly_name: KG140F-01 Battery Level
The only thing that is not working for me, is the tasmota rule, despite whatever i put in the rule, the transmission to the HA is every second… I bought some D1 mini, just for check if the problem is the ESP32 or not.
Rule1 on System#Boot do RuleTimer1 10 endon on Rules#Timer=1 do backlog SerialSend :R50=1,2,1,; RuleTimer1 10 endon
Rule1 1
So the dashboard is:
When the shunt detect the negative current:
When the shunt detect the positive current(charging):
Thanks a lot to all of you for your knowledge
Luis.