#!/bin/sh
NanoStatus=`curl -X GET -H "Content-Type: application/json" -d '{"on" : {"value":true}}' "http://192.x.x.x:16021/api/v1/xxx/state/on"`
echo "NanoStatus is: "$NanoStatus
#
curl --header "Content-Type: text/plain" -H POST "http://192.x.x.x:8080/rest/items/NanoStatus" --data "$NanoStatus"
#
NanoSelect=`curl -X GET -H "Content-Type: application/json" -d '{"on" : {"value":true}}' "http://192.x.x.x:16021/api/v1/xxx/effects/select"`
echo "NanoSelect is: "$NanoSelect
#
curl --header "Content-Type: text/plain" -H POST "http://192.x.x.x:8080/rest/items/NanoSelect" --data "$NanoSelect"
#
NanoBrightness=`curl -X GET -H "Content-Type: application/json" -d '{"on" : {"value":true}}' "http://192.x.x.x:16021/api/v1/xxx/state/brightness"`
echo "NanoBrightness is: "$NanoBrightness
#
curl --header "Content-Type: text/plain" -H POST "http://192.x.x.x:8080/rest/items/NanoBrightness" --data "$NanoBrightness"
#
I get this:
2018-12-28 02:58:00.056 [ome.event.ItemCommandEvent] - Item 'NanoStatus' received command {"value":false}
2018-12-28 02:58:00.081 [ome.event.ItemCommandEvent] - Item 'NanoSelect' received command "Earth Day"
2018-12-28 02:58:00.107 [ome.event.ItemCommandEvent] - Item 'NanoBrightness' received command {"value":46,"max":100,"min":0}
How can i work with the value {“value”:false} or {“value”:46,“max”:100,“min”:0}.
Or is something wrong in my curl request?
I am searching for examples, but cannot find something like this.
Thanks for help and greetings,
Markus
Hi namraccr.
I have only this description in the api documentation.
curl --location --request GET "http://192.168.x.x:16021/api/v1/Add-a-user-to-generate-auth-token/state/on"
and example request:
{
"value": true
}
And in my script, i send a request for this state and give the answer to the item Nanostatus. Line 2 and 5. Sorry, but i don’t know what you mean. Can you explain me, what you need?
Greetings, Markus
Can you post the items and/or the rules that you use to get the value into OH
You will need a JSONPATH transformation to extract the value from the generated JSON strings
rule "Skript nanoget.sh alle 30 Sekunden laden"
when
Time cron "0/30 0/0 * * * ?"
then
executeCommandLine("/etc/openhab2/scripts/nanoget.sh", 10000)
//logInfo("Skript nanoget.sh", results)
end
Install the JSONPATH transformation service in the PaperUI
rule "Skript nanoget.sh alle 30 Sekunden laden"
when
Time cron "0/30 0/0 * * * ?"
then
val jsonString = executeCommandLine("/etc/openhab2/scripts/nanoget.sh", 10000)
//logInfo("Skript nanoget.sh", results)
NanoStatus.postUpdate(transform("JSONPATH", "$.value", jsonString))
end
2018-12-29 18:13:00.062 [ome.event.ItemCommandEvent] - Item 'NanoStatus' received command {"value":true}
2018-12-29 18:13:00.065 [vent.ItemStateChangedEvent] - NanoStatus changed from % 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 36 100 14 100 22 1755 2759 --:--:-- --:--:-- --:--:-- 3142
NanoStatus is: {"value":true}
% 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 14 0 0 100 14 0 2239 --:--:-- --:--:-- --:--:-- 2800
% 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 33 100 10 100 23 1377 3168 --:--:-- --:--:-- --:--:-- 3285
NanoSelect is: "Snowfall"
% 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 10 0 0 100 10 0 6724 --:--:-- --:--:-- --:--:-- 10000
% 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 53 100 30 100 23 4224 3238 --:--:-- --:--:-- --:--:-- 4285
NanoBrightness is: {"value":30,"max":100,"min":0}
% 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 30 0 0 100 30 0 19480 --:--:-- --:--:-- --:--:-- 30000 to {"value":true}
And this is the rule:
rule "Skript nanoget.sh alle 1 Minuten laden"
when
Time cron "0 0/1 * * * ?"
then
val String jsonString = executeCommandLine("/etc/openhab2/scripts/nanoget.sh", 10000)
//logInfo("Skript nanoget.sh", results)
NanoStatus.postUpdate(transform("JSONPATH", "$.value", jsonString))
end
Nanoleaf is a light and i can switch it by the script from Dennis (mrJakez).
But i miss the actual state of the item. When i use the light for notification warnings, i have to know, if the light is On or OFF and which scene is on, to the set the previous state. Therefore i wrote the script and now i get the item values. But cannot work with it. I think the script is not right too, because i have copyed it and make it runnable with my knowledge.
rule "Skript nanoget.sh alle 1 Minuten laden"
when
Time cron "0 0/1 * * * ?"
then
executeCommandLine("/etc/openhab2/scripts/nanoget.sh", 10000)
var String jsonString = (NanoStatus.state as StringType).toString
var String jsonString1 = (NanoBrightness.state as StringType).toString
NanoStatusK.postUpdate(transform("JSONPATH", "$.value", jsonString))
NanoBrightnessK.postUpdate(transform("JSONPATH", "$.value", jsonString1))
end