ClimateDataCalculation
Posted: Thu Nov 06, 2014 1:25 pm
This plugin can be used to collect and calculate climate data like rain level, temperature and humidity from wireless sensors.
- Rain, temperature and humidity data can be collected with a RFXtrx
- Temperature and humidity data can be collected with a TellStick Duo (I am lacking a TellStick Duo log sample from a rain sensor to complete the code)
- Data from other devices like z-wave and 1-wire can easily be added and is on the 'ToDo list' but I need sample events from the EG log.
You can download the plugin from here (check the section 'Current plugins just ready for prime time'):
http://krambriw.net
The plugin supports the following features:
- You can configure how frequently you want to save readings (default every 10 minutes)
REVISED:
- For rain, the plugin calculates two moving averages, one fast and one slow. This is then used to create events when the lines are crossing each other. The more readings you select, the slower the response to changes. This is a very useful function to when you are looking for trend shifts (in this case, if rain is increasing or decreasing during time).
- In addition you can add a hysteresis value that will set the upper and lower band (+/- hysteresis/2) for the fast moving average before it triggers an event
- For temperature and humidity, the plugin calculates one moving average. This is then used in combination with the set-point and optionally the hysteresis to create events when the lines are crossing each other. The more readings you select, the slower the response to changes. This is a very useful function to avoid too many status changes when for instance controlling heaters with on/off control equipment (you might temporary open a door or window but the heater should not react immediately)
- In addition you can add a hysteresis value that will set the upper and lower band (set-point +/- hysteresis/2) for the moving average before it triggers an event
- You can select if you want to use the rule evaluation that will generate those events or not. Currently I have only one rule 'equal-less-greater' that will generate events when moving average gets equal, less or greater than its reference.
- All this works for rain level, temperature and humidity data
To collect data I use actions in macros. This simplifies your configuration, you just drag & drop the sensor event in the macro you created.
Sensor data is collected on a per sensor exclusive sqlite3 database table. The more frequent you have selected to store data, the quicker the size of your database will grow.
For all sensor types, there are two main actions
- A capture action to capture sensor data
- A reset action to clear all readings captured from the sensor
Currently only available for rain level data you also have the following actions
- RainReport action reporting the total rain between configured date & time stamps
- RainRequestSearch event triggered action searching for total rain between in event payload provided date & time stamps
- RainRequestQuery action searching for total rain between provided date & time stamps and returning the result as variable, foreseen to be used in scripts or other plugins using rain data
- Sending data search results via web-sockets to update web pages with current rain data (supports both Pako's Websocket Suite and Tornado)
The plugin handles also the known situation when you need to change batteries in the sensor. In this case the sensor id will most likely change. A rain sensor will also start counting from zero again. If you update the sensor id of the existing sensor database, the collecting of readings to the database will continue as before.
In the following I will give some configuration examples.
1) Start to collect sensor data
You just add a 'DataCapture' macro, name the database table and put in the sensor id. Configure the rest of the parameters if you do not accept the default. If you check the box '..use a rule' you will receive events when conditions are met as described above.
Then drag & drop the event from the sensor to the macro. You are done, data will be collected as soon as new sensor events arrives.
Once you have some collected (rain) data you can start to query the tables
2) Simplest is to use the 'RainReport' action. Add a new macro for it, select the sensor database table, the start and end date&time stamps and check the boxes if you want to send the result using web-sockets. By default it will just be printed in the log.
3) To request data from a script or similar, use the 'RainRequestSearch' or the 'RainRequestQuery' macro.
As example using the 'RainRequestSearch' macro:
Configure it and select the sensor database table. To trigger it, create an event with a payload specifying the start and end date&time stamps similar to this:
In the example above, the result will be calculated based on the first found records for '2014-11-07' and '2014-11-07'. You can also set the pl similar to the following examples:
['2014-11-07 10', '2014-11-09 22'] #will use records first found 2014-11-07 at 10 and 2014-11-09 at 22
['', '2014-11-08'] #will use from beginning until first record found 2014-11-08
['2014-11-07', ''] #will use from first record found 2014-11-07 until end
[] or ['', ''] #will use all records in the table
- Rain, temperature and humidity data can be collected with a RFXtrx
- Temperature and humidity data can be collected with a TellStick Duo (I am lacking a TellStick Duo log sample from a rain sensor to complete the code)
- Data from other devices like z-wave and 1-wire can easily be added and is on the 'ToDo list' but I need sample events from the EG log.
You can download the plugin from here (check the section 'Current plugins just ready for prime time'):
http://krambriw.net
The plugin supports the following features:
- You can configure how frequently you want to save readings (default every 10 minutes)
REVISED:
- For rain, the plugin calculates two moving averages, one fast and one slow. This is then used to create events when the lines are crossing each other. The more readings you select, the slower the response to changes. This is a very useful function to when you are looking for trend shifts (in this case, if rain is increasing or decreasing during time).
- In addition you can add a hysteresis value that will set the upper and lower band (+/- hysteresis/2) for the fast moving average before it triggers an event
- For temperature and humidity, the plugin calculates one moving average. This is then used in combination with the set-point and optionally the hysteresis to create events when the lines are crossing each other. The more readings you select, the slower the response to changes. This is a very useful function to avoid too many status changes when for instance controlling heaters with on/off control equipment (you might temporary open a door or window but the heater should not react immediately)
- In addition you can add a hysteresis value that will set the upper and lower band (set-point +/- hysteresis/2) for the moving average before it triggers an event
- You can select if you want to use the rule evaluation that will generate those events or not. Currently I have only one rule 'equal-less-greater' that will generate events when moving average gets equal, less or greater than its reference.
- All this works for rain level, temperature and humidity data
To collect data I use actions in macros. This simplifies your configuration, you just drag & drop the sensor event in the macro you created.
Sensor data is collected on a per sensor exclusive sqlite3 database table. The more frequent you have selected to store data, the quicker the size of your database will grow.
For all sensor types, there are two main actions
- A capture action to capture sensor data
- A reset action to clear all readings captured from the sensor
Currently only available for rain level data you also have the following actions
- RainReport action reporting the total rain between configured date & time stamps
- RainRequestSearch event triggered action searching for total rain between in event payload provided date & time stamps
- RainRequestQuery action searching for total rain between provided date & time stamps and returning the result as variable, foreseen to be used in scripts or other plugins using rain data
- Sending data search results via web-sockets to update web pages with current rain data (supports both Pako's Websocket Suite and Tornado)
The plugin handles also the known situation when you need to change batteries in the sensor. In this case the sensor id will most likely change. A rain sensor will also start counting from zero again. If you update the sensor id of the existing sensor database, the collecting of readings to the database will continue as before.
In the following I will give some configuration examples.
1) Start to collect sensor data
You just add a 'DataCapture' macro, name the database table and put in the sensor id. Configure the rest of the parameters if you do not accept the default. If you check the box '..use a rule' you will receive events when conditions are met as described above.
Then drag & drop the event from the sensor to the macro. You are done, data will be collected as soon as new sensor events arrives.
Once you have some collected (rain) data you can start to query the tables
2) Simplest is to use the 'RainReport' action. Add a new macro for it, select the sensor database table, the start and end date&time stamps and check the boxes if you want to send the result using web-sockets. By default it will just be printed in the log.
3) To request data from a script or similar, use the 'RainRequestSearch' or the 'RainRequestQuery' macro.
As example using the 'RainRequestSearch' macro:
Configure it and select the sensor database table. To trigger it, create an event with a payload specifying the start and end date&time stamps similar to this:
Code: Select all
pl = ['2014-11-07', '2014-11-09']
eg.TriggerEvent(
'ClimateDataCalculation',
payload = pl,
prefix='ClimateDataCalculation'
)
['2014-11-07 10', '2014-11-09 22'] #will use records first found 2014-11-07 at 10 and 2014-11-09 at 22
['', '2014-11-08'] #will use from beginning until first record found 2014-11-08
['2014-11-07', ''] #will use from first record found 2014-11-07 until end
[] or ['', ''] #will use all records in the table