-
Notifications
You must be signed in to change notification settings - Fork 184
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issues with Formatting json #294
Comments
Dear Cory, thanks for reporting this. It is probably about the fact that "Temperature" is nested inside the main dictionary, right? Accessing the data through JSON Pointer might help here in the future, see also #303. With kind regards, |
Hi, I've been using mqttwarn to parse mqtt topic's to influxdb. Works perfectly. I'm now looking at parsing nested JSON messages and this is where I get stuck (I'm a self taught hobbiest). I see there is a workaround for nested JSON included in README.md. Would you be able to advise if that will work with multiple payloads? This is my received JSON message:
I'm happy to "have a go" but if you could comment I'd appreciate it. Many thanks, Roland |
@hillnet I wrote the workaround in the README. It will work for your situation -- multiple temperature sensors with just one Sonoff? nice, I want to try that one day :-) -- it will take just a little more coding. The problem is that one message can create only one InfluxDb entry, by default. What you want is for each message to be processed twice. So we'll make mqttwarn do that. Make two Python functions like in the example, one pulling out the "-1" value and the other pulling out the "-2" value. Then create two topic sections in That should do it. |
Thanks @rgitzel , I'll have a go! |
Hi @rgitzel , For reference, here is the nested JSON from TASMOTA
My functions.py entry looks like this:
I took
to mean the following, but I must have misunderstood as it dosn't "trap" the mqtt message:
The topic being published to mqtt is: If you have time to provide further guidance I'd appreciate it. Thanks. |
Hi @hillnet, you're close! Add
I would also rename your second function to Cheers! |
Thank you @rgitzel . This is awesome...I was sooo close. It is now working as you documented. I need to do some work to get the "format" correct for influxdb, but that won't take too much now I have these single line data inputs. I appreciate you taking time to help. -- |
Aplogies for continuing this, and if I'm now off topic please say so. As noted above I can now "un-nest" nested JSON payloads. What I am struggling with is getting them inserted into influxdb. This is what I have in my mqttwarn.ini file (as a test before trying influxdb as the target):
This writes into the file as: This looks pefect for my current schema, but when I change the target to I get the following errors in my mqttwarn.log file:
I've read the section on "Line Protocol" (and noted the format below) on the InfluxDB website, and it appears this should work, but I am obviously missing something.
I don't (yet) understand why my config gets transformed into Aploogies for the "newbie" noise, but I hope one more steer will resolve this. -- |
@hillnet Try changing your format:
The plugin will insert a tag for I suppose the examples I wrote are misleading, as they don't work with that plugin. What I'm doing myself is writing full Influxdb lines out to topic This gave me more control: I can use the timestamp from message, not from mqttwarn, and keep the original topic name. I suppose another option would be to change the plugin to allow more control. Hmmm. |
Thank AGAIN @rgitzel, and yes I should have read the influxdb plugin guide last time :-( The partial solution was to actually have
My last remaining issue is to add a tag to each sensor "entity". At the moment I get 3 temperature values (1 per sensor, all bundled in the original nested JSON) and no way to identify them uniquely in grafana. The influxdb plugin treatment of the
I'll keep trying and see if I can come up with something... I am now almost sorted and can use TASMOTA on all my devices knowing mqttwarn can parse the nested JSON data to influxdb. -- Roland |
@hillnet You might consider pulling the latest version of mqttwarn. Judging by the code you copy/pasted from influxdb.py, you're not looking at the latest version (on your local machine, I assume?), which now includes some enhancements to the InfluxDB service (and expanded readme/format example). |
Thanks @jwyse , You are of course correct. Rookie mistake of not updating.... I cloned the repo today and now have success. For the record, my
This gives the following log entry:
[Edit: deleted {Timestamp} from "format = " as grafana seems to have an issue with it. Using server timestamps for now] I truely have success now. FYI @rgitzel Thanks for all the help. mqttwarn is an awesome piece of software @jpmens & @amotl -- |
I totally second @hillnet on mqttwarn being fantastic work and also thanks for the influxdb service plugin - I use it frequently. Most recently I came across a scenario where using the InfluxDB service pluging, along with a simple format string the Influx posting did not work. I am responding to this particular issue as reading through the above, it seems my scenario is related. Different from the formerly discussed solutions, I did not want to add an extra tag as I am fine and sufficient with the topic itself being added as tag: Inbound JSON String mqttwarn.ini
which resulted in the following error log entry Looking at the code in
This did not work for me, hence I've enhanced the code to deal with different format string scenario's and in particular when no additional tags are provided. I'm not an expert coder but you may want to look at pull request #376 and eventually consider the changes to be added in the one or other way. Thanks and best - Oliver |
As @hillnet signals goodness
and #376 contributed by @jacques42 as been merged already, I believe it is safe to close this issue. Please reopen if any of these things outlined within this discussion does not resolve the problem you have been observing, @the-butterfry. |
P.S.: As both a side note and a shameless plug from my side, I would like to mention that Kotori also received a Tasmota decoder the other day through daq-tools/kotori@77b94fa1 and daq-tools/kotori@5f5d9511, see also [1,2]. [1] https://getkotori.org/docs/decoders/ |
I'm trying to get the Format to correctly parse out json received with the File handler plugin.
Here's an example string that is being received.
{"Time":"2018-03-13T20:16:55","DS18B20":{"Temperature":19.8},"TempUnit":"C"}
All I want to do is pull out the {Temperature} data into the File, discarding the rest. I can't seem to make it work. Any tips?
P.S.
I can make {time} work just fine, but as soon as I try to transform {temperature} is where the problems starts.
The text was updated successfully, but these errors were encountered: