Logic Machine Forum
blink light - Printable Version

+- Logic Machine 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: blink light (/showthread.php?tid=5934)



blink light - Andrea Becagli - 18.03.2025

I have flood sensor witch sends me an alarm in case of flood. When the alarm state is triggered i need to make a light blink constantly until the alarm stops. 


I created an event-based script triggered by the state of the sensor and inside I created a while loop inside:

Code:
while grp.getvalue("stato sensore") do
  grp.write("luce", true)
  os.sleep(1)
  grp.write("luce", false)
  os.sleep(1)
end


Now it works but it easily overloads the CPU pretty easily. Is there a better way to do this?


RE: blink light - admin - 18.03.2025

See if the script triggers something else. One telegram per second should not cause high CPU load.
Set event script execution mode to "Last instance only".


RE: blink light - Andrea Becagli - 18.03.2025

(18.03.2025, 10:02)admin Wrote: See if the script triggers something else. One telegram per second should not cause high CPU load.
Set event script execution mode to "Last instance only".

Well, it does because the light is WLED led strip so it is not directly KNX but through API it became KNX. It actually works like this:

light group address >  triggers an event-based script > calls a function from the library i created

is that too much? Does using metatables heavily impact the CPU? I attached the TAG- activated event-script 

Code:
ga = event.dst
dt = grp.find(ga).datatype
ga_stato = get_st_add(ga)
value = event.getvalue()

wled = wled_ctrl:init({ip = "10.11.24.106", debug_mode = false})



if dt==1001 then
  wled:accensione(value, ga_stato)
elseif dt == 5001 then
  wled:luminosita(value, ga_stato)
elseif dt == 232600 then
  wled:colore(value, ga_stato)
elseif dt == 6 then
  wled:effetto(value, ga_stato)
elseif dt == 7 then
  wled:color_temp(value, ga_stato)
elseif dt == 8 then
  wled:palette(value, ga_stato)
else
  log("rec")
  log(wled:stato())
end
 



RE: blink light - admin - 18.03.2025

Install System load app on LM and check which process is causing high CPU load. Sometimes I/O load can be high without actual high CPU load.


RE: blink light - Andrea Becagli - 18.03.2025

(18.03.2025, 11:05)admin Wrote: Install System load app on LM and check which process is causing high CPU load. Sometimes I/O load can be high without actual high CPU load.

Ok I found the problem, kind of stupid: since I have 15 WLED strips and I using a generated general command to switch them all off and back on, I was sendind 15 telegrams each second.

I solved using the API to directly switch on and off all the strips. I now have a way lower CPU usage.

Thanks