Page 1 of 1
Reset automatic Textlog sensors
Posted: Wednesday 15 January 2020 15:10
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).
Re: Reset automatic Textlog sensors
Posted: Wednesday 15 January 2020 19:23
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 (24.06 KiB) Viewed 589 times
- clearText2.png (43.19 KiB) Viewed 589 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¶m=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
}
Re: Reset automatic Textlog sensors
Posted: Wednesday 15 January 2020 22:59
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.
Re: Reset automatic Textlog sensors
Posted: Wednesday 15 January 2020 23:04
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] ?
Re: Reset automatic Textlog sensors
Posted: Thursday 16 January 2020 9:47
by JanAtHome
That are all sensors.
Re: Reset automatic Textlog sensors
Posted: Thursday 16 January 2020 10:08
by waaren
JanAtHome wrote: ↑Thursday 16 January 2020 9:47
That are all sensors.
No. Also Switches / lights
Re: Reset automatic Textlog sensors
Posted: Thursday 16 January 2020 22:36
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.
Re: Reset automatic Textlog sensors
Posted: Thursday 16 January 2020 23:01
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.