Hi,
Here is my working Volvo interface. Most things you can do with your Volvo On Call app, you can also read out and do with the following Scene + VD.
To start off, it is using the jT.hometable so if you don't use that, start using that or strip it away in the Scene/VD. You need to add a entry in your jT.hometable called 'volvo' an example looks like this (yes all here is dummy data and also the 'time' one)
volvo = { sceneid = 14, lua = 512, vin = 'YOURVINNUMBER', auth = 'Basic dsjkh42euwendeh279eynhsfd8o3yg7bo3redgefdhf' }
And add this line because it uses it to run every xx minutes, add this to your homeTable too.
time = { minute = 59000 , five = 299000 , ten = 599000 }
Sceneid will be the number of the scene you will create, the 'YOURVINNUMBER' you can get by going into the technical information in your app (usually settings, then technical information, it will be at the bottom)
Your basic auth is just a username:password which is base64 encoded. To keep it simple and also have a nice tool to test out api's, i suggest you install Postman. You can add your credentials here:
Then click on update request and find your basic auth line here:
Next up create your scene:
--[[
%% autostart
%% properties
%% globals
volvoTable
--]]
local jT = json.decode(fibaro:getGlobalValue("HomeTable"))
local volvotrigger = tostring(fibaro:getGlobalValue("volvoTable"));
local vapi = '/customerapi/rest/v3.0/vehicles/'
local shortUrl = 'https://vocapi.wirelesscar.net/customerapi/rest/v3.0/vehicles/' .. jT.volvo.vin
local trigger = fibaro:getSourceTrigger()
if (trigger['type'] == 'global') then
controlUrl = shortUrl .. "" .. volvotrigger
httpmethod = 'POST'
else
controlUrl = shortUrl .. "/status"
httpmethod = 'GET'
end
local httpClient = net.HTTPClient({timeout=5000})
httpClient:request(controlUrl, {
options = {
method = httpmethod,
headers = {
['Content-Type'] = 'application/json; charset=UTF-8',
['Authorization'] = jT.volvo.auth,
['User-Agent'] = 'Dalvik/2.1.0 (Linux; U; Android 5.1.1; SM-G925F Build/LME47X)',
['X-Device-Id'] = 'b7d2fb2e39436fe',
['X-OS-Type'] = 'Android',
['X-Originator-Type'] = 'app'
}
},
success = function(status)
if (trigger['type'] ~= 'global') then
local result = json.decode(status.data)
if result then
-- print("successful")
-- print(status.data)
if result.carLocked then
fibaro:call(jT.volvo.lua, "setProperty", "ui.Label1.value", "Yes");
else
fibaro:call(jT.volvo.lua, "setProperty", "ui.Label1.value", "No");
end
fibaro:call(jT.volvo.lua, "setProperty", "ui.Label2.value", result.distanceToEmpty);
fibaro:call(jT.volvo.lua, "setProperty", "ui.Label3.value", result.heater.status);
fibaro:call(jT.volvo.lua, "setProperty", "ui.Label4.value", result.serviceWarningStatus);
print(result.serviceWarningStatus)
end
else
print(status.data) -- failed
end
end,
error = function(error)
--errorlog("ERROR")
print(error)
end
})
As you might have noticed it also uses a GlobalVar called "volvoTable" you need to make this one too.
You can leave the value empty for now.
Now install the VD (yes remember the ID to fill it in the jT table)
Volvo_V40.vfib
And then make it fancy with a nice picture for the scene:
And one for the lua.
And if all goes well, you can see this one:
There is more you can do, but for now i think this is sufficient. I own a V40 hence why it says that. Some cars don't have preheating or have other features (but these are most common)
If it doesn't work, let me know since this is my first 'bigger' scene & vd scripts in lua. It uses the global var to send over the url it needs to post to the api, while status commands are get commands for example.
Have fun (this really should be just a proper plugin)