InitialState.com

I would like to send some data from Openhab to initialstate.com to whip up a nice looking dashboard.
i’m not sure if i can do it from a PUT in my rules/actions, or how to specify the header/body. is this commonly done? it would be very handy.
http://support.initialstate.com/knowledgebase/articles/590091-how-to-stream-events-via-restful-api

seems like this might be interesting to you:

http://support.initialstate.com/knowledgebase/articles/590085-how-to-stream-events-in-python

combine with jsr-233 binding and jython.

thanks, i want to send data from inside a rule so i’m at a loss how to convert the curl to a POST of some kind. i’m finding information like the link below, which i’ll work on tonight and see how far i get.
this initialstate.com looks really interesting. hate that their name is essentially unsearchable on an openhab board though…
Problem using executeCommandLine and curl

thanks

Have you looked at the HTTP actions?

There is an action for GET, POST, PUT, and DELETE. If it works with curl I think it will work with these commands without problem.

from the InitialState.com website they have examples for python and arduino that rely on their libraries to function.
then they give this RESTful example, which i hope to do from inside a rule or script in OH.
so, it seems the challenge is to turn this curl into a POST or something. not very experienced at REST stuff, but learning fast.

from http://support.initialstate.com/knowledgebase/articles/590091-how-to-stream-events-via-restful-api

curl --include
–request POST
–header “Content-Type: application/json”
–header “X-IS-AccessKey: YOUR_KEY”
–header “X-IS-BucketKey: curl_example_bucket”
–header “Accept-Version: 0.0.1”
–data-binary “[
{
“key”: “temperature”,
“value”: “22.2”
},
{
“key”: “power”,
“value”: “6”
},
{
“key”: “status”,
“value”: “:thumbsup:
},
{
“key”: “current”,
“value”: “156”
},
{
“key”: “door”,
“value”: “open”
}
]”
https://groker.initialstate.com/api/events

If you must have a message body like this, the approach recommended on the wiki is to use the Exec binding out the executeCommandLine actions and call curl.

i’m trying to send data to InitialState.com and use it as my dashboard using a curl command in an executeCommandLine statement in a rule.
i’ve escaped out the spaces with @@ and the " with " but no luck.
the errors generated seem to make sense, until i fix them all and then i’m left with this.

this works from the command line fine.
curl -k -H “X-IS-AccessKey: xxxxxxxxxxxxxxxxxxxxxx” -XPOST “https://groker.initialstate.com/api/events” -H “Content-Type: application/json” -H “X-IS-BucketKey: testkey” -H “Accept-Version: 0.0.1” --data-binary “[{“key”: “TGAL”,“value”: “9100.2”,“epoch”: “1450651667”},{“key”: “AIRTEMP”,“value”: “66.6”,“epoch”: “1450651677”}]”

and then i turn it into this to use in a rule (with much effort along the way and errors that make sense and then fixed.)
var results = executeCommandLine(“curl@@–insecure@@-H@@“X-IS-AccessKey: xxxxxxxxxxxxxxxxx”@@-H@@“Content-Type: application/json”@@-H@@“X-IS-BucketKey: testkey”@@-H@@“Accept-Version: 0.0.1”@@-d@@[{“key”:“TGAL”,“value”:“3333.2”,“epoch”:“1450653700”}]@@-XPOST@@https://groker.initialstate.com/api/events@@”,5000)

and throws this error.
100 112 100 70 100 42 33 20 0:00:02 0:00:02 --:–:-- 33{“code”:“InvalidContent”,“message”:“Invalid JSON: Unexpected token k”}

i’ve fixed problems with the json data segment, that were giving appropriate errors. other things, but don’t know what is left to fix in it.
perhaps there are other ways to do this, but i would like to be able to easily pass item states to InitialState.com while in a rule. i’ve tried to use a script to do this, but it still needs to process this curl, and need to pass in my variable data…
any help would be appreciated. also interested in any alternatives to InitialState.com for prototyping a dashboard with graphing…

thanks
mike

Do you need to escape the ‘{’ and ‘}’? I don’t have a lot of experience with this so it’s only a WAG.

You can do this by writing your script to accept command line arguments and passing your variables to the script in your call in executeCommandLine. So it would be

var results = executeCommandLine("myCurlScript.sh " + variable1 + " " + variable2)

That will let you use a more normal curl command from your script and avoid these weird parsing errors and still pass variable data.

yes, it is the thing to do, and i just made it work.
would have be nice to do it inside a rule, but i’m not the first to mention that, it seems.
thanks for the help

Michael,

I am looking to do something similar, mainly to send weather data that OpenHab is already collecting to IntitalState.com

Did you ever get this to work from inside a rule?

Hi,
i want do it too. Any help?
Thanks
Petr