Tasmota: Retrieving sensor data via HTTP request

Created on 5 Jan 2018  路  8Comments  路  Source: arendst/Tasmota

I've looked through the code and there doesn't seem to be any mechansim to retrieve the current state/sensor data in a simple/consumable format (ideally JSON). I know there's MQTT, but I need something where I can periodically poll, and then easily work with the data.

Right now I'm just processing the /ay page - but since you already do some javascript on the fly regex, why not just pass that data around as JSON, and make something that is easily usable by other platforms?

Most helpful comment

As documented in the wiki you have to ability to execute any command from http. As of the latest devs it will output valid JSON only. So I see no problem at all.

Example to retrieve pow status 10 information with http://pow/cm?cmnd=status%2010 returns

{"StatusSNS":{"Time":"2018-01-05T18:26:09","ENERGY":{"Total":25.746,"Yesterday":0.185,"Today":0.148,"Power":8.0,"Factor":0.41,"Voltage":209.7,"Current":0.094}}}

All 8 comments

no, the primary use case for Tasmota is MQTT, the webserver is intended for
initial configuration and troubleshooting, everything there is intended for
human consumption.

you may be able to abuse the console interface, but I think you will have to do
parsing of the output of that as well.

I'm confused by the use-case. If you can use HTTP, why not use MQTT? What are your restrictions? Where are you wanting to call the device from?

If you present more conditions we might be able to help better. For example, you can use node-red to act as a relay and convert the MQTT output to JSON, but not sure if you can support node-red.

My point wasn't to alter the primary use case at all - it was just the point that by slightly modifying how the webpage polls to display data could easily open up a whole different set of options, with no real cost and greater compliance with standards (as opposed to how /ay currently outputs the data.

In terms of use case, I have a little over 150 Sonoff Pow's that I'm using to monitor different devices - and I only need to spot-check the Pow's as a secondary data source. There's a ton of traffic rolling around on the MQTT side, that I was hoping to eliminate since I only need to check devices periodically, not have live detailed state. While I suspect there aren't that many people using as many devices I have, I have to believe there's others who would love to have direct JSON data without introducing another point of failure into their system - or for people who might only want to have one or two devices, and don't want a whole bunch of extra things running just to facilitate a pretty trivial request.

As documented in the wiki you have to ability to execute any command from http. As of the latest devs it will output valid JSON only. So I see no problem at all.

Example to retrieve pow status 10 information with http://pow/cm?cmnd=status%2010 returns

{"StatusSNS":{"Time":"2018-01-05T18:26:09","ENERGY":{"Total":25.746,"Yesterday":0.185,"Today":0.148,"Power":8.0,"Factor":0.41,"Voltage":209.7,"Current":0.094}}}

That last command looks like EXACTLY what I'm after - I tried it on mine though, and it only returns this:

STATUS10 = {"StatusSNS":{"Time":"2018-01-06T05:56:24"}}

You mentioned the latest dev, so I'm assuming this isn't on 5.10.0, but instead on the latest checkins?

Just a followup - I tries this running the same software on the TH16, and I got this:

STATUS10 = {"StatusSNS":{"Time":"2018-01-06T06:13:05","AM2301":{"Temperature":79.9,"Humidity":17.2},"TempUnit":"F"}}

Both show the correct data in the WebUI - and idea why my POW would return no extra data, but the TH16 would?

If I request status type 8, then I get:
STATUS8 = {"StatusPWR":{"Total":161.300,"Yesterday":27.550,"Today":7.180,"Power":1138,"Factor":1.00,"Voltage":242,"Current":4.631}}

Just be interested to know why the inconsistency. Thanks for the answer though, this meets all my needs!

As said before, major changes in the latest dev. Just install and enjoy.

Awesome - thanks for your help and the great project!

Was this page helpful?
0 / 5 - 0 ratings