Logic Machine Forum
Changing Schedule time via script for visulation page - 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: Changing Schedule time via script for visulation page (/showthread.php?tid=686)



Changing Schedule time via script for visulation page - savaskorkmaz - 20.03.2017

Hello ,

We have a thermostat page in our project . This thermostat page is communication with a modbus thermostat. 
We created a time scheduler which turn on and off the thermostat and it's working.
But my customer asked that I don't want to go another page for changing scheduler.
Because of that I created a turn on time knx object, turn off knx object and a time scheduler active decative object in my page.
I want that, when i push the time scheduler active object, a script will enable that scheduler and same script will change event times of scheduler with value of  turn on time knx object, turn off knx object in the screen

Regards,


RE: Changing Schedule time via script for visulation page - admin - 21.03.2017

First, you need to get ID of each event you want to change:
Code:
log(db:getall('SELECT * FROM scheduler_events'))

Then you can use this function to change event time:
Code:
hour = 12 -- event time / start hour
min = 30 -- event time / minute
id = 42 -- event DB id

db:update('scheduler_events', {
  start_hour = hour,
  start_min = min
}, { id = id })

You can change active state of schedulers by name:
Code:
name = 'My scheduler'
active = 1 -- 1 = active, 0 = inactive
db:update('schedulers', { active = active }, { name = name })

After each change you need to clear schedulers cache:
http://forum.logicmachine.net/showthread.php?tid=265&pid=2804#pid2804