Cannot change sensor unit of measurement

Hello there

I am using an Tasmota device to read my utility meter. The device is called “gplugm”. The sensor is called “sensor.gplugm_ei”, which shows the total energy consumed this year. This is working perfectly. The value is showing up in my dashboard, but without any unit of measurement.

I need to configure the sensor as Energy sensor and set a unit of measurement “kWh” to properly use the energy dashboard.

I received this configuration script from the developer of the device

homeassistant:
 customize_glob:
 sensor.gplugm_ei:
 unit_of_measurement: "kWh"
 device_class: energy
 state_class: total_increasing

I added it to the top of my configuration.yaml but I get a bad error:

Cannot quick reload all YAML configurations because the configuration is not valid: Invalid config for 'homeassistant' at configuration.yaml, line 2: expected a dictionary for dictionary value 'customize_glob', got None Invalid config for 'homeassistant' at configuration.yaml, line 3: 'sensor.gplugm_ei' is an invalid option for 'homeassistant', check: sensor.gplugm_ei Invalid config for 'homeassistant' at configuration.yaml, line 4: 'unit_of_measurement' is an invalid option for 'homeassistant', check: unit_of_measurement Invalid config for 'homeassistant' at configuration.yaml, line 5: 'device_class' is an invalid option for 'homeassistant', check: device_class Invalid config for 'homeassistant' at configuration.yaml, line 6: 'state_class' is an invalid option for 'homeassistant', check: state_class

What am I doing wrong? Could somebody help me with an example on how to set up the sensor in Configuration.yaml?

Indentation all wrong. See here:

You must only have one homeassistant: heading in the file, so you may need to combine what you’ve been sent with what you already have.

homeassistant:

# existing config already under homeassistant: here

  customize:
    sensor.gplugm_ei:
      unit_of_measurement: "kWh"
      device_class: energy
      state_class: total_increasing

Ok, thank you! I changed it to this:

homeassistant:
 # Loads default set of integrations. Do not remove.
 default_config:
 # Load frontend themes from the themes folder
 frontend:
 themes: !include_dir_merge_named themes
 automation: !include automations.yaml
 script: !include scripts.yaml
 scene: !include scenes.yaml

  customize:
    sensor.gplugm_ei:
      unit_of_measurement: "kWh"
      device_class: energy
      state_class: total_increasing

What am I doing wrong here?

The bits you’ve included before the customize do not sit under homeassistant but are top-level keys. If you don’t already have anything under that key, just leave it. Like this:

# Loads default set of integrations. Do not remove.
default_config:
# Load frontend themes from the themes folder
frontend:
themes: !include_dir_merge_named themes
automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml

homeassistant:
  customize:
    sensor.gplugm_ei:
      unit_of_measurement: "kWh"
      device_class: energy
      state_class: total_increasing

Do not change the indentation level of anything already in the file. Indentation is critical in YAML.

Thank you so much!

It’s working now!

Hello everyone

I do have a connecting problem with the same device (gplugm). May you can help me there.

The utility meter device is working and on the Tasmota interface I can see the right values. I have somehow a connection to home assistant over mqtt but without the sensor values.

In the protocol on the mosquito broker I see the following log:

2025-06-06 14:46:37: New connection from 192.168.178.133:61496 on port 1883.
2025-06-06 14:46:37: New client connected from 192.168.178.133:61496 as DVES_AC8388 (p2, c1, k30, u'stromprivat').

I got the following lines in the console of the device:

