[SOLVED] Help with sending Command

I want to use OpenHAB to start my heater in my Volvo.

I have used Charles to se what my Android app sends to my car.

POST /customerapi/rest/v3.0/vehicles/MYVINNUMBER/heater/start HTTP/1.1
X-Client-Version: 3.2.1.14229
X-Device-Id: e702fb7ee9366fd
X-OS-Type: Android
X-OS-Version: 22
X-Originator-Type: app
Locale: sv_SE
Authorization: Basic MyCrYptedToken==
Content-Type: application/json; charset=UTF-8
User-Agent: Dalvik/2.1.0 (Linux; U; Android 5.1.1; SM-G925F Build/LMY47X)
Host: vocapi.wirelesscar.net
Connection: Keep-Alive
Accept-Encoding: gzip
Content-Length: 2

{}

How do I send this from OpenHAB?

/Mike

I think your best bet will probably be to use the Exec binding to issue a curl command. If you search the forum for “curl” I think you will see several examples of people using curl in this way.

The HTTP binding can only do GET so it won’t work.

1 Like

Adding to Rich’s advice, you could create a one-line bash script volvo.sh:

#!/bin/bash
curl --silent -X POST https://vocapi.wirelesscar.net/customerapi/rest/v3.0/vehicles/MYVINNUMBER/heater/start -d '{}' -H 'X-Client-Version: 3.2.1.14229' -H 'X-Device-Id: e702fb7ee9366fd' -H 'X-OS-Type: Android' -H 'X-OS-Version: 22' -H 'Locale: sv_SE' -H 'Authorization: Basic MyCrYptedToken==' -H 'Content-Type: application/json; charset=UTF-8' -H 'User-Agent: Dalvik/2.1.0 (Linux; U; Android 5.1.1; SM-G925F Build/LMY47X)' -H 'Host: vocapi.wirelesscar.net' -H 'Connection: Keep-Alive' -H 'Accept-Encoding: gzip' -H 'Content-Length: 2'

Although you may not need any of the X- headers or some others. If running that at a command line turns on your Volvo’s heater, you could then add it as an item using the exec binding:

Switch VolvoHeater { exec=">[ON:/home/openhab/volvo.sh]", autoupdate="false" }
4 Likes

Thank you very much.
I will try this and report back.

/mike

It worked like a charm.

Now I can start the heather and lock the car from OpenHAB.

My next question is how I can parse the position.

I have the Item:

String VolvoPosition {exec=“<[/home/openhab/volvoposition.sh:60000]” }

This give the result:

{“position”:{“longitude”:17.112344765625,“latitude”:60.6234904785156,“timestamp”:“2016-02-02T15:40:16+0000”,“speed”:null,“heading”:null},“calculatedPosition”:{“longitude”:null,“latitude”:null,“timestamp”:null,“speed”:null,“heading”:null}}

How can I transform this into

17.112344765625,60.6234904785156

So I can use it in Google maps.

/mike

add to volvo.items:

Group Volvo
Location VolvoPosition (Volvo) { exec="<[/home/openhab/volvoposition.sh:60000:JS(volvoposition.js)]" }
Number VolvoDistanceFromHome "distance from home [%.0f m]" (Volvo)

create volvoposition.js:

var vp = eval('(' + input + ')');
return vp.position.longitude + "," + vp.position.latitude;

In your sitemap, if you have Group item=Volvo, its contents will contain a map of the Volvo’s location on the Classic UI. Other clients can show a map and there is a wiki page about customizing your own.

You can also calculate the distance in meters from another point in a rule:

import org.openhab.core.library.types.*

rule DistanceFromHome
when
  Item VolvoPosition changed
then
  val PointType home = new PointType("xxxx,yyyy")
  VolvoDistanceFromHome.postUpdate(home.distanceFrom(VolvoPosition.state as PointType))
end
1 Like

Hi

I receive an error in the rule:

