Script with last updated event - 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: Script with last updated event (/showthread.php?tid=777) |
Script with last updated event - Mr.D - 06.05.2017 Hi, I am trying to write a event-script that includes a check if a certain object has been changed/updated within the last 16 hours. For example: If a certain door has been opened/changed status within the last 16 hours, and someone sets the house in night mode, then a certain action should be performed. value = event.getvalue value1 = 1/1/1 (if door opened within 16 hours == true it not false) if value == true and value1 == true then grp.write('3/3/3', 50) end Thanks, Mr.D RE: Script with last updated event - buuuudzik - 06.05.2017 For checking if some object was updated in the last 16 hours you can do this: Code: last_timestamp = grp.find("1/1/1").updatetime RE: Script with last updated event - Mr.D - 06.05.2017 (06.05.2017, 13:09)buuuudzik Wrote: For checking if some object was updated in the last 16 hours you can do this: Thanks, Works like a charm! BR, Mr.D RE: Script with last updated event - buuuudzik - 07.05.2017 For such long period(16hours) sometimes you must also consider the time shift. For this you can use: Code: -- is daylight saving time? RE: Script with last updated event - Mr.D - 11.05.2017 Hi, How do I use the os.microtime() if I would want an event-script to react only if its between certain hours of the day? For example: Event-based script now = os.microtime() if now == between 2 o'clock and 4 o'clock then grp.write(1/1/1) end BR, Mr RE: Script with last updated event - Jørn - 11.05.2017 os.microtime just gives you the time in milliseconds. Maybe the easiest way is to create a new object that is controlled with the scheduler, set it to turn on at 2, and turn off at 4. This way it will be easier to just change the scheduler than editing the script as well. Start your script with if grp.getvalue('Schedule switch') == true then Mvh RE: Script with last updated event - Erwin van der Zwart - 11.05.2017 Hi, Try this: Code: -- Settings ------------------------------ BR, Erwin RE: Script with last updated event - Mr.D - 13.05.2017 Hi Erwin, Thanks for your help. However I can not get this to work: Code: value1 = grp.getvalue('Timer - Settverdi - Alarm') What am I doing wrong here...? BR. Mr.D RE: Script with last updated event - Erwin van der Zwart - 13.05.2017 Hi, Just tested it and the script works as intended, so you might need to check on of these items: 1) Is your script activated? 2) Are the object names in your script correct? 3) Is the object type from object 'Timer - Settverdi - Alarm' the same for object 'Timer - Alarm' ? (can it handle the value from other object) 4) Is your time / timezone correct? BR, Erwin RE: Script with last updated event - Mr.D - 16.05.2017 Hi Erwin, I cant figure out whats wrong... 1) Is your script activated? 2) Are the object names in your script correct? 3) Is the object type from object 'Timer - Settverdi - Alarm' the same for object 'Timer - Alarm' ? (can it handle the value from other object) 4) Is your time / timezone correct? For question 1, 2 and 3: The following code works: Event-Based Code: value1 = grp.getvalue('Timer - Settverdi - Alarm') Event-Based Code: value1 = grp.getvalue('Timer - Settverdi - Alarm') I have set up the spacelynk with a NTP (time.apple.com) and the timezone is Europe/Oslo. The update times for objects are correct as far as I can see. I have also tried setting min = 01 and max = 23 and still nothing happens... BR, Mr.D RE: Script with last updated event - Erwin van der Zwart - 16.05.2017 Hi, Do you see errors in the error log? BR, Erwin RE: Script with last updated event - Mr.D - 18.05.2017 Hi Erwin, I could not find anything in the error log. However, I copied the code and deleted the script. Created a new script for the same tag object and pasted the code into the new script. No changes what so ever to the code, but now it works... So I am one happy camper Thanks for your help! Mr.D |