Programmatically send a MQTT message within tasmota firmware.

52 views
Skip to first unread message

BaasKoos

unread,
Jul 3, 2020, 4:28:56 PM7/3/20
to TasmotaUsers

Hi Guys,

I'm looking for some help or a pointer in a direction where to find a guide how the MQTT driver in the Tasmota source is working.

What I'm trying to do is to mod the code (tasmota V8.3.1) to include "Month" and "Last month" as counters for power measurements to be used on PZEMs and PowR2. Which is working so far.
The idea is then to send a MQTT message with the energy usage for the month automatically from the sensor at midnight last/first day of the month.
So to do this I'm looking for a way to programmatically send a MQTT msg. something like a TELE but uniquely identifiable.
I was hoping there could be something straight forward such as sendMQTT(topic,data); but no success yet.

Reason I don't want to keep track of the monthly usage on the sensor management side (rednode) is due to up time and reliability.

Is there any documentation on the source side of Tasmota explaining how things are put together and working?

Any help will be gladly appreciated!

Michael Ingraham

unread,
Jul 3, 2020, 4:41:22 PM7/3/20
to TasmotaUsers
Tasmota retains the total power consumed (of course while the device is operational).

On the NodeRed side of things, you can request this total at any time (`Status 8`), i.e., at the end of the month. So, on the NodeRed side, you've stored the previous month's power reading. Request the current reading from Tasmota (Status 8). Perform the arithmetic (current-previous) in NodeRed for the month's total power consumption. Then store the Tasmota power reading you just retrieved for use next month. Then repeat next month.

Yes, NodeRed may be down right at month end. But so may be the Tasmota device.

Phil

unread,
Jul 3, 2020, 10:37:35 PM7/3/20
to TasmotaUsers
I would suggest your tasmota device is not a secure repository for data, 

If whatever is hosting your node red sys is unreliable i would focus on fixing that for the cost of a couple of retail smart devices you could buy a brand new raspberry pi-0-w psu and sd card.. capable of hosting node red a rdbms and or a timeseries db and mqtt broker 24/7/365 and run watchdog services to ensure max uptime. 

Philip Knowles

unread,
Jul 4, 2020, 12:31:08 AM7/4/20
to TasmotaUsers, Phil
You could achieve this relatively easily by using a rule to store the energy value at 00:00:01 on the first of the month. You'd need to use a Timer triggered at 00:00:01 every day which triggers a rule which stores the day of the month in a variable. If the date=1 it triggers a rule to store the energy value.  Each teleperiod you could then publish the current value minus the stored one.
Alternatively, if you don't really want the long term value you could zero the total using a rule at 00:00:01 on the first of the month which would automatically give you the month's total every teleperiod.
Having said all that, t'other Phil is correct in that Tasmota isn't the right place to do it. I do that use openHAB to store the values in a MariaDB table every day so that I can graph and report the data.

Regards

Phil K

Sent from Outlook Mobile


From: 'Phil' via TasmotaUsers <sonof...@googlegroups.com>
Sent: Saturday, July 4, 2020 3:37:34 AM
To: TasmotaUsers <sonof...@googlegroups.com>
Subject: Re: Programmatically send a MQTT message within tasmota firmware.
 
--
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/19d54086-6a9b-498d-a32b-e0fadc32bfa2o%40googlegroups.com.

BaasKoos

unread,
Jul 4, 2020, 3:49:39 AM7/4/20
to TasmotaUsers
Yes this is my current way of operation. log the total value and reset the counters.

BaasKoos

unread,
Jul 4, 2020, 3:56:48 AM7/4/20
to TasmotaUsers
Thanx Phil, Yea I do agree fixing the the Rednode side is important but I have to run Windows because of software that I piggy back off for my solar and we all know windows have its issues of its own. Updates, reliable starting up programs etc. My Rednode tends to shoot itself in the head as well from time to time.
From my experience with Tasmota over the last 2 years about is that they are allot more reliable than my Windows host.

BaasKoos

unread,
Jul 4, 2020, 3:59:30 AM7/4/20
to TasmotaUsers
Thanx Philip, I will definitely look into the rulez more. looks like they are quite powerful. thanks for the idea!
To unsubscribe from this group and stop receiving emails from it, send an email to sonof...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages