LogicMachine Forum
scripitng - Printable Version

+- LogicMachine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: scripitng (/showthread.php?tid=5809)



scripitng - mariosp - 30.12.2024

Good evening, I would like your help about a event base script.
My client wants the lights to flash quickly (turn on and off) whenever a zone is breached. Can someone assist me?


RE: scripitng - buuuudzik - 30.12.2024

(30.12.2024, 12:42)mariosp Wrote: Good evening, I would like your help about a event base script.
My client wants the lights to flash quickly (turn on and off) whenever a zone is breached. Can someone assist me?

Could you clarify what you mean by “quickly”? How many zones are there? How many can be breached simultaneously?

The best solution is using sequencers in KNX modules, which can be triggered by a boolean object. If you plan to send many commands simultaneously over the TP bus, it could, of course, negatively impact the bus’s performance.

However, if we are talking about a few zones, sometimes controlled simultaneously, a good solution would be:
an event-based script that reacts to a change in the status of a given zone, checks if any zone is active, and then activates/deactivates a resident script. This script toggles the lighting in the respective zone and waits for a set time before toggling again.

It could be a good start:

Create objects with such names:
Light sequence_1_status with tag light_sequencer
Light sequence_1_cmd for light control

Number 1 is an index of your zone. Of course you can change this name but you need to tweak also the script to use another pattern.

Event script run on tag "light_sequencer":
Code:
if toboolean(event.getvalue()) then   script.enable("Light sequencer") end


Resident script 0s with a name "Light sequencer":
Code:
if not initialized then   initialized = true   value = false end -- Toggle value value = not value -- Check all zones statuses and toggle commands for enabled zones all_zones = grp.tag("light_sequencer") function getZoneCmdName(statusName)   id = statusName:match('_(%d+)_status')   return 'Light sequence_' .. tostring(id) .. '_cmd' end function toggleZone(statusName, value)   cmdName = getZoneCmdName(statusName)   grp.write(cmdName, value) end -- If all zones are disabled, disable the script local should_be_enabled = false for k,v in ipairs(all_zones) do   cmdName = getZoneCmdName(v.name)     log(k, v.address, v.name, v.value)   if toboolean(v.value) == true then     should_be_enabled = true     grp.write(cmdName, value)   else     -- Switch of a zone light if its enabled     if toboolean(grp.getvalue(cmdName)) == true then       grp.write(cmdName, false)     end   end end -- Switch off all lights and disable the script if none zone is enabled if not should_be_enabled then   script.disable(_SCRIPTNAME) end -- Wait a selected time for the next change in seconds sleep(1)