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

JSON data - can't find the right way of grabbing info from data


Question

Posted

Hi

 

I need to get the lockStatus from this, but I can't find the right way..

data.armState.statusType works..

but 

data.doorLockStatusList.lockedState doesn't. 
There's a [ in doorLockStatusList that isn't there for armState - but I don't know how that changes the way I need to get the info.
data.doorLockStatusList.lockedState.lockedstate doesn't work.
if I add data.doorLockStatusList.0.lockedState lua crashes
if I add data.doorLockStatusList[0].lockedState i get "nil" as result
if I add data.doorLockStatusList[lockedState] I get "nil" as result.. 
What am I msising?

 

{
"accountPermissions": {
"accountPermissionsHash": "###########################"
},
"armState": {
"statusType": "DISARMED",
"date": "2021-06-29T15:01:39.000Z",
"name": "Fibaro Verisure",
"changedVia": "REMOTE_APP"
},
"smartPlugs": [],
"doorLockStatusList": [
{
"deviceLabel": "2CBK DK42",
"area": "Fordør",
"userString": "Tina Thomsen",
"method": "TAG",
"lockedState": "UNLOCKED",
"currentLockState": "UNLOCKED",
"pendingLockState": "NONE",
"eventTime": "2021-11-06T10:28:01.000Z",
"secureModeActive": false,
"motorJam": false,
"paired": true
}
],

3 answers to this question

Recommended Posts

  • 0
Posted

Please login or register to see this code.

It's an array so you need to pick out an element from the array - in this case the first [1] element.

Beware, the reason it returns an array is that there can be multiple items in the array.

I don't know hoe the lock responds but it could be a list of previous users unlocking... and if you are lucky the last is the first.

 

  • 0
  • Inquirer
  • Posted

    @jgab.. that worked BUT...

     

    why... when the json looks like this in json2table?:

    it says '0' .. which I tried... 

     

    Please login or register to see this attachment.

    • 0
    Posted (edited)

    Because many other languages index arrays from 0 - like javascript and probably the 'json2table' tool you used.

    Lua index all arrays starting from 1.

    Edited by jgab

    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...