Ability to ignore 0 values

Use this forum to discuss possible implementation of a new feature before opening a ticket.
A developer shall edit the topic title with "[xxx]" where xxx is the id of the accompanying tracker id.
Duplicate posts about the same id. +1 posts are not allowed.

Moderators: leecollings, remb0

Post Reply
Calzor Suzay
Posts: 145
Joined: Tuesday 08 July 2014 15:10
Target OS: -
Domoticz version: 4.9700
Location: UK
Contact:

Ability to ignore 0 values

Post by Calzor Suzay »

Some sensors I have as part of scripts or other sometimes crap out over the internet or the requesting site doesn't respond etc. so you can end up with a 0 value which messes up graphs.

I've tried some logic in scripts or this and that which help but still can end up with 0 values.
I know you can so the shift left click and remove but means you have to check daily the validity of each sensors recordings.

It would be nice to have an option to dump 0 values say once an hour or a defined value if this is possible?
User avatar
Egregius
Posts: 2592
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Ability to ignore 0 values

Post by Egregius »

If the 0 value comes from a script you should check it there. For sure if you retrieve data from a url.
If you really want to remove them from the database you could set up a script and execute it by cron.
I run this script every night to remove all data older than 1 hour ( I don't care about that ) and remove all data from unused devices.
You could alter the query to remove 0 values.

Code: Select all

<?php
$db = new SQLite3('/volume1/@appstore/domoticz/var/domoticz.db');
$clean = strftime("%G-%m-%d %k:%M:%S",time()-3600);
$tables = array( 'LightingLog',
                'MultiMeter',
                'MultiMeter_Calendar',
                'Meter',
                'Meter_Calendar',
                'Percentage',
                'Percentage_Calendar',
                'Rain',
                'Rain_Calendar',
                'Temperature',
                'Temperature_Calendar',
                'UV',
                'UV_Calendar',
                'Wind',
                'Wind_Calendar');
foreach($tables as $table)
{
    $query=$db->exec("DELETE FROM $table WHERE DeviceRowID not in (select ID from DeviceStatus where Used = 1) OR Date < '$clean'");
    if ($query)
    {
        $rows = $db->changes();
        if($rows>0)
            echo $rows." rows removed from $table<br/>";
    }
}
$query=$db->exec("DELETE FROM LightingLog WHERE DeviceRowID not in (162)");
    if ($query)
    {
        $rows = $db->changes();
        if($rows>0)
            echo $rows." rows removed from LightingLog<br/>";
    }
$sql = 'VACUUM;';
if(!$result = $db->exec($sql))
    die('There was an error running the query [' . $db->error . ']'); 
Calzor Suzay
Posts: 145
Joined: Tuesday 08 July 2014 15:10
Target OS: -
Domoticz version: 4.9700
Location: UK
Contact:

Re: Ability to ignore 0 values

Post by Calzor Suzay »

I guess I need to know my tables and stuff but doable, thanks.
I'll try and get better error checking in the scripts but this is an option :)
User avatar
Egregius
Posts: 2592
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Ability to ignore 0 values

Post by Egregius »

The script runs for over a year daily here. I also use adminer do directly access the database. Never had an issue with the DB.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest