Controlling a Tasmota Smart Outlet (with Power Monitoring) According to the Power Usage

After my last post on processing the RF Signals using nodered, I wanted to write on some more MQTT processing functions that I use in my home.

I have several Sonoff S31 (Power Monitoring) Smart plugs that I have flashed with Tasmota firmware and connected to the Home Assistant.

One of these plugs is connected to a power strip that I use as a charging station in my basement. My 18650-battery charger, the 20V BLACK+DECKER tool battery charger, 1S/2S/3S Lipo battery (that goes in my Hobby RC cars) charger and the usual 9V or AAA, AA rechargeable battery charger get their power through this plug. There’s another one of these Tasmotized S31 plug that provides power to the charger of the Polaris Kids ATV that’s in my garage.

 

It’s a pain in the butt to keep a reminder and power off these outlets when the charging is done, because I have to go to there and see if the charging is done by checking the charger LED bulbs. Also, when it comes to batteries, I try to be extra careful and I’m not sure how safe it’s to keep these chargers on for a long period even after the batteries are full.

In the Tasmota console it can be noticed that these power monitored smart outlets publish power usage data to MQTT.  By default this is published every 5 mins. The MQTT Topic would be “tele/<outlet_name>/SESNOR”.

We can see how much current flows through the plug if we look clearly. Here’s how the data looks in Node-red when we convert the JSON payload we get in MQTT to a JS Object.

 

We can fetch the “Current” value from this JS Obejct using a simple Node-red flow like this.

 

 

 

 

 

 

 

 

 

The “Convert JSON to JS Object” node and “Fetch payload.ENERGY.Current” node are configured as :

 

 

After the batteries are fully charged the power flowing through the plug should come to 0 or at least come near to 0. To check this theory, I pushed this Current value we got at the end of above follow to an influxdb database (that I run a docker container) and created time series graph on Grafana (again, running on docker) to see how the current flowing through the plug changed over time.

This is how the graph turned out to be. When the current reached the peak the battery charger started indicating the battery as fully changed, then the current got dropped until it reached 0 after several hours.

 

 

Now I could improve the flow in Node-red to turn of the plug when the current reaches 0A, or  at least when it comes down to 0.05A since by then the battery is already full.

 

If the Tasmota plugs are not connected to Home Assistant, I could still do this by publishing an MQTT message with the payload “OFF” to the topic “cmnd/<outlet_name>/POWER”

Likewise, I could turn on the plug when I plug in the charger and it will automatically turn of after the battery is full. No need to worry about keeping the battery charger on continuously.

As always thanks for your interest and thanks for reading!