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


Scene as database


jgab

Recommended Posts

Here is a way to misuse the scene structure while we wait for a database...

Persistent key-value store that doesn't suffer from global variables accidentally being destroyed...

Please login or register to see this code.

Much more efficient to keep the lock in a fibaro global but wanted to keep the example "clean"...

Empirical tests with two competing scenes writing and reading data doesn't seem to destroy data for each other. Beware, the lock mechanism is not fool-proof, but seems to work in practice. With only one writer (instance) there is no problem.

Maybe a better place for the HomeTable...

Edited by jgab
  • Like 2
Link to comment
Share on other sites

  • Topic Author
  • The above example is a generalised key/value persistent store. It can be used instead of fibaro globals when you want to store data that the fibaro globals where not meant to store and that gets destroyed whenever something is saved in the variables panel. The performance is worse than fibaro globals (especially writing) but for storing scene configurations and setups it works well - data that is typically set up once when the scene is deployed and then mostly read.

    The background is that I used to have a scene that built me a hometable. Over time I have moved away from automatically trying to build and update the table as the table consisted of more and more hand-tweaked data anyway. And I have it formatted in a way I like with keys in the order that makes sense to me.

    So, I more or less ended up with a scene that just declared a big table and then stored it in a fibaro global. Why don't read that table direct from the scene then? and avoid the problem of accidentally destroying the fibaro global holding the value?

    Ex, scene with ID 14 (only text in scene)

    Please login or register to see this code.

    Code to retrieve the table

    Please login or register to see this code.

    (the table has to be written in json format)

    Edited by jgab
    • Like 3
    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
    Reply to this topic...

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