-
-
Notifications
You must be signed in to change notification settings - Fork 223
Add machine-readable output #209
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
Comments
None of the commands of the cli tool output json, but a PR to add support for defining the output format would be welcome! |
I'm sure there's a cleaner way but this works as a temp solution:
And if you want to just grab the data from a key:
|
I hacked something togethor to make a working JSON output.
The debug output has the JSON we need.
Using SED and AWK. I managed to split the JSON from other debug text, split each output into sections and then only print one output, which has all the information we need. We can then parse using JQ. I've tested this using a KP115 (smartplug) and KP303 (smartstrip). I also have an HS110 which outputs non-sensical multi-line JSON so JQ can't parse it.
This gives: For my working KP115, as an example, I can fetch the emeter information using jq Regarding
Simply the output from the device is all we'd want. Any calculations or interpretation aren't needed. |
@lazynooblet (and everyone else), feel free to test the linked PR, it should cover ~all commands if I didn't miss something. The simplest way to use the raw data is just access the output from
|
@rytilahti this works great thank you! Its also much faster. Whilst there was a pause of half a second as the commands went back and forth, now the response is instant. I can finally remove that monstrosity of sed/awk/jq 😏 Thanks again! 🥇 |
CLI Module run with "sysinfo" flag or datatypes returned in JSON format are invalid as variable names and string values are encapsulated with single-quotes. The JSON standard requires double-quotes. This is making it difficult to pipe data from the script to any service/application that expects proper JSON data without running it through a wrapper that does a find/replace on the single quotes.
The text was updated successfully, but these errors were encountered: