LUA - if sensor value then remove from db (devicechanged , table.insert)

Moderator: leecollings

Post Reply
daemonshome
Posts: 19
Joined: Saturday 30 May 2020 15:30
Target OS: -
Domoticz version:
Contact:

LUA - if sensor value then remove from db (devicechanged , table.insert)

Post by daemonshome »

Hi all,

The incoming value from AC outdoor sensor in offline state is 102 degC - hence I want to remove it from sending in to domoticz database.

So far i have the script, which checks the incoming value, and make adjustments accordingly - change the value to fixed. Script Attached.
Instead i would like to remove, delete the incoming wrong value complately, so have a gap not a fixed value. Any hints here?
Thanks.

Code: Select all

debug = false

temp_sensor='qlimaAC - Temp Outside'
temp_limit=100
temp_default=0.0

commandArray = {}
-- Update virtual sensor  ---------------------------------------------------
local function updateNum(dev, value1)
    local cmd = string.format("%d|0|%d", otherdevices_idx[dev], value1)
    table.insert (commandArray, { ['UpdateDevice'] = cmd } )
end

-- MAIN ---------------------------------------------------------------------
if (devicechanged[temp_sensor]) then
    current_temp = tonumber(devicechanged[temp_sensor])
    if (debug) then print(' #current_temp: '..current_temp) end
        
    if (current_temp > temp_limit) then
        if (debug) then print('ERROR: Sensor ( '..temp_sensor..') = '..current_temp..' !!!') end
        updateNum(temp_sensor, temp_default)
        return commandArray
    end
    
end

return commandArray
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: LUA - if sensor value then remove from db (devicechanged , table.insert)

Post by waaren »

daemonshome wrote: Wednesday 28 October 2020 8:49 Instead i would like to remove, delete the incoming wrong value complately, so have a gap not a fixed value. Any hints here?
The sensor data is store in the devicestatus table and whatever value is in that table will be copied every 5 minutes to the short log sensor table.

The only way I can think of is to "remember" the date /time that you received the wrong value and after a couple of minutes remove that value from the short log sensors with an (API) call to

http://<domoticz ip: domoticz:port>/json.htm?date=yyyy-mm-dd+hh:mm:ss&idx=<idx>&param=deletedatapoint&type=command

so if the wrong value arrived 2020-10-28 10:03 then you should use date=2020-10-28+10:05:00
(and 2020-10-28+10:05:01 if you have a busy system :) )

Don't forget to add the seconds !! All data after that time of that device will be deleted if you only give hh:mm
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
daemonshome
Posts: 19
Joined: Saturday 30 May 2020 15:30
Target OS: -
Domoticz version:
Contact:

Re: LUA - if sensor value then remove from db (devicechanged , table.insert)

Post by daemonshome »

waaren wrote: Wednesday 28 October 2020 10:19
daemonshome wrote: Wednesday 28 October 2020 8:49 Instead i would like to remove, delete the incoming wrong value complately, so have a gap not a fixed value. Any hints here?
The sensor data is store in the devicestatus table and whatever value is in that table will be copied every 5 minutes to the short log sensor table.

The only way I can think of is to "remember" the date /time that you received the wrong value and after a couple of minutes remove that value from the short log sensors with an (API) call to

http://<domoticz ip: domoticz:port>/json.htm?date=yyyy-mm-dd+hh:mm:ss&idx=<idx>&param=deletedatapoint&type=command

so if the wrong value arrived 2020-10-28 10:03 then you should use date=2020-10-28+10:05:00
(and 2020-10-28+10:05:01 if you have a busy system :) )

Don't forget to add the seconds !! All data after that time of that device will be deleted if you only give hh:mm
Basically I see the concept
however this seem to be a bit more complicated to me to includ in a simple script.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest