Jump to content

Welcome to Smart Home Forum by FIBARO

Dear Guest,

 

as you can notice parts of Smart Home Forum by FIBARO is not available for you. You have to register in order to view all content and post in our community. Don't worry! Registration is a simple free process that requires minimal information for you to sign up. Become a part of of Smart Home Forum by FIBARO by creating an account.

 

As a member you can:

  •     Start new topics and reply to others
  •     Follow topics and users to get email updates
  •     Get your own profile page and make new friends
  •     Send personal messages
  •     ... and learn a lot about our system!

 

Regards,

Smart Home Forum by FIBARO Team


  • 0

[SCENE + VD] Volvo On Call


riemers

Question

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

Please login or register to see this link.

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)

Please login or register to see this code.

And add this line because it uses it to run every xx minutes, add this to your homeTable too.

Please login or register to see this code.

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)

Please login or register to see this attachment.

 

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:

Please login or register to see this attachment.

 

Then click on update request and find your basic auth line here:

Please login or register to see this attachment.

 

Next up create your scene:

Please login or register to see this code.

As you might have noticed it also uses a GlobalVar called "volvoTable" you need to make this one too.

 

Please login or register to see this attachment.

You can leave the value empty for now.

 

Now install the VD (yes remember the ID to fill it in the jT table)

Please login or register to see this attachment.

 

And then make it fancy with a nice picture for the scene:

Please login or register to see this image.

/monthly_2017_01/manager.png.1d1800245828561dc588d97169e81d03.png" />

And one for the lua.

volvo.png

 

And if all goes well, you can see this one:

Please login or register to see this attachment.

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)

 

 

 

Edited by riemers
Added time and links to homeTable from frank howto
Link to comment
Share on other sites

13 answers to this question

Recommended Posts

  • 0

Hi ! I'am trying to get this to work but i need some help. 

I have put 

Please login or register to see this code.

In  VD like below (is that correct?)

 

local jT = json.decode(fibaro:getGlobalValue("HomeTable"))
fibaro:sleep(jT.time.five)
fibaro:startScene(jT.volvo.sceneid)
volvo = { sceneid = 410, lua = 512, vin = XXXXX, auth = Basic XXXXXX }

 

When i Debug i get following error

[ERROR] 15:21:04: line 5: '}' expected near 'bWFyaxxxx
 
2.. Next i copy your scene.  Do i need to change anything in that ?
 
3. Then i created a variable
volvoTables with values like  /heater/start  /heater/stop
 
Hoping for help
 
//Pewi
 
 
Link to comment
Share on other sites

  • 0
  • Inquirer
  • You don't need to add volvotables with values (just an empty one is sufficient). The VD will set the value's and the scene will pick up the changes. Make sure you quote the basic auth, it need quotes around it or it will fail too.

     

    You can't use a VD to trigger the scene, the scene is triggered by the value in the volvotables. I had to make it like this because of the basic auth and options required on the http call (which is only present in scenes) see if that helps out, if not let me know.

    Link to comment
    Share on other sites

    • 0

    Thanks reimers for your quick reply.

    I am completely new to this so some of my questions may be obvious for you but not for me :-)

     

    1. I have changed in your scene ”User-Agent” and ”X-Device-Id”

    is that correct?

     

    --[[

    %% 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'] = 'mozilla/5.0(Linux; U; Android 6.0.1; SM-G930-F Build/MMB29K)',

    ['X-Device-Id'] = '952a6777b2xxxx',

    ['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

    })

     

    Then i get this:

     

    Please login or register to see this attachment.

     

    2. I changed so i only have ”volvoTabel ”as a variabel without any values

     

    Please login or register to see this attachment.

     

     

     

    3. I have updated VD with ”volvo” is that correct?

     

    local jT = json.decode(fibaro:getGlobalValue("HomeTable"))

    fibaro:sleep(jT.time.five)

    fibaro:startScene(jT.volvo.sceneid)

    volvo = { sceneid = 410, lua = 553, vin = 'YV1DZ8156F27xxxxx', auth = Basic 'bWFyaWUud2lrbHVuZEBtb2Rlcm5la2xxxxxxhxxxxxx' }

     

    Lua is this the number for VD 

     

    Then i get this

     

    Please login or register to see this attachment.

     

     

    Hope you can help me

     

    //pewi

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • Is that a typo? It should be "volvoTable" not "volvoTabel"

     

    The volvo line in jT should be escaped like:

    volvo = { sceneid = 410, lua = 553, vin = 'YV1DZ8156F27xxxxx', auth = 'Basic bWFyaWUud2lrbHVuZEBtb2Rlcm5la2xxxxxxhxxxxxx' }

     

    You had the ' after the word Basic. 

    Change those 2 typo's and see how far you get then.

    Link to comment
    Share on other sites

    • 0

    Typo !   I have changed to volvoTable and the volvo line but i still get the same debug error 

    New line: volvo = { sceneid = 410, lua = 553, vin = 'YV1DZ8156F2xxxxx', auth = 'Basic bWFyaWUud2lrbHVuZEBtb2Rlcm5la29ub21pLnNlOkNhbW9uxxx' }

     

    Please login or register to see this attachment.

     

    and debug in the scene

    Please login or register to see this attachment.

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • The volvo line goes into your HomeTable. So you don't need to edit the script for that.

     

    You should follow the guide from 

    To get the knowledge for that, if you have not already.

     

    I also seem to miss that you need to add this to your homeTable:

    Please login or register to see this code.

    Since it uses that as easy reference when running it each time.

    So your homeTable should consist of a "volvo" line and a "time" line. I'll update the first post with the time line too.

    Link to comment
    Share on other sites

    • 0

    reimers hope you have time for me it's very much appreciated. I try understand how it all fits together.  

    This is what is done so far

     

    HomeTable   

    Please login or register to see this attachment.

     

    I still get error

    Please login or register to see this attachment.

     

    Lua is this the number for VD

     

    and the scene

     

    I copy/paste your scene and get another error now?

    Please login or register to see this attachment.

    Do i need to change anything in your scene? 

     

    i have a predefined table " volvoTable"

     

    What am i doing wrong?

     

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • You need to read up on the thread i posted earlier "Tutorial - Using a Hometable to store device and scene ID's" from frank.

     

    As a simple example, what i normally do is create the homeTable in panels global variables. Then i create a simple scene which has the following code:

     

    Please login or register to see this code.

    This will just set your "HomeTable" variable in global panel with those values. You cannot just add the lines. If you read through the topic of Frank, you will understand why these types of things are handy.

    And feel free to ask, i don't mind helping out, that is what a forum is about. (as long as you do read threads too ofcourse) :-)

    Link to comment
    Share on other sites

    • 0

    Hi this is really great, thanks!! Would possible to add battery levels for hybrid cars? How should I create a notification when the service Status changes? Any help would be appreciated.

    Edited by Helm
    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • Battery status, if that shows up in the volvo app, it should be possible to do too. But that needs a change of code.. i don't have a hybrid. You need to make the calls yourself and see what value's/params they are in order to change the code. So unless your a web guy that can do some api calls with the right headers... i don't think it would be easy to find out. Perhaps you can find the strings from another party like the open source python lib.

    Link to comment
    Share on other sites

    • 0

    Looks interesting!

     

    - Im not using home table so I suppose I can just use my own local "Volvo" table?

    - Purpose of the string "vapi" can't see its used?

    - What about x-device-id and x-os-typ?

     

    Will try to run this using GEA.

     

     

    Edited by KristianO
    Link to comment
    Share on other sites

    Join the conversation

    You can post now and register later. If you have an account, sign in now to post with your account.

    Guest
    Answer this question...

    ×   Pasted as rich text.   Paste as plain text instead

      Only 75 emoji are allowed.

    ×   Your link has been automatically embedded.   Display as a link instead

    ×   Your previous content has been restored.   Clear editor

    ×   You cannot paste images directly. Upload or insert images from URL.

    ×
    ×
    • Create New...