Page 1 of 2
CommandArray not executed
Posted: Thursday 04 March 2021 13:01
by azonneveld
[EDIT]
Seems to be solved in 2021.1
[/EDIT]
Sometimes lines put into the commandarray are not executed.
Because I suspected the array was not always executed, I created two scripts, devicebased and a time based (acting as a watchdog)
The idea is that tWakeupAssist is triggered using a timer. This works fine.
Next, when the tWakeupAssist is set 'on' it should be set 'off' and some actions are triggered (indicated by "...some other actions are triggered...")
The timebased script, tests if the tWakeupAssist is 'on' for more than 2 minutes.
If the device is still on, the devicebased script has probably failed to run. So, tWakeupAssist is triggered again.
I checked the error-log, but it shows no errors.
The script fails approx. once or twice a month. De device is triggered every day.
Who could give me a suggestion to fix this failing script?
Devicebased lua script:
Code: Select all
if (deviceName=='tWakeupAssist') then
if deviceValue == "On" then
commandArray[#commandArray + 1] = {['tWakeupAssist'] = "Off"}
end
...some other actions are triggered...
end
Timebased lua script
Code: Select all
---------------------------------------------
-- WakeUpAssistant Check trigger
---------------------------------------------
if otherdevices['tWakeupAssist']=='On' then
difference = timedifference(otherdevices_lastupdate['tWakeupAssist'])
if difference >= 2 then
commandArray[#commandArray + 1] = {['SendNotification']='WakeUpAssistant Trigger Failed'}
commandArray[#commandArray + 1] = {['tWakeupAssist'] = 'On'}
end
end
Re: CommandArray not executed
Posted: Thursday 04 March 2021 13:52
by jvdz
How does the whole script look so we can check what else could interfere?
Re: CommandArray not executed
Posted: Thursday 04 March 2021 14:30
by azonneveld
jvdz wrote: Thursday 04 March 2021 13:52
How does the whole script look so we can check what else could interfere?
Code: Select all
commandArray = {}
--============== SETTINGS =========================
local LuxLow = 800
--=================================================
local tNow = os.date("*t");
local tNowInMin = tNow.min + tNow.hour * 60
local ZonOp = tonumber(timeofday['SunriseInMinutes']);
local ZonOnder = tonumber(timeofday['SunsetInMinutes'])
local t = os.date("*t");
local Taan = uservariables["VerwarmingAanTemp"]
local Tuit = uservariables["VerwarmingUitTemp"]
local mCrestaTemp,mCrestaHumidity
-- loop through all the changed devices
for deviceName,deviceValue in pairs(devicechanged) do
-------------------------------------------------------------
-- WAKE ASSIST
-------------------------------------------------------------
if otherdevices_svalues['Profiel'] ~= '40' then
--if (otherdevices['WakeUpAssistant'] == 'On') then -- WakeUpAssistant Enabled
--for deviceName,deviceValue in pairs(devicechanged) do
if (deviceName=='tWakeupAssist') then
if deviceValue == "On" then
commandArray[#commandArray + 1] = {['tWakeupAssist'] = "Off"}
end
if deviceValue == "On" and otherdevices['SkipWakeupassistant'] ~= 'On' and (otherdevices['WakeUpAssistant'] == 'On') then
--- UITZETTEN GAAT VIA GLOBALS, HIER WORDT TRIGGER GEZET
if (otherdevices_svalues['Profiel']~='30') then -- niet uitzetten als profiel op nooituit staat
commandArray[#commandArray + 1] = {['Variable:WakeUpAssistTriggered']='1'}
commandArray[#commandArray + 1] = {['Variable:WakeUpAssistStarted']=tostring(tNowInMin)}
end
--- UITZETTEN GAAT VIA GLOBALS
commandArray[#commandArray + 1] = {['Slaap Licht'] = "On"} -- Activatie device voor group SleepAssistantBoven
commandArray[#commandArray + 1] = {['Ikea Socket 02'] = "On FOR 15"} -- lamp op logeerkamer 15 minuten aan
if (((tNowInMin <= ZonOp) and (uservariables['LuxAlive'] == 0)) or ((tonumber(otherdevices['LuxMeter']) < LuxLow) and uservariables['LuxAlive'] == 1)) then
commandArray[#commandArray + 1] = {['Group:Woon Lamp'] = "On AFTER 10"}
end
if otherdevices_svalues['NotificationLevel']=='20' then -- NotificationLevel Debug
commandArray[#commandArray + 1] = {['SendNotification']='WakeUpAssistant Triggered'}
end
-- WakeUpAssistant uit functie onderdrukken via NooitUit_Auto
if otherdevices['NooitUit_Auto'] == 'On' then
if otherdevices_svalues['Profiel']~='30' then
commandArray[#commandArray + 1] = {['Profiel'] = "Set Level: 30"}
commandArray[#commandArray + 1] = {['NooitUit_Auto'] = "Off"}
if otherdevices_svalues['NotificationLevel']~='0' then -- Notification not muted
commandArray[#commandArray + 1] = {['SendNotification']='Profiel geschakeld naar NooitUit_Auto, als je morgen de uitfunctie van WakeUpAssistant ook wilt onderdrukken, kies dan een profiel en zet NooitUit_Auto weer aan'}
end
end
end
--==================================================================================================================
-- KRABBEN REPORT
----------------------------------
if otherdevices_svalues['NotificationLevel']~='0' then -- NotificationLevel not muted
local sCrestaTemp, sCrestaHumidity = otherdevices_svalues['Tuin Temp']
mCrestaTemp, mCrestaHumidity = otherdevices_svalues['Tuin Temp']:match("([^;]+);([^;]+)")
local mMin = otherdevices_svalues['Minimum Temp']
if tonumber(mCrestaTemp) < 3 and tonumber(mMin) < 0.5 then
--if tonumber(mCrestaTemp) < 30 and tonumber(mMin) < 10 then
os.execute ('(/bin/sleep 20 && /home/pi/domoticz/scripts/autokrabben.sh > /dev/null)&')
commandArray[#commandArray + 1] = {['SendNotification']='Krabben Report, temperatuur:' ..tostring(mCrestaTemp)}
--os.execute("/bin/sleep 1 && /home/pi/domoticz/scripts/autokrabben.sh")
end
end
--==================================================================================================================
elseif deviceValue == "Off" or otherdevices['SkipWakeupassistant'] == 'On' then
commandArray[#commandArray + 1] = {['SkipWakeupassistant']='Off'}
end
end
--end
--==================================================================================================================
elseif (otherdevices['WakeUpAssistant'] ~= 'On') then
commandArray[#commandArray + 1] = {['Variable:WakeUpAssistTriggered']='0'}
end
--================================================================
-- Skip WakeUpAssistant
--================================================================
local t = tonumber(uservariables["WakeUpAssistantNextMinutes"] - tNowInMin)
--print('assistant ' .. tostring(t))
if deviceName == 'SkipWakeupassistant' then
t = tonumber(uservariables["WakeUpAssistantNextMinutes"] - tNowInMin)
--print('assistant ' .. tostring(t))
if deviceValue == 'On' then
if t < 0 or t > 90 then -- WakeUpAssistant mag geskipt worden, maximaal 1 uur voor de wekker, en ook niet na de wekker
--print('assistant skip uitgezet')
commandArray[#commandArray + 1] = {['SkipWakeupassistant']='Off'}
end
end
end
end
return commandArray
This part is executed, since i received the notification:
Code: Select all
-- WakeUpAssistant uit functie onderdrukken via NooitUit_Auto
if otherdevices['NooitUit_Auto'] == 'On' then
if otherdevices_svalues['Profiel']~='30' then
commandArray[#commandArray + 1] = {['Profiel'] = "Set Level: 30"}
commandArray[#commandArray + 1] = {['NooitUit_Auto'] = "Off"}
if otherdevices_svalues['NotificationLevel']~='0' then -- Notification not muted
commandArray[#commandArray + 1] = {['SendNotification']='Profiel geschakeld naar NooitUit_Auto, als je morgen de uitfunctie van WakeUpAssistant ook wilt onderdrukken, kies dan een profiel en zet NooitUit_Auto weer aan'}
end
end
end
Re: CommandArray not executed
Posted: Thursday 04 March 2021 16:12
by jvdz
Script looks good but has many triggers added to the queue, so are you sure you test for 2 minutes "On" in stead of 2 seconds?
Re: CommandArray not executed
Posted: Thursday 04 March 2021 16:38
by azonneveld
jvdz wrote: Thursday 04 March 2021 16:12
Script looks good but has many triggers added to the queue, so are you sure you test for 2 minutes "On" in stead of 2 seconds?
When I check the tWakeupAssist device log, it is switched on and 2 minutes later switched to off.
Code: Select all
2021-03-04 06:12:01 Off EventSystem/AssistWakeUp2_2
2021-03-04 06:10:01 On timer
Re: CommandArray not executed
Posted: Thursday 04 March 2021 16:54
by waaren
azonneveld wrote: Thursday 04 March 2021 14:30
jvdz wrote: Thursday 04 March 2021 13:52
How does the whole script look so we can check what else could interfere?
I added some lines to print the content of the commandArray (or empty) just before it is returned to the eventSystem. Maybe it will help in finding the issue.
Code: Select all
commandArray = {}
local function tprint (t, indent, done) -- introduced done to prevent infinite loops for tables with self-references
local done = done or {}
indent = indent or 0
for key, value in pairs (t) do
pre = (string.rep (" ", indent)) -- indent it
if type (value) == "table" and not done[value] then
done [value] = true
print (pre .. tostring (key) .. ":");
tprint (value, indent + 2, done)
elseif type(value) == 'function' and not done[value] then
print( pre .. (tostring (key) .. "()"))
else
pre = pre .. (tostring (key) .. ": ")
print (pre .. tostring(value))
end
end
end
--============== SETTINGS =========================
local LuxLow = 800
--=================================================
local tNow = os.date("*t");
local tNowInMin = tNow.min + tNow.hour * 60
local ZonOp = tonumber(timeofday['SunriseInMinutes']);
local ZonOnder = tonumber(timeofday['SunsetInMinutes'])
local t = os.date("*t");
local Taan = uservariables["VerwarmingAanTemp"]
local Tuit = uservariables["VerwarmingUitTemp"]
local mCrestaTemp,mCrestaHumidity
-- loop through all the changed devices
for deviceName,deviceValue in pairs(devicechanged) do
-------------------------------------------------------------
-- WAKE ASSIST
-------------------------------------------------------------
if otherdevices_svalues['Profiel'] ~= '40' then
--if (otherdevices['WakeUpAssistant'] == 'On') then -- WakeUpAssistant Enabled
--for deviceName,deviceValue in pairs(devicechanged) do
if (deviceName=='tWakeupAssist') then
if deviceValue == "On" then
commandArray[#commandArray + 1] = {['tWakeupAssist'] = "Off"}
end
if deviceValue == "On" and otherdevices['SkipWakeupassistant'] ~= 'On' and (otherdevices['WakeUpAssistant'] == 'On') then
--- UITZETTEN GAAT VIA GLOBALS, HIER WORDT TRIGGER GEZET
if (otherdevices_svalues['Profiel']~='30') then -- niet uitzetten als profiel op nooituit staat
commandArray[#commandArray + 1] = {['Variable:WakeUpAssistTriggered']='1'}
commandArray[#commandArray + 1] = {['Variable:WakeUpAssistStarted']=tostring(tNowInMin)}
end
--- UITZETTEN GAAT VIA GLOBALS
commandArray[#commandArray + 1] = {['Slaap Licht'] = "On"} -- Activatie device voor group SleepAssistantBoven
commandArray[#commandArray + 1] = {['Ikea Socket 02'] = "On FOR 15"} -- lamp op logeerkamer 15 minuten aan
if (((tNowInMin <= ZonOp) and (uservariables['LuxAlive'] == 0)) or ((tonumber(otherdevices['LuxMeter']) < LuxLow) and uservariables['LuxAlive'] == 1)) then
commandArray[#commandArray + 1] = {['Group:Woon Lamp'] = "On AFTER 10"}
end
if otherdevices_svalues['NotificationLevel']=='20' then -- NotificationLevel Debug
commandArray[#commandArray + 1] = {['SendNotification']='WakeUpAssistant Triggered'}
end
-- WakeUpAssistant uit functie onderdrukken via NooitUit_Auto
if otherdevices['NooitUit_Auto'] == 'On' then
if otherdevices_svalues['Profiel']~='30' then
commandArray[#commandArray + 1] = {['Profiel'] = "Set Level: 30"}
commandArray[#commandArray + 1] = {['NooitUit_Auto'] = "Off"}
if otherdevices_svalues['NotificationLevel']~='0' then -- Notification not muted
commandArray[#commandArray + 1] = {['SendNotification']='Profiel geschakeld naar NooitUit_Auto, als je morgen de uitfunctie van WakeUpAssistant ook wilt onderdrukken, kies dan een profiel en zet NooitUit_Auto weer aan'}
end
end
end
--==================================================================================================================
-- KRABBEN REPORT
----------------------------------
if otherdevices_svalues['NotificationLevel']~='0' then -- NotificationLevel not muted
local sCrestaTemp, sCrestaHumidity = otherdevices_svalues['Tuin Temp']
mCrestaTemp, mCrestaHumidity = otherdevices_svalues['Tuin Temp']:match("([^;]+);([^;]+)")
local mMin = otherdevices_svalues['Minimum Temp']
if tonumber(mCrestaTemp) < 3 and tonumber(mMin) < 0.5 then
--if tonumber(mCrestaTemp) < 30 and tonumber(mMin) < 10 then
os.execute ('(/bin/sleep 20 && /home/pi/domoticz/scripts/autokrabben.sh > /dev/null)&')
commandArray[#commandArray + 1] = {['SendNotification']='Krabben Report, temperatuur:' ..tostring(mCrestaTemp)}
--os.execute("/bin/sleep 1 && /home/pi/domoticz/scripts/autokrabben.sh")
end
end
--==================================================================================================================
elseif deviceValue == "Off" or otherdevices['SkipWakeupassistant'] == 'On' then
commandArray[#commandArray + 1] = {['SkipWakeupassistant']='Off'}
end
end
--end
--==================================================================================================================
elseif (otherdevices['WakeUpAssistant'] ~= 'On') then
commandArray[#commandArray + 1] = {['Variable:WakeUpAssistTriggered']='0'}
end
--================================================================
-- Skip WakeUpAssistant
--================================================================
local t = tonumber(uservariables["WakeUpAssistantNextMinutes"] - tNowInMin)
--print('assistant ' .. tostring(t))
if deviceName == 'SkipWakeupassistant' then
t = tonumber(uservariables["WakeUpAssistantNextMinutes"] - tNowInMin)
--print('assistant ' .. tostring(t))
if deviceValue == 'On' then
if t < 0 or t > 90 then -- WakeUpAssistant mag geskipt worden, maximaal 1 uur voor de wekker, en ook niet na de wekker
--print('assistant skip uitgezet')
commandArray[#commandArray + 1] = {['SkipWakeupassistant']='Off'}
end
end
end
end
if #commandArray == 0 then
print ('Wake Assist: -empty commandArray-')
else
tprint(commandArray)
end
return commandArray
Re: CommandArray not executed
Posted: Thursday 04 March 2021 16:56
by jvdz
But the question remains.
Just a wild guess but I think you are testing for 2 seconds and have a racing condition on your hands were the event systems is still processing the list of events returned from the device script and the Time script is ran detecting the switch is "On" and it is 2 seconds ago.
So please check that function and when you are using the one I use with the same name, it does return the lapsed time in seconds, not minutes, so increase the 2 to something like 30 as I assume the stack of events will be done after 30 seconds.

Re: CommandArray not executed
Posted: Thursday 04 March 2021 17:37
by azonneveld
jvdz wrote: Thursday 04 March 2021 16:56
I think you are testing for 2 seconds
Below is the time difference function I am using:
Code: Select all
function round(num, numDecimalPlaces)
local mult = 10^(numDecimalPlaces or 0)
return math.floor(num * mult + 0.5) / mult
end
function timedifference(s)
year = string.sub(s, 1, 4)
month = string.sub(s, 6, 7)
day = string.sub(s, 9, 10)
hour = string.sub(s, 12, 13)
minutes = string.sub(s, 15, 16)
seconds = string.sub(s, 18, 19)
t1 = os.time()
t2 = os.time{year=year, month=month, day=day, hour=hour, min=minutes, sec=seconds}
difference = round((os.difftime (t1, t2) / 60),0)
return difference
end
Re: CommandArray not executed
Posted: Thursday 04 March 2021 17:39
by azonneveld
waaren wrote: Thursday 04 March 2021 16:54
I added some lines to print the content of the commandArray (or empty) just before it is returned to the eventSystem. Maybe it will help in finding the issue.
I have included your lines in my script... "now we wait..."
Re: CommandArray not executed
Posted: Thursday 04 March 2021 17:46
by jvdz
Also please show the domoticz log records when this issue happens so we can see the timing of the events, but I am pretty sure this will be a race condition.
Re: CommandArray not executed
Posted: Thursday 04 March 2021 18:09
by azonneveld
I altered the logging lines a bit, because it was flooding the log
Code: Select all
local doLog = false
-- loop through all the changed devices
for deviceName,deviceValue in pairs(devicechanged) do
-------------------------------------------------------------
-- WAKE ASSIST
-------------------------------------------------------------
if otherdevices_svalues['Profiel'] ~= '40' then
--if (otherdevices['WakeUpAssistant'] == 'On') then -- WakeUpAssistant Enabled
--for deviceName,deviceValue in pairs(devicechanged) do
if (deviceName=='tWakeupAssist') then
doLog = true
........................
bottom of script
Code: Select all
if doLog == true then
if #commandArray == 0 then
print ('tWakeupAssist -empty commandArray-')
else
print("tWakeupAssist Failed to Trigger")
tprint(commandArray)
end
end
return commandArray
Re: CommandArray not executed
Posted: Thursday 04 March 2021 18:19
by azonneveld
This is not gonna work... the notification of the failed trigger came first, meaning the script was not executed the first time.
Need to figure out some way to not flood the log, but capture the occurrence

.
azonneveld wrote: Thursday 04 March 2021 18:09
I altered the logging lines a bit, because it was flooding the log
Code: Select all
local doLog = false
-- loop through all the changed devices
for deviceName,deviceValue in pairs(devicechanged) do
-------------------------------------------------------------
-- WAKE ASSIST
-------------------------------------------------------------
if otherdevices_svalues['Profiel'] ~= '40' then
--if (otherdevices['WakeUpAssistant'] == 'On') then -- WakeUpAssistant Enabled
--for deviceName,deviceValue in pairs(devicechanged) do
if (deviceName=='tWakeupAssist') then
doLog = true
........................
bottom of script
Code: Select all
if doLog == true then
if #commandArray == 0 then
print ('tWakeupAssist -empty commandArray-')
else
print("tWakeupAssist Failed to Trigger")
tprint(commandArray)
end
end
return commandArray
Re: CommandArray not executed
Posted: Thursday 04 March 2021 18:26
by jvdz
azonneveld wrote: Thursday 04 March 2021 17:37
jvdz wrote: Thursday 04 March 2021 16:56
I think you are testing for 2 seconds
Below is the time difference function I am using:
Sorry, but I see I missed this one while typing my post around that time. So it is indeed the difference in minutes which makes the race condition unlikely and am curious if the extra logging will provide some explanation.
Re: CommandArray not executed
Posted: Thursday 04 March 2021 19:33
by azonneveld
Found some kind of solution to prevent the log from flooding. Usually my 'alarm clock' goes between 06 and 07. So most of the time this should capture it.
Altered the logging lines to:
Code: Select all
if tNowInMin > 360 and tNowInMin < 420 then
if #commandArray == 0 then
print ('tWakeupAssist -empty commandArray-')
else
print("tWakeupAssist Failed to Trigger")
tprint(commandArray)
end
end
Re: CommandArray not executed
Posted: Wednesday 10 March 2021 7:53
by azonneveld
I think this is a hit!
The script that generates the logs:
Code: Select all
if otherdevices['tWakeupAssist'] == 'On' then
print("=============== tWakeupAssist DEBUG ====================")
if #commandArray == 0 then
print ('tWakeupAssist -empty commandArray-')
else
tprint(commandArray)
end
print("=============== tWakeupAssist DEBUG ====================")
end
return commandArray
The log:
Code: Select all
2021-03-10 06:50:01.187 Status: Schedule item started! Name: tWakeupAssist, Type: On Time, DevID: 50, Time: 2021-03-10 06:50:01
2021-03-10 06:50:01.499 Status: LUA: =============== tWakeupAssist DEBUG ====================
2021-03-10 06:50:01.499 Status: LUA: tWakeupAssist -empty commandArray-
2021-03-10 06:50:01.499 Status: LUA: =============== tWakeupAssist DEBUG ====================
2021-03-10 06:50:01.787 Status: LUA: =============== tWakeupAssist DEBUG ====================
2021-03-10 06:50:01.787 Status: LUA: 1:
2021-03-10 06:50:01.787 Status: LUA: tWakeupAssist: Off
2021-03-10 06:50:01.787 Status: LUA: 2:
2021-03-10 06:50:01.787 Status: LUA: Variable:WakeUpAssistTriggered: 1
2021-03-10 06:50:01.787 Status: LUA: 3:
2021-03-10 06:50:01.787 Status: LUA: Variable:WakeUpAssistStarted: 410
2021-03-10 06:50:01.787 Status: LUA: 4:
2021-03-10 06:50:01.787 Status: LUA: Slaap Licht: On
2021-03-10 06:50:01.788 Status: LUA: 5:
2021-03-10 06:50:01.788 Status: LUA: Ikea Socket 02: On FOR 15
2021-03-10 06:50:01.788 Status: LUA: 6:
2021-03-10 06:50:01.788 Status: LUA: Group:Woon Lamp: On AFTER 10
2021-03-10 06:50:01.788 Status: LUA: 7:
2021-03-10 06:50:01.788 Status: LUA: Profiel: Set Level: 30
2021-03-10 06:50:01.788 Status: LUA: 8:
2021-03-10 06:50:01.788 Status: LUA: NooitUit_Auto: Off
2021-03-10 06:50:01.788 Status: LUA: 9:
2021-03-10 06:50:01.788 Status: LUA: SendNotification: Profiel geschakeld naar NooitUit_Auto....
2021-03-10 06:50:01.788 Status: LUA: =============== tWakeupAssist DEBUG ====================
Re: CommandArray not executed
Posted: Wednesday 10 March 2021 10:40
by waaren
azonneveld wrote: Wednesday 10 March 2021 7:53
I think this is a hit!
Can you please explain what the difference is between what you get and what you expected? Probably obvious for you but I am having a hard time to understand it.
Re: CommandArray not executed
Posted: Thursday 11 March 2021 7:27
by azonneveld
waaren wrote: Wednesday 10 March 2021 10:40
Can you please explain what the difference is between what you get and what you expected? Probably obvious for you but I am having a hard time to understand it.
The script is executed when tWakeupAssist is 'on'. The first thing the script does, is switch it off.
So, it should always return a commandarray.
At 06:50:01.187 the tWakeupAssist is triggered.
Next the script runs, but it doesnt turn off the tWakeUpAssist; this gives: tWakeupAssist -empty commandArray-
288ms later, the script is started again, and now it is executed.
Good behaviour:
Code: Select all
2021-03-11 06:10:01.012 Status: Schedule item started! Name: tWakeupAssist, Type: On Time, DevID: 50, Time: 2021-03-11 06:10:01
2021-03-11 06:10:01.215 Status: LUA: =============== tWakeupAssist DEBUG ====================
2021-03-11 06:10:01.215 Status: LUA: 1:
2021-03-11 06:10:01.215 Status: LUA: tWakeupAssist: Off
2021-03-11 06:10:01.215 Status: LUA: 2:
Bad behaviour:
Code: Select all
2021-03-10 06:50:01.187 Status: Schedule item started! Name: tWakeupAssist, Type: On Time, DevID: 50, Time: 2021-03-10 06:50:01
2021-03-10 06:50:01.499 Status: LUA: =============== tWakeupAssist DEBUG ====================
2021-03-10 06:50:01.499 Status: LUA: tWakeupAssist -empty commandArray-
2021-03-10 06:50:01.499 Status: LUA: =============== tWakeupAssist DEBUG ====================
2021-03-10 06:50:01.787 Status: LUA: =============== tWakeupAssist DEBUG ====================
2021-03-10 06:50:01.787 Status: LUA: 1:
2021-03-10 06:50:01.787 Status: LUA: tWakeupAssist: Off
2021-03-10 06:50:01.787 Status: LUA: 2:
.......................
Here is the summarized code:
Code: Select all
for deviceName,deviceValue in pairs(devicechanged) do
if otherdevices_svalues['Profiel'] ~= '40' then
if (deviceName=='tWakeupAssist') then
if deviceValue == "On" then
commandArray[#commandArray + 1] = {['tWakeupAssist'] = "Off"}
end
...............................
end
-- Debug Logging
if otherdevices['tWakeupAssist'] == 'On' then
print("=============== tWakeupAssist DEBUG ====================")
if #commandArray == 0 then
print ('tWakeupAssist -empty commandArray-')
else
tprint(commandArray)
end
print("=============== tWakeupAssist DEBUG ====================")
end
return commandArray
Re: CommandArray not executed
Posted: Thursday 11 March 2021 7:27
by azonneveld
azonneveld wrote: Thursday 11 March 2021 7:27
waaren wrote: Wednesday 10 March 2021 10:40
Can you please explain what the difference is between what you get and what you expected? Probably obvious for you but I am having a hard time to understand it.
The script is executed when tWakeupAssist is 'on'. The first thing the script does, is switch it off.
So, it should always return a commandarray and only run once.
At 06:50:01.187 the tWakeupAssist is triggered.
Next the script runs, but it doesnt turn off the tWakeUpAssist; this gives: tWakeupAssist -empty commandArray-
288ms later, the script is started again, and now it is executed.
Good behaviour:
Code: Select all
2021-03-11 06:10:01.012 Status: Schedule item started! Name: tWakeupAssist, Type: On Time, DevID: 50, Time: 2021-03-11 06:10:01
2021-03-11 06:10:01.215 Status: LUA: =============== tWakeupAssist DEBUG ====================
2021-03-11 06:10:01.215 Status: LUA: 1:
2021-03-11 06:10:01.215 Status: LUA: tWakeupAssist: Off
2021-03-11 06:10:01.215 Status: LUA: 2:
Bad behaviour, script is triggered twice:
Code: Select all
2021-03-10 06:50:01.187 Status: Schedule item started! Name: tWakeupAssist, Type: On Time, DevID: 50, Time: 2021-03-10 06:50:01
2021-03-10 06:50:01.499 Status: LUA: =============== tWakeupAssist DEBUG ====================
2021-03-10 06:50:01.499 Status: LUA: tWakeupAssist -empty commandArray-
2021-03-10 06:50:01.499 Status: LUA: =============== tWakeupAssist DEBUG ====================
2021-03-10 06:50:01.787 Status: LUA: =============== tWakeupAssist DEBUG ====================
2021-03-10 06:50:01.787 Status: LUA: 1:
2021-03-10 06:50:01.787 Status: LUA: tWakeupAssist: Off
2021-03-10 06:50:01.787 Status: LUA: 2:
........cut...............
Here is the summarized code:
Code: Select all
commandArray = {}
for deviceName,deviceValue in pairs(devicechanged) do
if otherdevices_svalues['Profiel'] ~= '40' then
if (deviceName=='tWakeupAssist') then
if deviceValue == "On" then
commandArray[#commandArray + 1] = {['tWakeupAssist'] = "Off"}
end
........cut...............
end
-- Debug Logging
if otherdevices['tWakeupAssist'] == 'On' then
print("=============== tWakeupAssist DEBUG ====================")
if #commandArray == 0 then
print ('tWakeupAssist -empty commandArray-')
else
tprint(commandArray)
end
print("=============== tWakeupAssist DEBUG ====================")
end
return commandArray
[/quote]
Re: CommandArray not executed
Posted: Thursday 11 March 2021 8:46
by waaren
azonneveld wrote: Thursday 11 March 2021 7:27
So, it should always return a commandarray.
At 06:50:01.187 the tWakeupAssist is triggered.
Next the script runs, but it doesnt turn off the tWakeUpAssist; this gives: tWakeupAssist -empty commandArray-
Bad behaviour:
Code: Select all
2021-03-10 06:50:01.187 Status: Schedule item started! Name: tWakeupAssist, Type: On Time, DevID: 50, Time: 2021-03-10 06:50:01
2021-03-10 06:50:01.499 Status: LUA: =============== tWakeupAssist DEBUG ====================
2021-03-10 06:50:01.499 Status: LUA: tWakeupAssist -empty commandArray-
2021-03-10 06:50:01.499 Status: LUA: =============== tWakeupAssist DEBUG ====================
Maybe you will see some interesting values when you add some prints. Something like below?
Code: Select all
if #commandArray == 0 then
print ('tWakeupAssist -empty commandArray-')
print('sValue of Profiel: ' .. tostring(otherdevices_svalues['Profiel'] ) )
-- Any other interesting device values Here ?
else
tprint(commandArray)
end
Re: CommandArray not executed
Posted: Thursday 11 March 2021 14:00
by azonneveld
waaren wrote: Thursday 11 March 2021 8:46
Maybe you will see some interesting values when you add some prints. Something like below?
I think it is a longshot, but added:
Code: Select all
print('sValue of Profiel: ' .. tostring(otherdevices_svalues['Profiel'] ) )
Could not think of anything else, since the off statement is the first thing the script should handle. In case the script crashes on something, I would expect a notification in the log.
The strangest thing about it, is that the script is executed on the next run. It seems to me the execution is somehow interrupted, or the value of the tWakeupAssist is not accessible for a couple of ms.