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

Use JSON for variables


Question

Posted

Hi all,

 

Based on the following idea i was checking out the possibilities for my HC2: 

Please login or register to see this link.

 

I created several variables and notifications which should send pushover messages when the basic variable is changed from None to the kind of Garbage. 

Now i'd like to create a LUA script to check the current date which can be checked in the output of my JSON file, if there is any kind of Garbage today. 

 

Output is like:

[{"afvalstroom_id":138,"ophaaldatum":"2018-01-02","timestamp":1514847600},{"afvalstroom_id":132,"ophaaldatum":"2018-01-05","timestamp":1515106800}]

In this case my ophaaldatum is the date to check (current date == ophaaldatum), and if these date are the same my predefined variable must be changed to example:

138 = GFT

132 = PMD

 

In this case is the situation when today is 2018-01-02 i'll want a pushover message that i have to remember the GFT garbage.

 

Please help me out, how can i check the JSON file (which is located 

Please login or register to see this link.

) and translate it to change my predefined variable?

 

13 answers to this question

Recommended Posts

  • 0
Guest Turmoil
Posted
Quote

I created several variables and notifications which should send pushover messages when the basic variable is changed from None to the kind of Garbage. 

Now i'd like to create a LUA script to check the current date which can be checked in the output of my JSON file, if there is any kind of Garbage today. 

 

I assume you are using something similar to

Please login or register to see this link.

for both pushover and access to the afvalkalender. The Lua script there decodes the received json with

Please login or register to see this code.

I have not used this further myself but my understanding is that 'result' in this case is a Lua table structure built from the received data. You can see the mapping relationship in a problem of a different sort reported on

Please login or register to see this link.

. From the Lua table you should be able to make simple comparisons as required.

 

I'm new at this myself so I may be barking up the wrong tree but I hope it gives a starter for getting what you wanted.

 

 

  • 0
Guest Turmoil
Posted

I had a bit more time today and could not stop from experimenting. You should be able to use something like the following:

Please login or register to see this spoiler.

 

