Hi @waaren
script works perfect, sync works also perfect !
I added the global message construction and some addons.
Only one scriptline(loggingline) does not work, the one with:
globalMessage(add, '\nCommand: ' .. cmd .. '\nReturnCode: ' .. returnTable[3] ..'\ncommandOutput: ' .. commandOutput .. '',logcode) or
the original;
--dz.log('\nCommand: ' .. cmd .. '\nReturnCode: ' .. returnTable[3] ..'\ncommandOutput: ' .. commandOutput,dz.LOG_ERROR)
see code below.
I also dont understand why this has a value of 3...
p.
Code: Select all
local timer_overdag = 'every 15 minutes between 06:10 and 00:25 on mon,tue,wed,thu,fri,sat,sun' -- OVERDAG dan wel syncen
local timer_nacht = 'every 15 minutes between 00:35 and 06:00 on mon,tue,wed,thu,fri,sat,sun' -- NACHT dan niet syncen
--
-- nas gaat om 6 aan en 0030 uit en op ma di do ook van 9-14 uit --dit laatste is nog niet verwerkt
-- dz.log('\nCommand: ' .. cmd .. '\nReturnCode: ' .. returnTable[3] ..'\ncommandOutput: ' .. commandOutput,dz.LOG_ERROR) deze regel doet t nog niet komt dit door [3] waar is deze 3 voor?
-- /mnt/mntroot nog aan een extra usb stick koppelen
return
{
on = { timer = {timer_overdag,timer_nacht},
devices = {'filecopy'},
},
execute = function(dz,item,info)
if (item.isDevice and item.name == 'filecopy' and item.state == 'On') or item.isTimer then
local logcode = 3
local messageTable = {}
local add = 'add'
local del = 'del'
local chg = 'chg'
local function globalMessage(action, message, logcode)
if logcode == nil then logcode = 3 end
if action == add and logcode > 0 then
messageTable = dz.helpers.addMessage(dz, item, info, message, messageTable, logcode)
elseif action == del then
dz.globalData.mylogging = message
dz.devices('timerlog').updateText(message)
elseif action == chg then
dz.helpers.dumpMessages(dz, messageTable)
end
end
local sourceDir = '/mnt/mntroot'
local targetDir = '/mnt/mntnas'
local function osCommand(cmd)
local fileHandle = assert(io.popen(cmd, 'r'))
local commandOutput = assert(fileHandle:read('*a'))
local returnTable = {fileHandle:close()}
if returnTable[3] ~= 0 then
-- The globalMessage does not work.. why is that ? the dz.log below also does not work why the 3
globalMessage(add, '\nCommand: ' .. cmd .. '\nReturnCode: ' .. returnTable[3] ..'\ncommandOutput: ' .. commandOutput .. '',logcode)
--dz.log('\nCommand: ' .. cmd .. '\nReturnCode: ' .. returnTable[3] ..'\ncommandOutput: ' .. commandOutput,dz.LOG_ERROR)
end
return commandOutput
end
local function fileCount(dir)
return tonumber(osCommand('ls ' .. dir .. ' | wc -l'))
end
if fileCount(sourceDir) > 0 then
globalMessage(add, ' NAS: Er zijn bestanden op de SHARE aanwezig...',logcode)
dz.devices('motion files aanwezig').switchOn()
if (item.isDevice and item.name == 'filecopy' and item.state == 'On') or (item.isTimer and item.trigger == timer_overdag) then
osCommand('sudo mv ' .. sourceDir .. '/* ' .. targetDir .. '/')
globalMessage(add, ' NAS: Er zijn bestanden verplaatst...',logcode)
dz.devices('motion files aanwezig').switchOff()
end
else
globalMessage(add, ' NAS: Er zijn geen bestanden op de SHARE aanwezig...',logcode)
dz.devices('motion files aanwezig').switchOff()
end
if item.isDevice and item.name == 'filecopy' and item.state == 'On' then
item.switchOff().afterSec(5)
end
globalMessage(chg) -- dump
end
end
}
Raspberry (raspbian on rpi 3) , Domoticz Beta, dzVents , RFXtrx433e, P1, Hue, Yeelight, Zwave+, X10, ESP(easy), MQTT,Weather Underground, System Alive Checker, Domoticz Remote Server to RPI with Google Assistant,
Jablotron connection, Ikea