SpaceLogic KNX Forum
Schneider Electric SpaceLogic KNX forum to get support and share knowledge including selection, installation and troubleshooting for spaceLYnk, Wiser for KNX, eConfigure KNX, SpaceLogic KNX Hybrid module and other topics.
Link copied. Please paste this link to share this article on your social media post.
Hi experts,
I am using a Wiser for KNX and am activating some scripts.
I have the issue that when I activate a script and it works, after modification of the script the original script keeps being active. I tried already to deactivate the script, I even deleted the script but in the logs of scripts and more general logs in Wiser (since I use the log() function in the script) I can see the script remains active. I need to reboot the Wiser in order to stop the scripts (some sort of 'reset'). What might be the issue?
I have added an example script in attachment. It is when I f.e. delete a log() function, that the scripts keeps it logging. as example I added a logMessage function in the 30 seconds time check - this log keeps a log every 30 seconds. I removed it in the code, saved, deactivated, activated the script but it keeps logging although not any more present in the script.
This makes it hard to debug scripts since I don't know which modification is used.
Thank you,
Regards,
Danny
Script:
-- Lua Script for Wiser KNX Logic Controller
-- Turn on light randomly between 9:00 PM and 9:30 PM and off between 11:00 PM and 1:00 AM
-- Light group address
local lightGroupAddress = "0/0/18" -- ceno
-- Push button group address
local pushButtonGroupAddress = "0/0/45"
-- Function to switch a light on or off
function switchLight(lightGroupAddress, state)
grp.write(lightGroupAddress, state)
end
-- Function to log messages
function logMessage(message)
log(message)
end
-- Function to get the current time in hours and minutes
function getCurrentTime()
local now = os.date("*t")
return now.hour, now.min
end
-- Function to calculate a random time offset within a range (in seconds)
function getRandomOffset(minMinutes, maxMinutes)
local minSeconds = minMinutes * 60
local maxSeconds = maxMinutes * 60
return math.random(minSeconds, maxSeconds)
end
-- Function to wait until a specific time
function waitUntil(hour, minute)
while true do
local currentHour, currentMinute = getCurrentTime()
if currentHour == hour and currentMinute == minute then
break
end
os.sleep(30) -- Check every 30 seconds
end
end
-- Main function to control the light based on time
function controlLightBasedOnTime()
while true do
-- Wait until 9:00 PM
logMessage("waiting until 9:00 PM")
waitUntil(21, 0)
-- Get a random offset between 0 and 30 minutes
local onOffset = getRandomOffset(0, 30)
logMessage("Waiting " .. onOffset .. " seconds to turn on the light")
os.sleep(onOffset)
-- Turn on the light
switchLight(lightGroupAddress, 1)
logMessage("Light turned on at " .. os.date())
-- Get a random offset between 2 and 4 hours for turning off
local offOffset = getRandomOffset(120, 240)
logMessage("Waiting " .. offOffset .. " seconds to turn off the light")
os.sleep(offOffset)
-- Turn off the light
switchLight(lightGroupAddress, 0)
logMessage("Light turned off at " .. os.date())
-- Wait until the next day
os.sleep(86400 - (os.time() % 86400)) -- Sleep until midnight
end
end
-- Start the function
controlLightBasedOnTime()
Link copied. Please paste this link to share this article on your social media post.
Its caused by your functions that contains while loops, and os.sleeps, you probably use them as event based script as a new instance is started at each event. In the latest FW you can set what event needs to be kept active (first or last instance) to avoid this behavior when using delays in parallel
Link copied. Please paste this link to share this article on your social media post.
Hi DannyV.
this sounds interesting!
Would you mind to share a project-backup?
Of course some general informations like HW, FW-Version are always good to know 😉
Link copied. Please paste this link to share this article on your social media post.
Its caused by your functions that contains while loops, and os.sleeps, you probably use them as event based script as a new instance is started at each event. In the latest FW you can set what event needs to be kept active (first or last instance) to avoid this behavior when using delays in parallel
Link copied. Please paste this link to share this article on your social media post.
Hi Erwin and Thomas,
Thank you for your answers. Is there a better way than using the os.sleep delays for switching on a light for a certain (fixed) time or for an 'away-system' (where lights during evenings switch on and off at certain times)?
Link copied. Please paste this link to share this article on your social media post.
Using the delay in the ETS application (if any available) is always the preferred method, otherwise os.sleep(x) is your only option, keep in mind that event based scripts can run in parallel so you must use the first/last instance setting or os.kill script we used in the past (not needed anymore with the new instance setting option)
Create your free account or log in to subscribe to the board - and gain access to more than 10,000+ support articles along with insights from experts and peers.