How can you submit a mosquitto_pub MQTT topic of tele/Sonoff/STATE?

848 views
Skip to first unread message

BeMark Roles

unread,
Aug 13, 2018, 6:09:22 PM8/13/18
to SonoffUsers
If I enter in "tele/Sonoff/STATE" into the console web page of a  Tasmota Sonoff web page, I receive its data back. But if I try to publish the same topic of:

mosquitto_pub -t " tele/Sonoff/STATE"  -m ""

I do not receive any data BACK ( I have omitted the -h, -u, -P attributes from the above line command in this post, but actually used them) 

BeMark Roles

unread,
Aug 13, 2018, 6:22:46 PM8/13/18
to SonoffUsers
OK here is how I got it too work

mosquitto_sub -t "cmnd/Sonoff/state -m""

Philip Knowles

unread,
Aug 13, 2018, 6:25:06 PM8/13/18
to BeMark Roles, SonoffUsers

Cmnd not tele should work. May even work with cmnd.

 

Regards

 

Phil K

 

Sent from Mail for Windows 10

--
You received this message because you are subscribed to the Google Groups "SonoffUsers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sonoffusers...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

 

Philip Knowles

unread,
Aug 13, 2018, 6:29:12 PM8/13/18
to BeMark Roles, SonoffUsers

Meant may even work with stat but glad you got it working

 

Sent from Mail for Windows 10

 

BeMark Roles

unread,
Aug 14, 2018, 5:09:49 PM8/14/18
to SonoffUsers
Thanks for your help.

I have notice that when I subscribe to all topics with the -v option and using the octothorpe "#" (that's 'hash tag' to you youngins or perhaps it's the 'pound sign' for your middle aged people out there). I instantly get a list of all devices and there states in the form of "tele/Sonoff-1/LWT Offline".

My question is there away that I can publish a request that would give me that same list?

Phil

unread,
Aug 16, 2018, 2:11:18 PM8/16/18
to SonoffUsers
IIrc Teleperiod is the setting that governs the frequency of the tele/.....  publications from a device.

So issuing a Teleperiod cnmd with an uber short period will stimulate an almost instant publication after which its been received you can reset the teleperiod again perhaps?

whats the end goal? 

Mark Roles

unread,
Aug 17, 2018, 10:20:18 AM8/17/18
to SonoffUsers

Phil, 
my end goal from my last post would be to show me a list off all devices that are currently online and those that show that they are offline. That would be a great check to see the current status of the complete a home automation setup 

Colin Law

unread,
Aug 17, 2018, 10:32:24 AM8/17/18
to SonoffUsers
If you want to know which are online and which are offline then you can use the MQTT LWT topic for each device. You just need to display the last received message on that topic.

Colin

On Fri, 17 Aug 2018 at 15:20, Mark Roles <kb7...@gmail.com> wrote:

Phil, 
my end goal from my last post would be to show me a list off all devices that are currently online and those that show that they are offline. That would be a great check to see the current status of the complete a home automation setup 

--

Alain Alain

unread,
Aug 17, 2018, 10:46:17 AM8/17/18
to SonoffUsers
The way I do it in my Openhab setup is to clear the state of all my items.
Then publish

sonoff/cmnd/sonoff1/teleperiod 300
sonoff/cmnd/sonoff2/teleperiod 300
...
sonoff/cmnd/sonoff9/teleperiod 300

to all Sonoff and wait for answer.

300 is the default value. Everytime you send a teleperiod command, whatever the delay you choose, the sonoff publish its state (something like this)

sonoff/sonoff1/tele/STATE = {"Time":"2017-10-26T09:03:39", "Uptime":4, "Vcc":3.197, "POWER":"OFF", "Wifi":{"AP":1, "SSId":"wald", "RSSI":50, "APMac":"06:18:D6:2B:2C:F8"}}

No answer -> sonoff not connected

Aymeric

Phil

unread,
Aug 17, 2018, 11:28:54 AM8/17/18
to SonoffUsers
Rather than reinvent the wheel, have you come across the tasmoadmin formaly sonaweb project,  its a light webserved service which lists all you tasmota devices and provides a single page list for details and links to web interfaces for eeach device and also provides a one stop upgrade shop when updating tasmota to the latest release..


fwiw i run it alongside nodered/apache and mosquitto on a pi-0-w 

Mark Roles