14:56:11.548 MQT: tele/gPlugM2_AC8388/STATE = {"Time":"2025-06-06T14:56:11","Uptime":"0T00:09:39","UptimeSec":579,"Heap":157,"SleepMode":"Dynamic","Sleep":50,"LoadAvg":20,"MqttCount":1,"Berry":{"HeapUsed":4,"Objects":42},"Wifi":{"AP":1,"SSId":"Nestli","BSSId":"2C:3A:FD:19:92:B4","Channel":1,"Mode":"HT40","RSSI":100,"Signal":-42,"LinkCount":1,"Downtime":"0T00:00:04"}}
14:56:11.588 MQT: tele/gPlugM2_AC8388/SENSOR = {"Time":"2025-06-06T14:56:11","z":{"SMid":"75652081","Pi":0.000,"Po":0.074,"Pi1":0.000,"Pi2":0.000,"Pi3":0.000,"Po1":0.000,"Po2":0.000,"Po3":0.000,"U1":241.0,"U2":240.0,"U3":239.0,"I1":0.46,"I2":1.02,"I3":0.46,"Ei":53.010,"Eo":1.824,"Ei1":33.993,"Ei2":19.017,"Eo1":1.824,"Eo2":0.000,"Q5":0.000,"Q6":0.000,"Q7":0.000,"Q8":0.000,"Q51":1.941,"Q52":0.001,"Q61":0.010,"Q62":0.000,"Q71":5.970,"Q72":0.000,"Q81":21.591,"Q82":20.665}}

In the script configuration I have the following code:

>D 35
; gPlugM Tasmota 14.6.0 HDLC/DLMS (25.5.25)
upH=0
sr=0
ss=0

rBlink=0
d=750
noWifi=0

; set your decryption key (len 32), if encrypted
;dKEY="12345678123456781234567812345678"
dKEY=""

; shared var within local network
g:Pi=0
g:Po=0

; define Pins of colored LEDs
redP=1
blueP=3
greenP=4
; butA=9
; rxPin=7

>B
; disable publishing at MQTT teleperiod, on boot
smlj=0

; activate data parsing
-> sensor53 r

; enable pin 4 (green LED) to indicate serial activity
-> sensor53 l4

>BS
; enable mDNS
-> setOption55 1

; MQTT frequenyc is set to 1/10 Hz
-> teleperiod 10

; dynamic wifi Tx power
-> wifipower 0

; reduce power consumption
; See https://tasmota.github.io/docs/Dynamic-Sleep/
-> setOption127 OFF
-> sleep 50

; For low RSSI: Keep wifi in no-sleep mode to avoid outages
; -> setOption127 ON

; referrer check
-> SetOption128 ON

; show CPU temperature in webUI
; -> SetOption146 1

; configure LED pins
spinm(blueP O)
spinm(greenP O)
spinm(redP O)

; lightshow at startup
spin(redP 1)
delay(d)
spin(redP 0)
spin(greenP 1)
delay(d)
spin(greenP 0)
spin(blueP 1)
delay(d)
spin(blueP 0)


>M 1
; rx Pin 7, raw 8E1, Baudrate 2400
+1,7,rE1,0,2400,z

; invert HW serial (4) && disable pullup (8)
1,=so2,0C

; set input buffer size (may be increased)
1,=so3,600

; your 32 char HEX Key from var dKEY is set
; if data is not encrypted, "1,=so4," is set
;1,=so4,DECR-KEY
1,=so4,%dKEY%

; OBIS Codes (IEC 62056-61):
; See https://cdn.standards.iteh.ai/samples/104764/8356233bf80942e9ba6d5ac9cbdf3af0/IEC-62056-6-1-2023.pdf
;     media: abstract=0, electricity=1, heat=6, gas=7, water=8)
; "-" channel: =0 (if not more than 1 available)
; ":" physical unit (in=1, out=2,
;      phase current=31,51,71, voltage=31,51,71,
;      phase power in=21,41,61, out=22,42,62)
; "." measurement type (instant=7, counter=8, peak-hold=6)
; "." tarif (0=total, 1=day, 2=night)

; some DSO use 96.1.1. instead
1,pm(96.1.0)@#),*,,SMid,0

; P=Power, i=in, o=out, V=Voltage, I=Current, E=Energy
1,=h<h4>Real Power In & Out<h4/>
1,pm(1.7.0)@1000,Pi ___ 1.7.0,kW,Pi,3
1,pm(2.7.0)@1000,Po ___ 2.7.0,kW,Po,3

