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

Read a JSON with HC3


jguellec

Question

Hi everyone,
 
I am (desperately) trying to retrieve JSON data from a website that provides French rivers levels (I am living close to the Seine river in Paris, and therefore I am quite interested when the river is getting close to flood height). 
 
I already have a script that is working in Domoticz, but I’d like to have it running on my HC3. The existing scripts can be found here : 

Please login or register to see this link.

 
The website that returns the rivers data can be found here : 

Please login or register to see this link.

 
I’m not a developer, but I think this is standard JSON format ? 
 
I would like to be able to run a scene that will get the data from this website, so I could send notification when it’s getting close to a given level. 
 
I would perfectly be able to code this part, but how to read the JSON is a mystery for me !
 
Any help would be MUCH appreciated :)
Link to comment
Share on other sites

20 answers to this question

Recommended Posts

  • 0

Yes, it is json format. 
 

I use 

Please login or register to see this link.

 to see the structure. Copy paste the output of 

Please login or register to see this link.

 and see the structure. 

 

 

Link to comment
Share on other sites

  • 0
  • Inquirer
  • Well, thanks. I had a chance to look. I’m already using Firefox and I understood the structure of the file. What I don’t know is how to (using a scene or a quick app) I can get the last measure into a local or global variable

    Link to comment
    Share on other sites

    • 0

    If have written a simple QuickApp code which reads the values from the website and if a value is higher than the treshold, it gives a debug message

     

    Please login or register to see this code.

    or

     

     

     

     

     

    Edited by SmartHomeEddy
    • Thanks 1
    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • Wow !! Thank you so much ? !! That’s exactly what I’ve been trying to do. 

     

    Thank you :)

    Link to comment
    Share on other sites

    • 0

    Well, I still don’t know what the readings logically mean. Still work to be done. 
     

    Please login or register to see this code.


     

    At what interval you need to check the data?

    What is the treshold (I took 1.20) when do you need a notification?

     

    It looks like the data represent history and future? 

     

     

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • Well, the refresh can be done every hour, or 30 minutes, it’s fine. 

     

    For the threshold, I’m using 4.00 meters as a first warning. It’s getting serious after 5 meters. 

     

    Yes, the data shows an history. I think it’s in Unix time (from January, 1st, 1970 : 

    Please login or register to see this link.

     

    I didn’t had the time to check, but I’ll have a look later today. 

     

    But again, thanks A LOT for your help. Much appreciated !

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • Ok, I had a look. The site provides 2 days of history. What is interesting is the last value (the most up to date one). 

     

    So I confirm it’s Unix time, but for whatever reason it as 3 extra “0” at the end ?‍♂️ 

     

    For example : 1596448800000 represents 3/8/2020 12:00

    Link to comment
    Share on other sites

    • 0

    The date time can be formatted with this link:

     

        local url = "https://www.vigicrues.gouv.fr/services/observations.json/index.php?CdStationHydro=F700000103&FormatDate=iso&GrdSerie=H&FormatSortie=simple"

     

    (FormatDate=iso)

     

    This is an example debug output: 

     

    Please login or register to see this code.

     

    Link to comment
    Share on other sites

    • 0

    I looked at the data and it doesn't look like a prediction, only history and actual water level. Or is there a timezone thing? 

     

    I did some changes. 

     

    Please login or register to see this code.

     

     

    The changed QuickApp:

     

     

     

     

     

     

    Edited by SmartHomeEddy
    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • Yes, I confirm. There’s no prediction, only observed levels from the last 2 days. 

     

    I’m leaving for few hours, I’ll check your last version once I’ll be back :)

     

    Last question : I’m trying to get the latest value into a global variable. I know I should use the operator “#” to get the latest value in a table, but I’m not quite sure how I can achieve that In this case ?

     

    You’re very kind for the help ! 

    Link to comment
    Share on other sites

    • 0

    Your welcome

     

    On 8/3/2020 at 2:33 PM, jguellec said:

    There’s no prediction, only observed levels from the last 2 days.

     

    Well, the level won’t go up from 1 meter to 5 meter in 10 minutes, so that won’t be a problem. 

     

    On 8/3/2020 at 2:33 PM, jguellec said:

    Last question : I’m trying to get the latest value into a global variable. I know I should use the operator “#” to get the latest value in a table, but I’m not quite sure how I can achieve that In this case ?

     

    Maybe it is more easy to read the value from the QuickApp. I have put the latest value in the Quickapp (and the date in de log) and added some labels. 

     

     

     

     

     

    Edited by SmartHomeEddy
    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • Just tried your last version, it’s working great ! That’s exactly what I was looking for. You’re a boss )) 

     

    Now I will play around with a scene to check the QA value and get push notification with pushover (I know how to do that at least ?). 

     

    But again thanks for your help, and I’ve learn a lot looking at your code and I now better understand how QA works and how to read a JSON file. Much much appreciated ?

    Edited by jguellec
    • Like 1
    Link to comment
    Share on other sites

    • 0

    You're welcome. I had many help from members of this forum. Glad to do something back. Now the sky is the limit ?

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • 1 hour ago, SmartHomeEddy said:

    (The QuickApp is available in the download section)

     

     

     

    Excellent ! I’ll download the latest version later today ✌️

     

    Thanks for the great work 

    Link to comment
    Share on other sites

    • 0
    On 8/12/2020 at 1:07 PM, SmartHomeEddy said:

    (The QuickApp is available in the download section)

     

    Hi 

    Any chance you can share the link again? or the code here.. it is inaccessible.

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