Power monitoring with an XTM18S and MQTT


The rst cause: 4 is a watchdog reset, it might be something taking too long to execute (wi-fi or MQTT connection, web interface…).

Does it keep rebooting?


thanks for sharing.
I am trying to setup a power monitor like yours but directly connected to raspberry…
My doubt is about the wiring.
You connect directly to Wemos at pin D6 right? But the XTM power out Open-Collector (SO, DIN43864), max 36V/30mA CC… so you can burn out your wemos? Or you put some resistence in the middle?
I don’t understand why you connect directly…
Thansk a lot,



Hi, I have no problems connecting directly to the Wemos and it never gave me any trouble for this last few months. If you look at the first post on this thread, the original project is connected the exact same way. The pulse is very short (90ms i think) and <= then 27mA.


ok very short but very high! 36V!
Other proiect use a resistance.
Have you measured the VOUT?



No, i didn’t measure. If you’re worried about that just put a resistence.



I don’t know what happens… but without any change IT’S WORKING FINE including web server… in a SONOFF BASIC, of course :slight_smile:

THANK YOU! :hugs:


Your welcome @Pharizna! I’ll include the Sonoff Basic in the list of compatible boards.

P.S: Can you please send a photo of the connections you’ve made on the Sonoff?


Of course :slight_smile:
Here it is a “sketch” from our friend @Lantzi


Last question

In your code your are using

define PULSE_FACTOR 1000

But for the XTM18S the ratio is 2000 pulses / kWh



You should change the value of PULSE_FACTOR to 2000 or it will count the double…


I did it. It was only to confirm it

Thank you



Yes, directly. I used it for a whole week without issues but I understand your concern. I am aware of my limitations and that’s why I included a disclaimer in my post.

No. Since the pulse is so short, I guess we should measure with an oscilloscope, which I don’t own. I suposse my standard voltimeter is not appropriate for such dynamic signal.

@j.assuncao , thanks for sharing your code in github. It has plenty of features! Nice work!

@Pharizna , thanks for the feedback with the SonOff. Just out of curiosity, are you using it for overall home electricity consumption?


Of course :slight_smile:

It’s my main goal … but previously I’m testing the system measuring only single “external” devices and then I’ll connect in my home fuse box :sweat_smile:


@Pharizna, be carefull when you connect the XTM to the fuse box. You have to use a model suited to your total consumption in terms of Amps.


Thank you Jorge

My home main disjuntor is 25A and my XTM18S current range is 0.25 - 32A


hi, this is the project i was looking for. i’ve ordered today 1 xtm18sa (with lcd display and 50A), my goal is to monitor entire apartment consumption. i live in italy with 3 KWh of max consumption and 25A of fuse box.

I’ve wemos d1 and nodemcu availables.

it’s possible to connect this to emoncms? it’s an opensource project with apis avaibles and their own equipment also use esp8266 to connect to emoncms. thanks and sorry form my bad english :slight_smile:


hi, @hangy! I don’t know if it’ll work with EmonCMS because i don’t use it but HA can connect to it. Probably if you send the readings to EmonCMS from HA it is possible.



I’ve just installed the “device” to monitor my home consumption … and it’s working


Wow, that’s awesome. Definitely, I have to take a look at Grafana. Congratulations!
Did you put the device in the electric box at the entry of your house? (¿en el cuadro eléctrico a la entrada de casa? :slight_smile: ). Did you ask for help to a professional?


@Pharizna Great work! With some math (and sensor templates) you can get other values like Apparent Power (kVA) and Current (A). I’m also using a couple of automations to get daily and monthly consumption.

@timseebeck If you know a little about electricity you can do it yourself. It’s really not a big deal…

I’m now working on a new version of the meter that uses the ACS712 AC current meter to be use on extension sockets for example.