; Note: adding +16 to the last value (precision)
; will generate an immediate MQTT telegram

1,=h<hr/>
1,=h<h4>Instant Phase Power In & Out<h4/>
1,pm(21.7.0)@1000,Pi1 ___ 21.7.0,W,Pi1,3
1,pm(41.7.0)@1000,Pi2 ___ 41.7.0,W,Pi2,3
1,pm(61.7.0)@1000,Pi3 ___ 61.7.0,W,Pi3,3
;
1,pm(22.7.0)@1000,Po1 ___ 22.7.0,W,Po1,3
1,pm(42.7.0)@1000,Po2 ___ 42.7.0,W,Po2,3
1,pm(62.7.0)@1000,Po3 ___ 62.7.0,W,Po3,3

1,=h<hr/>
1,=h<h4>Instant Phase Voltage<h4/>
1,pm(32.7.0)@10,U1 ___ 32.7.0,V,U1,1
1,pm(52.7.0)@10,U2 ___ 52.7.0,V,U2,1
1,pm(72.7.0)@10,U3 ___ 72.7.0,V,U3,1

1,=h<hr/>
1,=h<h4>Instant Phase Currents<h4/>
1,pm(31.7.0)@100,I1 ___ 31.7.0,A,I1,2
1,pm(51.7.0)@100,I2 ___ 51.7.0,A,I2,2
1,pm(71.7.0)@100,I3 ___ 71.7.0,A,I3,2

1,=h<hr/>
1,=h<h4>Real Energy Counters <h4/>

1,pm(1.8.0)@1000,Ei ___ 1.8.0,kWh,Ei,3
1,pm(2.8.0)@1000,Eo ___ 2.8.0,kWh,Eo,3

1,=h_
1,pm(1.8.1)@1000,Ei1 ___ 1.8.1,kWh,Ei1,3
1,pm(1.8.2)@1000,Ei2 ___ 1.8.2,kWh,Ei2,3

1,pm(2.8.1)@1000,Eo1 ___ 2.8.1,kWh,Eo1,3
1,pm(2.8.2)@1000,Eo2 ___ 2.8.2,kWh,Eo2,3

1,=h<hr/>
1,=h<h4>Reactive Energy Counters<h4/>

1,pm(5.8.0)@1000,Q5 ___ 5.8.0,kVArh,Q5,3
1,pm(6.8.0)@1000,Q6 ___ 6.8.0,kVArh,Q6,3
1,pm(7.8.0)@1000,Q7 ___ 7.8.0,kVArh,Q7,3
1,pm(8.8.0)@1000,Q8 ___ 8.8.0,kVArh,Q8,3
1,=h_
1,pm(5.8.1)@1000,Q51 ___ 5_8_1,kVArh,Q51,3
1,pm(5.8.2)@1000,Q52 ___ 5_8_2,kVArh,Q52,3

1,pm(6.8.1)@1000,Q61 ___ 6_8_1,kVArh,Q61,3
1,pm(6.8.2)@1000,Q62 ___ 6_8_2,kVArh,Q62,3

1,pm(7.8.1)@1000,Q71 ___ 7_8_1,kVArh,Q71,3
1,pm(7.8.2)@1000,Q72 ___ 7_8_2,kVArh,Q72,3

1,pm(8.8.1)@1000,Q81 ___ 8_8_1,kVArh,Q81,3
1,pm(8.8.2)@1000,Q82 ___ 8_8_2,kVArh,Q82,3
#

>S
; every second
upH=uptime/60
sr=sunrise/60
ss=sunset/60

; enable MQTT 15 seconds after boot
if upsecs>15 {
 smlj|=1
}

; update values of global vars
Pi=sml[2]
Po=sml[3]

; if no wifi connection after 10 sec, blink red
if wifis==0 {
  noWifi+=1
}
if noWifi>10 {
  rBlink=2
}

>F
; every 100 ms

; blink red
if rBlink>0 {
  spin(redP 1)
  rBlink-=1
  noWifi=0
} else {
  spin(redP 0)
}

