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


Sampling data other than temperature and power


Theo

Recommended Posts

My goal is to observe long-term values from any device. It is written for HC2 but should with some rewriting also work for HC3 probably.

If you want to use this code you have to decide what to observe and how to activate the script.

As I found out, storing data on the HC2 has some caveats so I use ZeroBrane to pull them from my HC2 and gather them in a file on my pc.

ZeroBrane can be installed in any disk location; it ads only a start menu item to your system (

Please login or register to see this link.

 

I have installed a Everspring floodlight, which has limited support on the HC2. See a VD "VD_tuinlamp.json" for on/off switch as attachment.
It contains a PIR-device and a light meter (Lux) which is optimised for low levels and clips at 250 Lux.
For the light sensor I had to configure three parameters:

1: size 2, light-on timer [sec]
2: size 2, light level limit for PIR activation [lux]
3: size 2, reporting cycle [min]

I want to use the light sensor to open and close curtains. Therefore, I wanted to have light level data over multiple days.

 

Step 1

The sampling script, sample_tuinlamp.lua, ads data to a array variable in the lower part of the variables panel ( local _gtable="TuinLuxTabel") in json format.

You also need two data simple data values in the upper part of the variables panel (local _glux="tuinlux" and local _gtime="tuinluxtime").

It contains no triggers, you can add them in the header. I chose for calling it every minute from my check-everything script.
Of course you have to change the number of the device ( local _tuin_lichtsensor=112).

I'm not interested in noise data with a high frequency, so the storage is limited to significant changes:

local TuinLux=deviceNumValue(_tuin_lichtsensor)

local PrevLux=getGlobal(_glux)

local PrevLuxTime=getGlobal(_gtime) --times are stored as os.time() timestamp

 

if ((math.abs(1.0 - ((TuinLux % 250) + 1) / ((PrevLux % 250) + 1)) > 0.05) or (PrevLuxTime == 0))

If this condition is met,

  1. the json data are taken from the global variable,
  2. json.decoded,
  3. expanded with a new data point,
  4. json.encoed
  5. stored in the global variable again.

 

As the data are observed every minute, an extra data point is added 10 seconds earlier when the last recorded change is longer than 1000 seconds ago.

Note that the "tuinlux" global variable is also read in my control script to initiate different actions. My control script needs to know only this variable and to call the sample_tuinlamp.lua:

Please login or register to see this code.

 

The code is very straightforward, no fancy constructs.

 

Question: when you use the save button on the variables panel, the data-table will be cleared. I did loose some days of data points. It took me a while to understand this. Does somebody know the reason for this behavior?

 

Step 2

Run a ZeroBrane script (TuinLux_demo.lua) to pull the data from the HC2 and add them to a local file. If the local file does not exist, it is created.

Some data lines:

Please login or register to see this code.

The data are in a csv format and can be imported into any spreadsheet application to produce fancy graphs.

ZeroBrane has a lot of demos which use a crude graphics library. With some trial an error I got it running.

Happy experimenting! Any comments are welcomed.

Please login or register to see this attachment.

 

 

 

Please login or register to see this attachment.

Please login or register to see this attachment.

Please login or register to see this attachment.

Edited by Theo
correction cycle is minutes, not seconds
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...