unread,
Aug 17, 2018, 1:26:12 PM8/17/18
to SonoffUsers
Phil,
I am looking for fully automating the detection of my devices. Having an MQTT request would be so much fast and easy.  I use TasmoAdmin once in awhile, but it takes too long to search for all my devices. 

Again all that I am just looking for is a MQTT publish command that would list all the devises and actually have the words ONLINE or OFFLINE, just how it does when I subscribe to all MQTT messages with a #.

Phil

unread,
Aug 17, 2018, 2:21:22 PM8/17/18
to SonoffUsers
sorry thought you wanted a quick at a glance view,  i find the tasmoadmin (still wanna call it sonaweb..) 'List' page ideal for that even if i do need to scroll down for everything.

So the method suggested by Alain Alain above is probably best, issue a non changing 'teleperiod 300' command for each device you expect to find in sequence and each device that receives the command (is online) and will respond with publishing a status string/payload.

afaik with a publish/subscribe/broker model wildcard subscriptions in the same topic/path  are simple enough but with discrete independent publishing actors a wildcard publishing event isnt a simple (or feasible???) request..

Colin Law

unread,
Aug 17, 2018, 5:04:09 PM8/17/18
to SonoffUsers
That is exactly what you can get by subscribing to the LWT topics and remembering the current values of those.  How you remember the current values depends on what s/w you are using for the UI.

Colin

Greg from Oz

unread,
Aug 18, 2018, 7:08:32 AM8/18/18
to SonoffUsers
I use the LWT option in MQTT:

lwt.PNG

My software also logs every time the device goes offline. I use Domotiga software.

Mark Roles

unread,
Aug 20, 2018, 11:07:33 AM8/20/18
to SonoffUsers
Greg from Oz and Colin Law,
you both suggest that I should they subscribing to the MQTT LWT. This sounds promising. So what is the exact MQTT command to do this then?

And thanks to all for your timely support,for it is greatly appreciated.

Colin Law

unread,
Aug 20, 2018, 12:50:27 PM8/20/18
to SonoffUsers
On Mon, 20 Aug 2018 at 16:07, Mark Roles <kb7...@gmail.com> wrote:
Greg from Oz and Colin Law,
you both suggest that I should they subscribing to the MQTT LWT. This sounds promising. So what is the exact MQTT command to do this then?

The command to subscribe depends on which s/w you are using to access MQTT and the topic to subscribe to is whatever LWT is configured to in the sonoff device.  I think the default is tele/LWT.  If you subscribe to tele/# you should see it.

Colin

 

And thanks to all for your timely support,for it is greatly appreciated.

--

Greg from Oz

unread,
Aug 20, 2018, 5:11:50 PM8/20/18
to SonoffUsers
mosquitto_sub -v -h your-ip-mosquito-server -t "#"

The above command will show you everything that the server is receiving.

The LWT should show at the beginning as it is persistent I think.

Mark Roles

unread,
Aug 21, 2018, 10:19:03 AM8/21/18
to SonoffUsers
Greg from Oz,
your MQTT command is what I finally used along with it having its data then stored into a text file (mosquitto_sub -v -h your-ip-mosquito-server -t "#" > LWT_data.txt). 

What is also useful, is to do the same with the STATE and SENSOR topics. For once it has been stored into a text file, it is easy to parse out the data and write a simple script that would act upon the data. Such as send me an SMS to my phone telling me when one of my units voltage (Vcc) is low.

Greg from Oz

unread,
Aug 22, 2018, 3:09:29 AM8/22/18
to SonoffUsers
You don't have to do the sensor ans state topics because the # is the top level and those topics should be underneath it.

If you are going to run a script to output to a file all the time you create a script and run this:

#!/bin/bash
#If the script is already running then exit
if [[ "`pidof -x $(basename $0) -o %PPID`" ]]; then
    echo Already running
    exit
fi

mosquitto_sub -v -R -h 192.168.0.164 -t "#" | while read RAW_DATA
do
  echo $RAW_DATA # replace with your task of choice
  # you can grep stuff and do whatever in this loop
done


You put the text above into a script and run it with & at the end and it will run in the background forever. Put it start up of server.
eg /usr/local/bin/test.sh &

The -R flag prevents "stale" messages from being processed

Just an idea as I am not sure how you want to do what you want.
Reply all
Reply to author
Forward
0 new messages