; blink green on data reception
; if smlv[2]==1 {
;   spin(greenP 1)
;   smlv[0]
; } else {
;   spin(greenP 0)
; }

>W
@<style>h4{margin-block-end: 0;color: cyan}td th{font-weight: normal;}tr th:first-child{text-align: left;}tr td:nth-child(2){text-align: right;color: lime;font-weight:normal;}table{width:100\%;}</style>
@<table><tbody>
 <tr><th>L+G E450, data freq. (counters 1/60 Hz)</th>1/5 Hz<td></td></tr>
 <tr><th>SM-ID</th><td>%smls[1]%</td></tr>
 <tr><th>Date \& Time</th><td>%tstamp%</td></tr>
 <tr><th>Uptime</th><td> %1upH% h</td></tr>
</tbody></table>

Has anyone a guess what I’m doing wrong?

Good afternoon,
It look like that I/we have the same Problem:

  • Same Devie gPlugM
  • Almost same script
  • D 35
    ; gPlugM Tasmota 14.3.0 DLMS L+G Universal (8.1.24)"

  • On Home Assistant I see only a few basis entities

I also got a suggest for the configuration.yaml file

default_config:

# Load frontend themes from the themes folder
frontend:
  themes: !include_dir_merge_named themes

automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml

homeassistant:
  customize:
    sensor.gPlugM_ei_1_8:
      unit_of_measurement: "kWh"
      device_class: energy
      state_class: total_increasing
      last_reset: 1970-01-01T00:00:00+00:00
    sensor.gPlugM_ei1_1_8_1:
      unit_of_measurement: "kWh"
    sensor.gPlugM_ei2_1_8_2:
      unit_of_measurement: "kWh"
    sensor.gPlugM_eo_2_8:
      unit_of_measurement: "kWh"
      device_class: energy
      state_class: total_increasing
      last_reset: 1970-01-01T00:00:00+00:00
    sensor.gPlugM_eo1_2_8_1:
      unit_of_measurement: "kWh"
    sensor.gPlugM_eo2_2_8_2:
      unit_of_measurement: "kWh" 
    sensor.gPlugM_i1_31_7:
      unit_of_measurement: "A"
    sensor.gPlugM_i2_51_7:
      unit_of_measurement: "A"
    sensor.gPlugM_i3_71_7:
      unit_of_measurement: "A"
    sensor.gPlugM_v1_32_7:
      unit_of_measurement: "V"
    sensor.gPlugM_v2_52_7:
      unit_of_measurement: "V"
    sensor.gPlugM_v3_72_7:
      unit_of_measurement: "V"
    sensor.gPlugM_pi_1_7:
      unit_of_measurement: "kW"
    sensor.gPlugM_po_2_7:
      unit_of_measurement: "kW"

utility_meter:
  energy_in_daily:
    source: sensor.gPlugM_ei_1_8
    cycle: daily
  energy_in_weekly:
    source: sensor.gPlugM_ei_1_8
    cycle: weekly
  energy_in_monthly:
    source: sensor.gPlugM_ei_1_8
    cycle: monthly
  energy_in_yearly:
    source: sensor.gPlugM_ei_1_8
    cycle: yearly
type or paste code here

Having a look into MQTT withe the explorer I see some exchange. However on Home Assistant I do not se the data/entities.

Many thanks for your tips/help

Hello Hans Peter

After playing around for a long time, I had already given up. When I returned to the Home Assistant after a few days, I discovered some new data in the Tasmota. Now I just have to give them the right unit and it seams to work.

It looks like that in the Tasmota Integration:

On the Tasmota Device I use the following settings:

I hope it’ll help you.

Good afternoon,
Great to hear, that you managed to solve the problem. I also found a solution (together with a good working colleague). Your Tasmota configuration looks similar as mine. Also the tasmota script on the gPlugM. In a first step I installed the MQTT explorer on Home Assistant. There I found/saw the topic from gPlugM.