You'll have to finish the testing for garbage collection info, from what I received you will get an array of collection dates etc but that may be what you are requesting. You will also need to put your pushover data into the request.

  • 0
  • Inquirer
  • Posted

    Ahh thats great, i will test it asap and ill let you know!

    • 0
  • Inquirer
  • Posted (edited)

    i'm checking right now, but on which way you checked the date? because there is no time definition? it gives me correct the message, that there is no message to send but it might be that it doesn't check the correct date in my opinion..

    Edited by Harmen070
    • 0
    Guest Turmoil
    Posted (edited)

    Hi, I see now that I overlooked that your response.data is actually as follows (1st 4 rows only .. and yes you had shown this initially):
     

    Please login or register to see this spoiler.

     

    You may want other tests etc but I think this works in principal. The difficulty is the use of the two dimensional array-table structure.

    Good Luck!

    Edited by Turmoil
    • 0
    Posted (edited)

    Hi @Turmoil , @Harmen070 ,

     

    I like the idea!

     

    After playing a while with the code i managed to get it work. ( @Turmoil , credits to you for providing the code, great work!)

    instead of displaying text, I think I will use an icon which change color orange, green or blue when I have to get the bin out.

     

    I use the HVC URL and it uses other "afvalstroom_id's" but that shouldn't be difficult to change back to the Avalex URL.

    Please login or register to see this code.

    Edit: Added the information below to keep the information together,

             For most of the part the text is a shameless copy of the original post at

    Please login or register to see this link.

     

    This script is for Dutch users, that must place their containers on the street.

     

    Start your browser and go to https://apps.hvcgroep.nl/rest/adressen/zipcode–housenumber
    replace the red things with your info. for the url you can use the url of your collector:

     

    Collector's:

    Cyclus NV:

    Please login or register to see this link.


    HVC:

    Please login or register to see this link.


    Dar:

    Please login or register to see this link.


    Afvalvrij / Circulus-Berkel:

    Please login or register to see this link.


    Meerlanden:

    Please login or register to see this link.


    Cure:

    Please login or register to see this link.


    Avalex:

    Please login or register to see this link.


    RMN:

    Please login or register to see this link.


    Venray:

    Please login or register to see this link.


    Den Haag:

    Please login or register to see this link.


    Berkelland:

    Please login or register to see this link.


    Alphen aan den Rijn:

    Please login or register to see this link.


    Waalre:

    Please login or register to see this link.


    ZRD:

    Please login or register to see this link.


    Spaarnelanden:

    Please login or register to see this link.


    Montfoort:

    Please login or register to see this link.


    GAD:

    Please login or register to see this link.


    Cranendonck:

    Please login or register to see this link.

     

    The output you get looks like this:
     [{"bagId":"0505200000092263","postcode":"3328LN","huisnummer":35,"huisletter":"","huisnummerToevoeging":"","openbareRuimteNaam":"Moestuin","woonplaatsNaam":"Dordrecht","latitude":51.7701971,"longitude":4.6597255,"woonplaatsId":2351,"gemeenteId":505}]

     

    Write down your bagId number! that is the unique key of your address.

     

    The BagID is used in the following URL's:
    Ophaaldagen:

    Please login or register to see this link.

    <<replace BagID

     

    In the output you see "afvalstromen" ID's.
    Use this URL to find information about your ID's:

    Please login or register to see this link.

    <<replace BagID

     

    Adjust your settings in the script: BagId, afvalstromen ID's and collector url. (I only have tested HVC)

     

    Edit: 1-10-2018 new version: changed "zoekdatum" to tomorrow. (I like to have a notification the day before) and changed notification text a bit.

     

     

    greets,

    Remi

    Edited by Remi
    • Thanks 1
    • 0
    Posted

    Thanks, I might have a use for this with my TTS scenes!

     

    Jim

    • 0
  • Inquirer
  • Posted

    I’m testing at the moment but when i’m done i will share the code

    • 0
  • Inquirer
  • Posted

    Can anyone just help me how to schedule this check? i'd like to run this script twice a day, but i doesn't see any option how to schedule this check

    • 0
    Posted

    When I don't know how to do something I begin with a block scene, and convert it to Lua.

    And copy the code i want to use.

     

    Example:

    Please login or register to see this spoiler.

     

     

    • 0
    Posted (edited)

    Question:

     

    In the script we check for the current date, and that's the easy part since the current date is known.

     

    Part of the code:

    Please login or register to see this spoiler.

     

     

    Edited by Remi
    • 0
    Posted (edited)

    Please login or register to see this code.

    Assumes that the result table is sorted on dates. The last date will not get a days2next field.

    result =

    [{"afvalstroom_id":5,"ophaaldatum":"2018-08-02","days2next":14},{"afvalstroom_id":5,"ophaaldatum":"2018-08-16","days2next":1},{"afvalstroom_id":6,"ophaaldatum":"2018-08-17","days2next":7},{"afvalstroom_id":3,"ophaaldatum":"2018-08-24","days2next":6},{"afvalstroom_id":5,"ophaaldatum":"2018-08-30","days2next":14},{"afvalstroom_id":5,"ophaaldatum":"2018-09-13","days2next":1},{"afvalstroom_id":6,"ophaaldatum":"2018-09-14","days2next":7},{"afvalstroom_id":3,"ophaaldatum":"2018-09-21","days2next":6},{"afvalstroom_id":5,"ophaaldatum":"2018-09-27","days2next":14},{"afvalstroom_id":5,"ophaaldatum":"2018-10-11","days2next":1},{"afvalstroom_id":6,"ophaaldatum":"2018-10-12","days2next":7},{"afvalstroom_id":3,"ophaaldatum":"2018-10-19","days2next":6},{"afvalstroom_id":5,"ophaaldatum":"2018-10-25","days2next":14},{"afvalstroom_id":5,"ophaaldatum":"2018-11-08","days2next":1},{"afvalstroom_id":6,"ophaaldatum":"2018-11-09","days2next":7},{"afvalstroom_id":3,"ophaaldatum":"2018-11-16","days2next":6},{"afvalstroom_id":5,"ophaaldatum":"2018-11-22","days2next":14},{"afvalstroom_id":5,"ophaaldatum":"2018-12-06","days2next":1},{"afvalstroom_id":6,"ophaaldatum":"2018-12-07","days2next":7},{"afvalstroom_id":3,"ophaaldatum":"2018-12-14","days2next":6},{"afvalstroom_id":5,"ophaaldatum":"2018-12-20"}]

    Edited by jgab
    • 0
  • Inquirer
  • Posted

    Awesome it is working perfect for me, thank you all guys!

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