Need some help, please. Running a rule that executes a shell script. Shell script returns a JSON string that I wish to assign to different items. Tried running this with ‘executeCommandLine’ and ‘transform’ which I have used before. Both methods work but the returned string has a bunch of other data in it I do not want or recognise. When I execute the shell script from the command line it works perfectly and returns just the JSON data.
% Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 0 0 0 0 0 0 0 0 --:–:-- --:–:-- --:–:-- 0 100 106 100 106 0 0 185 0 --:–:-- --:–:-- --:–:-- 185 [{“id”:“01EW1DZSCT20KY4PQWCZ7DXE53”,“nmi”:“6407294703”,“channels”:[{“identifier”:“E1”,“type”:“general”}]}]
The data that I do not recognise is the prepended data in the rule output. Specifically
% Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 0 0 0 0 0 0 0 0 --:–:-- --:–:-- --:–:-- 0 100 106 100 106 0 0 185 0 --:–:-- --:–:-- --:–:-- 185
No idea what this is.
My rule is as follows:
rule "AmberAPI"
when
// Every 15 Seconds
Time cron "*/15 * * * * *"
then
logInfo("AmberAPI", "Rule started: ")
var String AmberAPI_JSON = executeCommandLine(Duration.ofSeconds(5), "/usr/bin/sh", "/home/openhabian/AmberAPI.sh")
logInfo("AmberAPI", "Script returned: {}", AmberAPI_JSON)
val String id = transform("JSONPATH", "$.id", AmberAPI_JSON)
val String nmi = transform("JSONPATH", "$.nmi", AmberAPI_JSON)
val String channels = transform("JSONPATH", "$.channels", AmberAPI_JSON)
logInfo("AmberAPI", "JSON to Var Output: {}, {}, {}", id, nmi, channels)
sendCommand(AmberAPI_JSON2, AmberAPI_JSON)
logInfo("AmberAPI", "Rule ending...")
end
Searched for hours trying to find a solution but so far found nothing that helps. Any help would be greatly appreciated.
Weird! Not sure what process would be sending this sort of output to the console. I have just checked a few things and nothing jumps out as a root cause.
Not sure if this help at all but I like your idea about stripping out the rubbish until the start of the JSON data. I will give this a try. Not sure how to do this within a rule as typically I would use a shell script. Any pointers would be much appreciated.
var rubbish = = executeCommandLine( ... )
var interim = rubbish.split("[{") // should be fairly unique to JSON part
var AmberAPI_JSON = "[{" + interim.get(1) + "[{" + interim.get(2) // but there are multiple parts
Undoubtedly more elegant ways to do it
However, I think what you really want to do is use curl with -s option to stop it blabbering about what it is doing.
I take it you’ve been working to get a feed from Amber Electric’s API into openHAB - have you had success based on the above? I can’t find much discussion of it here, and the API discussion linked from Amber’s dev page seems to be all about HomeAssistant.
I’d really like to know what you’ve been able to do and how, if you don’t mind sharing!
I have a curl script doing the API feed and a couple of rules triggering the script and reading the data being returned. Working really well albeit a first pass.
I assume you are local to Melbourne. Happy to discuss this further over the phone. Do you have a number I could call you on?