Tasmota and Carlo Gavazzi EM112 Energy meter

368 views
Skip to first unread message

Albert Weterings

unread,
Mar 17, 2022, 9:35:36 AM3/17/22
to TasmotaUsers
Hi all. I connected a Carlo Gavazzi EM112 Energy meter via RS485/MODBUS to tasmota this works almost well via the script below.

There is one problem the moment the measured Wattage coming from register  0004h and 0106h goes over approximately 3600 watt it flips to a negative value. The register I read from the Energy meter contains a two word signed INT32.

I think I do something wrong with setting the decoder or the decode value goes in a variable that is not able hold the value. Does anyone have a idea how to solve this issue?

Documentation on this Energy meter can be found here:
and

>D
>B
tper=500
->sensor53 r
>S
;re-enable publishing at MQTT teleperiod, after 10 seconds of uptime
if upsecs>60
then
tper=10
endif
>M 1  
+1,1,m,0,9600,MODBUS,3,10,01030000,01030002,01030106,01030006,0103010C,01030110,01030500,0103051C
1,010304SSss@i0:10,Voltage,V,Voltage,1
1,010304SSss@i1:1000,Ampere,A,Ampere,2
1,010304SSss@i2:10,Watt,W,Watt,1
1,010304SSss@i3:10,VA,VA,VA,1
1,010304SSss@i4:1000,PF,PF,PF,2
1,010304SSss@i5:10,Hz,Hz,Hz,1
1,010304SSss@i6:1000,kWh (+),kWh (+),kWh (+),3
1,010304SSss@i7:1000,kWh (-),kWh (-),kWh (-),3
#

Philip Knowles

unread,
Mar 17, 2022, 5:32:36 PM3/17/22
to Albert Weterings, TasmotaUsers

Well from the look of your decoder strings you are only using 16 bit not 32 bit

 

SSss = extract a signed word (high order byte first)
ssSS = extract a signed word (low order byte first)
SSssSSss = extract a signed long word (high order byte first)
ssSSssSS = extract a signed long word (low order byte first)

 

Sent from Mail for Windows

--
You received this message because you are subscribed to the Google Groups "TasmotaUsers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sonoffusers...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/sonoffusers/fdd2570e-5b15-4245-b99c-36e9f220ef86n%40googlegroups.com.

 

Albert Weterings

