Reset automatic Textlog sensors

Topics (not sure which fora)
when not sure where to post, post here and mods will move it to right forum.

Moderators: leecollings, remb0

Post Reply
JanAtHome
Posts: 38
Joined: Wednesday 10 January 2018 16:49
Target OS: Raspberry Pi / ODroid
Domoticz version: 38153
Location: Raalte Holland
Contact:

Reset automatic Textlog sensors

Post by JanAtHome »

Over Domoticz
Version: 4.11605
Build Hash: 7de1f368f
Compile Date: 2020-01-08 23:12:15
dzVents Version: 2.5.5
Python Version: 3.7.3 (default, Apr 3 2019, 05:39:12) [GCC 8.2.0]


Hey
I am looking for a command to reset the text log of a switch / sensor via a script file.
I am looking for the command that is under the delete button (wissen).
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Reset automatic Textlog sensors

Post by waaren »

JanAtHome wrote: Wednesday 15 January 2020 15:10 I am looking for a command to reset the text log of a switch / sensor via a script file.
I am looking for the command that is under the delete button (wissen).
Can you try this one ?
clearText.png
clearText.png (24.06 KiB) Viewed 588 times
clearText2.png
clearText2.png (43.19 KiB) Viewed 588 times
read the comments in the script first. If anything is not clear please feel free to ask

Code: Select all

local scriptVar = 'textClearAPI'

return
{
    on = 
    { 
        devices = 
        {
            'clearText',    -- create as a virtual selector type switch. Levels 0 = 'Off', 
                            -- 10, 20, etc.. like clear nameOfDevicetoClear log & text 
                            -- name of the device to clear must be the second word in the level 
        },
        httpResponses =
        {
            scriptVar,
        }
    },

    logging =   
    {
        level = domoticz.LOG_DEBUG, -- set to LOG_ERROR when tested and OK
        marker = 'Clear text and log: ', 
    },
       
    execute = function(dz, item)
        
        local function getAndClearLightLog(idx)
            local getTextURL =  dz.settings['Domoticz url'] .. '/json.htm?type=textlog&idx=' .. idx
            local deleteTextURL = dz.settings['Domoticz url'] .. '/json.htm?type=command&param=clearlightlog&idx=' .. idx
            dz.openURL(
            { 
                url = getTextURL,  
                method = "GET", 
                callback = scriptVar,
            })
            dz.openURL(deleteTextURL).afterSec(3)
        end
        
        
        if item.isDevice and item.level ~= 0 then
            clearDevice = dz.devices(dz.utils.stringSplit(item.levelName,' ')[2]) 
            dz.log('current text: ' .. clearDevice.state)
            if clearDevice.deviceSubType == 'Text' then clearDevice.updateText('').silent() end
            getAndClearLightLog(clearDevice.id)
            item.switchOff().silent()
        elseif item.isHTTPResponse then
            for index, record in ipairs( item.json.result) do
                dz.log(record.Date .. ' ' .. record.Data)
            end    
        end    
    end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
JanAtHome
Posts: 38
Joined: Wednesday 10 January 2018 16:49
Target OS: Raspberry Pi / ODroid
Domoticz version: 38153
Location: Raalte Holland
Contact:

Re: Reset automatic Textlog sensors

Post by JanAtHome »

Waaren tks
I will convert the script.
What matters to me is that the logs of certain sensors are emptied every month.
Or maybe even better, save the last 50 or 100 (adjustable).
And automatically erase the rest.
Thanks in advance for this example.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Reset automatic Textlog sensors

Post by waaren »

JanAtHome wrote: Wednesday 15 January 2020 22:59 ... a nd automatically erase the rest.
Is this not already a standard feature of domoticz that can be configured in [setup] [settings] [log history] ?
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
JanAtHome
Posts: 38
Joined: Wednesday 10 January 2018 16:49
Target OS: Raspberry Pi / ODroid
Domoticz version: 38153
Location: Raalte Holland
Contact:

Re: Reset automatic Textlog sensors

Post by JanAtHome »

That are all sensors.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Reset automatic Textlog sensors

Post by waaren »

JanAtHome wrote: Thursday 16 January 2020 9:47 That are all sensors.
No. Also Switches / lights
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
JanAtHome
Posts: 38
Joined: Wednesday 10 January 2018 16:49
Target OS: Raspberry Pi / ODroid
Domoticz version: 38153
Location: Raalte Holland
Contact:

Re: Reset automatic Textlog sensors

Post by JanAtHome »

Hello Waaren
You misunderstand me.
I mean that I want to reset some sensors / switches / lights logs, not all. But only the item I have chosen.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Reset automatic Textlog sensors

Post by waaren »

JanAtHome wrote: Thursday 16 January 2020 22:36 I mean that I want to reset some sensors / switches / lights logs, not all. But only the item I have chosen.
OK, understand now. Thx for clarifying.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest