Need Help with Lua Script for Group Object Control - 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: Need Help with Lua Script for Group Object Control (/showthread.php?tid=4875) |
Need Help with Lua Script for Group Object Control - josdegroot - 16.07.2023 Hello everyone, I've been working on a Lua script to control a group object in my system, but I'm having some trouble getting it to work as expected. I was hoping someone here might be able to help me figure out what's going wrong. Here's the idea behind the script: I want to check a specific group object (with ID "0/0/21") and see if it has not been turned on for at least 5 minutes. If it hasn't, I want to turn it on for 3 minutes and then turn it off again. Code: -- Define the group object ID I'm using the `grp.getvalue(alias)` function to check the last time the group object was turned on, and the `grp.setvalue(alias, value)` function to turn the group object on and off. However, the script doesn't seem to be working as expected. Does anyone have any ideas about what might be going wrong? Any help would be greatly appreciated! Thanks in advance. RE: Need Help with Lua Script for Group Object Control - Daniel - 17.07.2023 It would be better to do it differently. Instead of making your own timer just use object update time and compare it with os.time to see how long the object was not updated. Code: myobject = grp.find('1/1/1') RE: Need Help with Lua Script for Group Object Control - admin - 17.07.2023 Problems with your script: 1. currentStatus is most likely Boolean and comparing it with 0 won't work because it's true/false. You can simply write it as if currentStatus then instead. 2. Use os.sleep(seconds) instead of os.execute(). 3. There's no grp.setvalue() function - it is called grp.write() RE: Need Help with Lua Script for Group Object Control - josdegroot - 17.07.2023 Tanks for the tips... i tried to execute all the tips in the new script... but it's still not working Code: -- Define the group object RE: Need Help with Lua Script for Group Object Control - Daniel - 18.07.2023 This should be resident script which periodical checks for the values, not event with such delay. use logs to debug it. RE: Need Help with Lua Script for Group Object Control - admin - 18.07.2023 grp.write expects first argument to be a group address or a name, but you are passing a table from grp.find. Use this instead: Code: myobject:write(true) RE: Need Help with Lua Script for Group Object Control - josdegroot - 18.07.2023 Thanks for the reply! This one is working Code: -- Define the group object |