I have an upcoming project which I would like your support regarding the Lua Scripting.
A LM5 Lite will be used for this connected on the KNX TP Main Line.
The functions I need to implement are described below:
Function 1 :
175 KNX Detectors must be monitored if are online on the KNX bus - KNX Watchdog script running every hour.
If one or more devices are offline then:
Step 1: Send email with a certain subject and body including the phys. address of the device(s) being offline.
Step 2: Check (tagged objects) and reset if necessary the corresponding motion detection objet to 'false', of the device(s) being offline.
Function 2:
Calculate (OR Logic) if there is motion in the building; for this I have the nice resident script from the forum.
This will send a bit object as a result where then I will have event script for:
Step 1: If not motion then grp.write('xx/xx/xx', true)
else (reset timer from step 3) end
Step 2: Store a timestamp of the event
Step 3: Resident Script every 1sec to compare this timestamp with the actual time of the LM. If delta (t) > 900 (sec) then grp.checkwrite('xx/xx/xx, true)
else grp.checkwrite('xx/xx/xx', false).
Thank you in advance for the support and always being helpful and active.
--Address count
ie=1
while (addresses[ie]~=nil) do
ie=ie+1
end
--ping addresses
content='<b>KNX Physical Address check</b><br><br>'
content2=''
--log('Checking')
for i = 1, ie-1, 1 do
result = tostring(knxlib.ping(addresses[i]))
if result == 'false' then
content2 = content2 ..'Address: '.. addresses[i] .. ' - ' .. '<b>ERROR!</b>' .. '<br>'
end
end
--log('Check completed...')
--send email
if content2 ~= '' then
res, err = mail('feedback@buildingautomation.ee', 'Physical Address check result', content .. content2)
end
Probably I would use Dynamic Folder in ETS to get all needed devices with physical addresses and save/print it to pdf. Copy all PA-s to notepad++ and use replace function to modify PA-s (like they are in script on line 2 to 13) that you can copy all addresses to script at once. It's about 10 min job to get all 175 addresses into script.
I hope this helps...
This can be optimized further by checking if the device as sent a telegram to a specific group address in the last X minutes. If it did then there's no point in checking the physical address. It's also advisable to add a small delay between each check so the bus is not overloaded.
For table iteration you can use ipairs, then the count loop is not needed (you can also use #addresses to get the table length).
Code:
for _, address in ipairs(addresses) do
result = knxlib.ping(address)
if result == false then
content2 = content2 .. 'Address: ' .. address .. ' - <b>ERROR!</b><br>'
end
end
(13.08.2021, 09:21)admin Wrote: This can be optimized further by checking if the device as sent a telegram to a specific group address in the last X minutes. If it did then there's no point in checking the physical address. It's also advisable to add a small delay between each check so the bus is not overloaded.
For table iteration you can use ipairs, then the count loop is not needed (you can also use #addresses to get the table length).
Code:
for _, address in ipairs(addresses) do
result = knxlib.ping(address)
if result == false then
content2 = content2 .. 'Address: ' .. address .. ' - <b>ERROR!</b><br>'
end
end
for _, address in ipairs(addresses) do
result = knxlib.ping(address)
os.sleep(0.5)
if result == false then
content2 = content2 .. 'Motion Detector - Address: ' .. address .. ' - <b>IS OFFLINE!</b><br>'
end
end
--send email
if content2 ~= '' then
res, err = mail('123456@gmail.com', 'KNX Installation Fault',content2)
end
After the mail function I would like to reset the motion detection telegram of the device(s) that is offline. I was thinking to tag the group address with the phys address and then have a function in this scipt to write to the result a false.
How can i do this?
Or can I add an array of data to include the address and next to it the coresponding motion detection GA?
for _, dev in ipairs(devices) do
result = knxlib.ping(dev.address)
if result == false then
content = content .. 'Motion Detector - Address: ' .. dev.address .. ' - <b>IS OFFLINE!</b><br>'
grp.checkwrite(dev.motion, false)
end
os.sleep(0.5)
end
if content ~= '' then
res, err = mail('123456@gmail.com', 'KNX Installation Fault', content)
end
for _, dev in ipairs(devices) do
result = knxlib.ping(dev.address)
if result == false then
content = content .. 'Motion Detector - Address: ' .. dev.address .. ' - <b>IS OFFLINE!</b><br>'
grp.checkwrite(dev.motion, false)
end
os.sleep(0.5)
end
if content ~= '' then
res, err = mail('123456@gmail.com', 'KNX Installation Fault', content)
end
I have noticed that in same casses the watchdog is very sensitive. I believe if the moment of the knx device ping there is high bus load the LM will not get a reply and think a device is offline.
How many times is the ping sent to the bus? Could we set a three times repeat in case there is no reply from a device before considering it as offline? or a delay for the reply maybe?
An other thing I would like to have is if possible to include a date/time stamp before or after the offline device. Something to indicate the date time this error occured.
The date and time from the email could be used also as an indicator but it would be nice to have in the content of it also.
If this script is ment to run every hour, is there a way to accumulate the errors if any and then send them only once per day by mail?
You can send ping several times like this. You can also increase the sleep time between each device check from 0.5 to a higher value if needed.
Code:
for i = 1, 3 do
result = knxlib.ping(dev.address)
if result then
break
else
os.sleep(1)
end
end
You can get current date/time by calling os.date(). You can use this example to store events into a storage log: https://forum.logicmachine.net/showthread.php?tid=350
A separate scheduled script can send event log data to email once per day.
(30.12.2022, 10:03)Daniel Wrote: The ping parameter should be a physical address of a device you want to ping not a group address. Like this
result = knxlib.ping('1.1.1')
How do I transfer it to the screen if it is not with a group address? to be able to ping one device or another.
(31.12.2022, 08:21)Erwin van der Zwart Wrote: You could use a string object, but i would use 3 byte objects 1.2.3 and fetch the entered values with script to avoid invalid user input.
Limit the input values to the KNX standard on the start and middle object value in the object parameters.