google-code-export / openhab

Automatically exported from code.google.com/p/openhab
GNU General Public License v3.0
0 stars 0 forks source link

Persist States of SwitchItem,RollershutterItem and ContactItem with SQL Persistence Service #451

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago

1. Feature Description
States of SwitchItem, RollershutterItem and ContactItem can be persisted with 
the attached patch.
SQL Persistence Service only could persist Numeric Items.

2. Example Use Case

Interesting for a couple of Statistics like:
- Duration of Beamer-Lamp
- Load profile of PCs, Home-cinema or Machines...
- Calculation of the power consumption of lighting, washing machines...

Visualization of the use cases above with Gantt-Charts: 
http://goo.gl/dd8nuQ

3. Solution
Attached is a Patch for SqlPersistenceService.java in 
org.openhab.persistence.sql

Eventually could it be integrated in 1.3.1.

Helmut

Original issue reported on code.google.com by Helmut.L...@gmail.com on 14 Sep 2013 at 3:26

GoogleCodeExporter commented 9 years ago
I forgot the Patch...

Original comment by Helmut.L...@gmail.com on 14 Sep 2013 at 3:29

Attachments:

GoogleCodeExporter commented 9 years ago
I assume that in addition to this patch, you have also changed the row type to 
some sort of CHAR (or VARCHAR)? I was worried that this may have caused a speed 
issue, but at least with a small table (9000 entries) that I have on my test 
setup, it doesn't seem to be a major problem.

Original comment by ch...@cd-jackson.com on 14 Sep 2013 at 6:50

GoogleCodeExporter commented 9 years ago
No, keep it simple! Boolean values stored as double ( 0 or 1 ), that's it. ;-)

//ORIGINAL Line: itemValue = Double.parseDouble(item.getState().toString());
itemValue = getStateAsDouble(item);

/**
 * Converts ItemState to Double
 * @param item
 * @return Double
 */
private Double getStateAsDouble(Item item){
    if(     item instanceof SwitchItem || 
            item instanceof RollershutterItem || 
            item instanceof ContactItem ) {
        return Double.parseDouble(item.getStateAs(DecimalType.class).toString());
    }
    return Double.parseDouble(item.getState().toString());
}

Original comment by Helmut.L...@gmail.com on 15 Sep 2013 at 4:47

GoogleCodeExporter commented 9 years ago
Ok - so this is just to persist other numeric data (which I completely agree 
with as your use case is also the same as mine). To avoid too many changes to 
the table structure, I think we should try and get a consensus on the format so 
that it covers as much as possible.

This patch should cover most items that are "numeric" - I guess we need to work 
out what to do with strings... 

Original comment by ch...@cd-jackson.com on 15 Sep 2013 at 9:45

GoogleCodeExporter commented 9 years ago

Original comment by teichsta on 5 Nov 2013 at 10:53

GoogleCodeExporter commented 9 years ago
This issue has been migrated to Github. If this issue id is greater than103 its 
id has been preserved on Github. You can open your issue by calling the URL 
https://github.com/openhab/openhab/issues/<issueid>. Issues with ids less or 
equal 103 new ids were created.

Original comment by teichsta on 17 Nov 2013 at 8:08

GoogleCodeExporter commented 9 years ago
see above!

Issue has been migrated to Github and should be discussed there.

Original comment by teichsta on 21 Nov 2013 at 1:51