Error during the execution of rule ‘DistanceFromHome’: Cannot cast org.openhab.core.library.types.StringType to org.openhab.core.library.types.PointType

Is the item VolvoPosition a Location item? The above rule ought to work if it is, and has other advantages over being a String item.

Hi,

I am interested as well, I found your post last Tuesday, then I could retrieve info from my car.
On Thursday I tried again but the site give a 500 error.

type: Status report
message: InvalidInputCriteria
description: The server encountered an internal error (InvalidInputCriteria) that prevented it from fulfilling this request.

I based on your post the site is still up, any idea what goes wrong?

Thanks
Sjoerd

Hi @Sjoerd

I find that i have to send commands i sequence.

I now use this for position:

#!/bin/bash
RESP=$(curl -s -X GET https://vocapi.wirelesscar.net/customerapi/rest/v3.0/customeraccounts -H ‘X-Client-Version: 3.2.1.14229’ -H ‘X-Device-Id: “mydeviceid”’ -H ‘X-OS-Type: Android’ -H ‘X-OS-Version: 22’ -H ‘X-Originator-Type: app’ -H ‘Locale: sv_SE’ -H ‘Authorization: Basic “MYCRYPTEDLOGIN”’ -H ‘User-Agent: Dalvik/2.1.0 (Linux; U; Android 5.1.1; SM-G925F Build/LMY47X)’ -H ‘Host: vocapi.wirelesscar.net’ -H ‘Connection: Keep-Alive’ -H ‘Accept-Encoding: gzip’)
RESP=$(curl -s -X GET https://vocapi.wirelesscar.net/customerapi/rest/v3.0/vehicle-account-relations/“mycustid” -H ‘X-Client-Version: 3.2.1.14229’ -H ‘X-Device-Id: “mydeviceid”’ -H ‘X-OS-Type: Android’ -H ‘X-OS-Version: 22’ -H ‘X-Originator-Type: app’ -H ‘Locale: sv_SE’ -H ‘Authorization: Basic “MYCRYPTEDLOGIN”’ -H ‘User-Agent: Dalvik/2.1.0 (Linux; U; Android 5.1.1; SM-G925F Build/LMY47X)’ -H ‘Host: vocapi.wirelesscar.net’ -H ‘Connection: Keep-Alive’ -H ‘Accept-Encoding: gzip’)
RESP=$(curl -s -X GET https://vocapi.wirelesscar.net/customerapi/rest/v3.0/vehicles/“MYVIN” -H ‘X-Client-Version: 3.2.1.14229’ -H ‘X-Device-Id: “mydeviceid”’ -H ‘X-OS-Type: Android’ -H ‘X-OS-Version: 22’ -H ‘X-Originator-Type: app’ -H ‘Locale: sv_SE’ -H ‘Authorization: Basic “MYCRYPTEDLOGIN”’ -H ‘User-Agent: Dalvik/2.1.0 (Linux; U; Android 5.1.1; SM-G925F Build/LMY47X)’ -H ‘Host: vocapi.wirelesscar.net’ -H ‘Connection: Keep-Alive’ -H ‘Accept-Encoding: gzip’)
RESP=$(curl -s -X GET https://vocapi.wirelesscar.net/customerapi/rest/v3.0/vehicles/“MYVIN”/attributes -H ‘X-Client-Version: 3.2.1.14229’ -H ‘X-Device-Id: “mydeviceid”’ -H ‘X-OS-Type: Android’ -H ‘X-OS-Version: 22’ -H ‘X-Originator-Type: app’ -H ‘Locale: sv_SE’ -H ‘Authorization: Basic “MYCRYPTEDLOGIN”’ -H ‘User-Agent: Dalvik/2.1.0 (Linux; U; Android 5.1.1; SM-G925F Build/LMY47X)’ -H ‘Host: vocapi.wirelesscar.net’ -H ‘Connection: Keep-Alive’ -H ‘Accept-Encoding: gzip’)
STAT=$(curl -s -X GET https://vocapi.wirelesscar.net/customerapi/rest/v3.0/vehicles/“MYVIN”/status -H ‘X-Client-Version: 3.2.1.14229’ -H ‘X-Device-Id: “mydeviceid”’ -H ‘X-OS-Type: Android’ -H ‘X-OS-Version: 22’ -H ‘X-Originator-Type: app’ -H ‘Locale: sv_SE’ -H ‘Authorization: Basic “MYCRYPTEDLOGIN”’ -H ‘User-Agent: Dalvik/2.1.0 (Linux; U; Android 5.1.1; SM-G925F Build/LMY47X)’ -H ‘Host: vocapi.wirelesscar.net’ -H ‘Connection: Keep-Alive’ -H ‘Accept-Encoding: gzip’)
RESP=$(curl -s -X GET https://vocapi.wirelesscar.net/customerapi/rest/v3.0/vehicles/“MYVIN”/position -H ‘X-Client-Version: 3.2.1.14229’ -H ‘X-Device-Id: “mydeviceid”’ -H ‘X-OS-Type: Android’ -H ‘X-OS-Version: 22’ -H ‘X-Originator-Type: app’ -H ‘Locale: sv_SE’ -H ‘Authorization: Basic “MYCRYPTEDLOGIN”’ -H ‘User-Agent: Dalvik/2.1.0 (Linux; U; Android 5.1.1; SM-G925F Build/LMY47X)’ -H ‘Host: vocapi.wirelesscar.net’ -H ‘Connection: Keep-Alive’ -H ‘Accept-Encoding: gzip’)
LAT=$(echo “$RESP” | jq ‘.position.latitude’)
LONG=$(echo “$RESP” | jq ‘.position.longitude’)
echo “$LAT,$LONG”

/Mike

@watou how do I do the curl with username and password instead of encrypted key?

/Mike

I don’t know how to use the API you’re interacting with. What do its API docs say? curl allows command-line parameters with user name and password, but whether the API you’re using accepts that form is a question in need of research.

Hi all,

I found a python repository that allows to easily query status. I tried adding the post into it, but couldn’t get it to work. Anyone with Python experience? Any thoughts why using a simple post won’t work?

Regards,

Nika.

I figured it out, turns out I was trying to post a heat command whereas my V60 only supports a preclimatization command :slight_smile:

Does this python code support changing values?

/Mike

Not yet, I just created 6 different scripts (lock/unlock/climate on/climate off/blink/honk). My python is so bad, I couldn’t create it myself - I therefore requested it from the original developer, but not sure whether he will implement it :slight_smile:

@nikagl Hi there - Where you able to push the VOC a bit further? My wife is in the process of buying an XC90, and well, I have no saying in all of that except the integration bit with openHAB :wink:

@kgoderis Hi Karel, I don’t do any OpenHAB development, I just responded to this thread because it contained some hints on how to use the vocapi
 check out the github and try to use whatever you find to add things to openhab (and ask openhab developers to actually add it). In my case I use Homeseer and simply created a vbscript that calls the Python Script and parses the status to add the status to virtual devices in Homeseer
 (or turn on the heater / lock the car based on events in homeseer)

@nikagl did you discover some more elements apart from what is published on the various webpages on the subject?

too bad it is not reporting the state of the gearbox. That would be very helpful in my case (I use that on my Tesla to control the open/close of the gate). Also, it the VOC a polling-only service, or is there a subscription mechanism to get events as they happen in the car?

There’s much more status you can get from the vocapi than communicated from the app, but I don’t think I’ve seen something about gearbox. You could use the location parms (long/lat) to open the gate? I query the status periodically but haven’t yet thought of some event that I could use depending on the status of something in the car (I don’t have a gate - I could turn on the lights in the house though)
 I don’t think it works subscription based, although the app must do it somehow, maybe they use Google Firebase Cloud Messaging (FCM) and Apple Push Notification (APN) services?