Logic Machine Forum
Change shedulers from a script - 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: Change shedulers from a script (/showthread.php?tid=265)

Pages: 1 2


Change shedulers from a script - buuuudzik - 08.04.2016

Is there a possibility in new firmware to change the Schedulers from script? This will be very helpful especially in the hotels.


RE: Change shedulers from a script - edgars - 08.04.2016

in upcoming release this will not be possible, but for the next versions we have planned this feature. Thanks for suggestion.


RE: Change shedulers from a script - rocfusion - 19.07.2016

Hi,

Is there an ETA when this will be available?

Thanks,


Roger


RE: Change shedulers from a script - admin - 19.07.2016

Which features exactly do you need?


RE: Change shedulers from a script - rocfusion - 19.07.2016

Hi,

I know that we can add\change\remove either scheduled scripts or schedules via the database. But it would be much simpler when there are a functions to do this.

Thanks,

Roger


RE: Change shedulers from a script - jetsetter - 05.09.2016

Hi,

I need at least to be able to enable or disable an existing scheduler based on some logic from a script, so can someone explain how can I do this at least via the database?

It would be also very useful to be able to modify an existing event of a scheduler (time/date/value) as well as be able to remove an event completely or add a new one.


tnx in adv
BR


RE: Change shedulers from a script - Erwin van der Zwart - 05.09.2016

Hi Jetsetter,

With this script you can enable/disable a scheduler:
Code:
-- Get new value for scheduler
value = event.getvalue()

-- Set scheduler name
scheduler_name = 'Scheduler 1'

-- Get schedulers from DB
query = 'SELECT * FROM schedulers'
for _, scheduler in ipairs(db:getall(query)) do
    if scheduler.name == scheduler_name then
       if value == true then
            db:update('schedulers', { active = 1 }, { id = scheduler.id })
            log('Scheduler ' .. scheduler_name .. ' is enabled')

         else
            db:update('schedulers', { active = 0 }, { id = scheduler.id })
          log('Scheduler ' .. scheduler_name .. ' is disabled')
       end
    end
end
-- Call cleanup of old schedulers
clearschedulers()

But why don't you create a logic block with script, create a dummy object for scheduler (linked to input 1 of logic),  your enable/disable object (linked to input 2 of logic) 
and your switching object (linked to output of logic)

This way you can control the output of the scheduler without writing to DB... 

BR,

Erwin van der Zwart


RE: Change shedulers from a script - admin - 05.09.2016

If running RC firmware you must call clearschedulers() after making any changes, otherwise all scheduler events until the end of the day will still run even when the scheduler is disabled.

Simplified Erwin's example:
Code:
name = 'Scheduler 1'
active = event.getvalue()

db:update('schedulers', { active = toboolean(active) }, { name = name })
clearschedulers()



RE: Change shedulers from a script - jetsetter - 05.09.2016

(05.09.2016, 11:06)Erwin van der Zwart Wrote: But why don't you create a logic block with script, create a dummy object for scheduler (linked to input 1 of logic),  your enable/disable object (linked to input 2 of logic) 
and your switching object (linked to output of logic)

This way you can control the output of the scheduler without writing to DB... 

Thank you very much Erwin.
You mean like an AND gate? It is a nice idea, the only problem with this way is that the end user will not know if the scheduler is actually active or not by looking at it at the schedulers page, he should reside in the dummy object I/O at the visualisation...
Any way, I will try both ways, I hope the final release will have some easier way to manipulate the schedulers.

Thank you all.


RE: Change shedulers from a script - mlaudren - 14.12.2016

Hi,

I'm trying something similar

I'm able to add an entry in a scheduler, but nothing happen at the specified time.
If I add it manually using the GUI, it's ok.

clearschedulers() function return an error : `attempt to call global 'clearSchedulers' (a nil value)`

Any idea?


RE: Change shedulers from a script - Erwin van der Zwart - 14.12.2016

Hi,

You probably use FW that don't have the function yet..

What HW/FW do you use? (probably HL/SL?)

BR,

Erwin


RE: Change shedulers from a script - admin - 15.12.2016

Looks like this function is available only to GUI, you can add it to common functions to use in your scripts.

Code:
function clearschedulers()
  local files = io.ls('/tmp')
  for _, file in ipairs(files) do
    if file:find('lm-scheduler-', 1, true) then
      os.remove('/tmp/' .. file)
    end
  end
end



RE: Change shedulers from a script - mlaudren - 15.12.2016

Yep, I have a hL.

FW 1.5.1

I had another tips :

add this at the begenning of the script.

Code:
ngx = {}
json= {}
dofile("/lib/genohm-scada/web/lib.lua")

Which one is prefered?


RE: Change shedulers from a script - rocfusion - 02.01.2017

Hi,

Has there been any progress on this in the latest firmware?

Thanks,


Roger


RE: Change shedulers from a script - mlaudren - 03.01.2017

I was able to change schedulers and scheduler's event from a script.
So I think all can be done if you know how to do it.

If admin is agree, I'll post a sample here.


RE: Change shedulers from a script - admin - 04.01.2017

You can change schedulers via database queries. This is not recommended since database schema might change between firmware releases, but for now there's no other way.


RE: Change shedulers from a script - jetsetter - 31.08.2017

(04.01.2017, 13:53)admin Wrote: You can change schedulers via database queries. This is not recommended since database schema might change between firmware releases, but for now there's no other way.

Hi, any news on when we will be able to modify schedulers without DB queries? Is it going to be included in the upcoming release?

tnx


RE: Change shedulers from a script - toujour - 09.01.2019

I'm interested too


RE: Change shedulers from a script - rocfusion - 24.03.2019

Hi, is there any change to for RC1?

thx

Roger


RE: Change shedulers from a script - admin - 25.03.2019

Not yet, can you explain your use case for this in more detail?