unread,
Mar 18, 2022, 2:12:27 AM3/18/22
to TasmotaUsers
It looks to be working using  SSssSSsx in that case it shows the correct value but still flips to negative the moment the value goes above 3200 (unfortunately I can't find the exact value where it flips) When I use SSssSSss I get an insane high value. I have tried I think all combinations with the filter nothing helps.

What is doing 010304? I could figure out 01 is the meter ID 03 the read register command but 04 I do not understand. If I make them all x I still get the correct reading.

Op donderdag 17 maart 2022 om 22:32:36 UTC+1 schreef knowles...@gmail.com:

Philip Knowles

unread,
Mar 18, 2022, 3:56:04 AM3/18/22
to Albert Weterings, TasmotaUsers

The register lists are in the MODBUS definition line

The information about decoders is annoyingly sparse but they mostly seem to be 010304 or 010404

Are you sure it’s a signed value?

Most of the MODBus meter definitions have Watts as unsigned so I would try that.

 

Regards

 

Phil K

Albert Weterings

unread,
Mar 18, 2022, 2:07:01 PM3/18/22
to TasmotaUsers
Thanks Phil for your help so far.

I'm still trying to figure out what is happening over here. It looks indeed that some of the variables are indeed unsigned. But the thing is this device is measuring bidirectional so I would expect some signed variables.

Currently I have the decoder set as below.
1,010304UUuuUUux@i0:10,Voltage,V,Voltage,1
1,010304SSss@i1:1000,Ampere,A,Ampere,2
1,010304SSssSSsx@i2:10,Watt,W,Watt,1
1,010304SSssSSsx@i3:10,VA,VA,VA,1
1,010304UUuuUUux@i4:1000,PF,PF,PF,2
1,010304UUuuUUux@i5:10,Hz,Hz,Hz,1
1,010304UUuuUUux@i6:1000,kWh (+),kWh (+),kWh (+),3
1,010304UUuuUUux@i7:1000,kWh (-),kWh (-),kWh (-),3

Voltage, PF, Freq, kWh (+), kWh (-) are definitely unsigned as they only count up.
Ampere should be signed as it defines the direction of the current
Watt and VA should be signed in my opinion to make it visible if the energy is positive or negative, my expectation is that the meter is calculating these values by multiplying (V*A*PF) and (V*A) The moment A is negative the resulting value is also negative.

Then still I see a other problem, the data should be Int32 32bits. If I catch the full 32 bits I get a very high value that is jumping up and down being read, if I cut off the last 4 bits the readout is good, so it looks like one or more of the last 4 bits is not part of the value being read or is being received faulty.

I did not expect reading these meters was so difficult so any insights are welcome

Philip Knowles

unread,
Mar 18, 2022, 3:11:29 PM3/18/22
to Albert Weterings, TasmotaUsers

OK had some time to sit down and look at it

So the decoder format is

SSss = extract a signed word (high order byte first)
ssSS = extract a signed word (low order byte first)
SSssSSss = extract a signed long word (high order byte first)
ssSSssSS = extract a signed long word (low order byte first)

So it definitely needs to be the second group as it’s INT32

So for INT32 a word is SSss as it’s MSB>LSB but I’m not sure what the Tasmota word order is but all the INT32 should be SSssSSss in the absence of further information. If that’s wrong it might need a trailing s  - SSssSSsss

 

PF and Hz are INT16 so they should be SSss

 

The last 2 items are INT64 LSW-MSW (less significant word first, most significant word after) Within a word: MSB-LSB (most significant byte first, less significant byte after) so still signed so, in theory, SSssSSssSSssSSss but some of the examples have xxxxxxxxSSssSSss

 

Not sure if any of those help

 

Regards

 

Phil K

 

Sent from Mail for Windows

 

From: Albert Weterings
Sent: 18 March 2022 18:07
To: TasmotaUsers
Subject: Re: Tasmota and Carlo Gavazzi EM112 Energy meter

 

Thanks Phil for your help so far.

--

You received this message because you are subscribed to the Google Groups "TasmotaUsers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sonoffusers...@googlegroups.com.

Albert Weterings

unread,
Mar 19, 2022, 9:12:03 AM3/19/22
to TasmotaUsers
Thanks Phil, You came up with the solution that works! The only thing I don't understand is what the trailing s is doing exactly, can you explane?

the working script for this power meter is:
>D
>B
tper=500
->sensor53 r
>S
;re-enable publishing at MQTT teleperiod, after 10 seconds of uptime
if upsecs>60
then
tper=10
endif
>M 1  
+1,1,m,0,9600,MODBUS,3,10,01030100,01030102,01030106,01030108,0103010C,01030110,01030112,01030116
1,010304SSssSSsss@i1:10,Voltage,V,Voltage,1
1,010304SSssSSsss@i0:1000,Ampere,A,Ampere,2
1,010304SSssSSsss@i2:10,Watt,W,Watt,2
1,010304SSssSSsss@i3:10,VA,VA,VA,2
1,010304SSssSSsss@i4:1000,PF,PF,PF,2
1,010304SSssSSsss@i5:10,Hz,Hz,Hz,1
1,010304SSssSSsss@i6:10,kWh (+),kWh (+),kWh (+),3
1,010304SSssSSsss@i7:10,kWh (-),kWh (-),kWh (-),3
#

Op vrijdag 18 maart 2022 om 20:11:29 UTC+1 schreef knowles...@gmail.com:

Philip Knowles

unread,
Mar 19, 2022, 12:50:17 PM3/19/22
to Albert Weterings, TasmotaUsers

The ‘trailing s’ changes the word order in INT32 from MSW – LSW to LSW – MSW (or vice versa)

David Goadby

unread,
Mar 19, 2022, 8:45:03 PM3/19/22
to TasmotaUsers
Although not yet connected to Tasmota I have been sorting out another similar device which has the code OB115-MOD. You can get them from Amazon. I picked this device as it is cheaper then the WM112 and uses a current transformer so I didn't have to rewire my incoming supply.

Anyway, this too has RS485/Modbus. The data being read from this unit drove me nuts for a while until I realised that it was IEEE754 format in the form of two 16 bit words (ie 4 bytes) in Big-Endian.

I wrote a Python script to prove my theory and I now get realistic data from it. The next problem is how to integrate it into Tasmota.....

Philip Knowles

unread,
Mar 20, 2022, 12:56:03 AM3/20/22
to David Goadby, TasmotaUsers
IEEE754 is mentioned in the Smart Meter Interface docs.


From: sonof...@googlegroups.com <sonof...@googlegroups.com> on behalf of David Goadby <david...@gmail.com>
Sent: Sunday, March 20, 2022 12:45:02 AM
To: TasmotaUsers <sonof...@googlegroups.com>
Subject: Re: Tasmota and Carlo Gavazzi EM112 Energy meter
 
--
You received this message because you are subscribed to the Google Groups "TasmotaUsers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sonoffusers...@googlegroups.com.

Philip Knowles

unread,
Mar 20, 2022, 3:56:19 AM3/20/22
to David Goadby, TasmotaUsers

The decoder string for IEEE754 is

ffffffff = extract a float value - IEEE754 decode
FFffFFff = extract a reverse float value - IEEE754 decode

 

The SDM530 looks to be a good place to start and I think this might work

>D 

>B 

->sensor53 r

>M 1 

+1,3,m,0,9600,MODBUS,1,1,01040002,01040004,01040006,01040008,0104000A,0104000C,0104000E,01040160,01040162,01040166,01040168,0104016A,

1,010404ffffffff@i0:1,Voltage,V,Voltage,2 

1,010404ffffffff@i1:1,Current,A,Current,2 

1,010404ffffffff@i2:1,Active Power,W,Power,2 

1,010404ffffffff@i3:1,Apparent Power,W,PowerA,2 

1,010404ffffffff@i4:1,Reactive Power,W,PowerR,2

1,010404ffffffff@i5:1,Power Factor,W,PowerF,2

1,010404ffffffff@i6:1,Import Active kWh,kWh,ImportAkWh,2 

1,010404ffffffff@i7:1,Import Reactive kWh,kWh,ImportRkWh,2 

1,010404ffffffff@i8:1,Export Active kWh,kWh,ExportAkWh,2 

1,010404ffffffff@i9:1,Export Reactive kWh,kWh,ExportRkWh,2

1,010404ffffffff@i10:1,Total Active kWh,kWh,TotalAkWh,2

#  

 

The meter definition registers might be 01030002, etc

The IEEE754 might be FFffFFff

If it does work please add it to the Tasmota documentation to help others

 

Regards

 

Phil K

Sent from Mail for Windows

 

From: David Goadby
Sent: 20 March 2022 00:45
To: TasmotaUsers

--

Reply all
Reply to author
Forward
0 new messages