For me, this is/was a confirmation, the the data from the smartmeter a arrived on MQTT. The question for me and my colleague was: Where are the correspinding entities on home assistant. My colleague knows HA for some years. From his point of view the question was: How doese HA subscribe the required topics. Well, actually it seems that certain topics (beginning with “homeassistant” will be automatically subscribed (you may have a look at MQTT explorer). In My case, the Topic “tele/gPlugM_43DC2C” was not subscribed at that time. We did that on MQTT. After that, isaw like you the entities on the tasmota Integration.

In conclusion:

  • The gPlugM device with it’s generic setup/configuration works well (The support from the vendor/producer “Gantrisch Energie AG” is really good.
  • Actually I use the generic Configuration on the gPlugM Device (I am waiting for the offical OBIS code from Energy Thun).
  • This ist the first time, that I had to work directly with MQTT. Therefore, there is some documention work to do (for me).

Best Regards
And Greetings from Thun

Hans Peter

1 Like

Hi Hans Peter

Can you perhaps briefly explain to me how you did the subscribe? i have been struggling with exactly the same problem since switching from the amsreader firmware to the tasmota version.

Good evening, sorry for the delay.
I was on a trip. Your question concerning the subscription of a topic:
First I got the correct topic from the MQTT explorer. There you’ll find the required topic (below you see "my2 topc). In your case, i suppose the required topic would be “tele\gPlugM_84C7AC\SENSOR”


You may copy the topic and use it for the subscription in the MQTT integration.

I got this hint from a colleague. In the HA documentation I found, that topics beginning “homeassistant” will be automatically subscribed. All other topics must be manually in MQTT subscribed.

Hope this helps :slight_smile:

Dear Collegues

I just successfully integrated the gplugm into HA. Therfore I want to share the steps and config I used for elektra.

  1. I had to ask elektra to enable the MBus interface
  2. basically followed this tutorial:
    Integration gPlug in Home Assistant
  3. configuration.yaml:
homeassistant:
  customize_glob:
    sensor.gplugm_z_ei:
      unit_of_measurement: "kWh"
      device_class: energy
      state_class: total_increasing
      last_reset: 1970-01-01T00:00:00+00:00
    sensor.gplugm_z_ei1:
      unit_of_measurement: "kWh"
      device_class: energy
      state_class: total_increasing
    sensor.gplugm_z_ei2:
      unit_of_measurement: "kWh"
      device_class: energy
      state_class: total_increasing
    sensor.gplugm_z_eo:
      unit_of_measurement: "kWh"
      device_class: energy
      state_class: total_increasing
      last_reset: 1970-01-01T00:00:00+00:00
    sensor.gplugm_z_eo1:
      unit_of_measurement: "kWh"
      device_class: energy
      state_class: total_increasing
    sensor.gplugm_z_eo2:
      unit_of_measurement: "kWh" 
      device_class: energy
      state_class: total_increasing
    sensor.gplugm_z_i1:
      unit_of_measurement: "A"
      device_class: current
    sensor.gplugm_z_i2:
      unit_of_measurement: "A"
      device_class: current
    sensor.gplugm_z_i3:
      unit_of_measurement: "A"
      device_class: current
    sensor.gplugm_z_u1:
      unit_of_measurement: "V"
      device_class: voltage
    sensor.gplugm_z_u2:
      unit_of_measurement: "V"
      device_class: voltage
    sensor.gplugm_z_u3:
      unit_of_measurement: "V"
      device_class: voltage
    sensor.gplugm_z_pi:
      unit_of_measurement: "kW"
      device_class: power
    sensor.gplugm_z_po:
      unit_of_measurement: "kW"
      device_class: power

utility_meter:
  energy_in_daily:
    source: sensor.gplugm_z_ei
    cycle: daily
  energy_in_weekly:
    source: sensor.gplugm_z_ei
    cycle: weekly
  energy_in_monthly:
    source: sensor.gplugm_z_ei
    cycle: monthly
  energy_in_yearly:
    source: sensor.gplugm_z_ei
    cycle: yearly