This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Grow light time control script
#1
Hi.
My soulmate is working with plants these days, and wants ligths to turn on and off in specified times of day.
I try to make a script to make here able to automate and decide this from Moasic.
Created 2 virtual groupadresses for on and off time (hh:mm), and made a time widget in Moasic for her to change times at her own will..
Group adresses is formatted as 3byte time/date.

Then I wrote this resident script to run every 60 seconds.
But it fails in many ways. I tried to log output but get errors.
Someone want to help out?
Could it be different time formats? first log entry returns a nil value, so why is it not reading my object data?

Code:
on_time = grp.getvalue('31/1/13')
off_time = grp.getvalue('31/1/14')
--log entry to confirm data is read
log(on_time)
log(on_time)

--log state of light to confirm change
    lightstate = grp.getvalue('31/1/17')
    log('Light turned off at ' .. os.date('%H:%M:%S') .. ' set to' ..ligthstate)

-- time set as hour and minute. Seconds never used when set, will always be 00, datatype is 3 byte time/day this is tested ok.
--as time is set by only hour and minute and seconds is never set in the on and off times, seconds have to be equal 00 when comparing. (3 byte time/day)
if os.date('%H:%M:00') == on_time then
    grp.write('31/1/15', true)
  --log state of light to confirm change
      lightstate = grp.getvalue('31/1/17')
    log("Light turned on at " .. os.date('%H:%M:%S') .. 'set to' ..lightstate)
elseif os.date('%H:%M:00') == off_time then
    grp.write('31/1/15', false)
  --log state of light to confirm change
    lightstate = grp.getvalue('31/1/17')
    log('Light turned off at ' .. os.date('%H:%M:%S') .. ' set to' ..ligthstate)
end
Reply
#2
Still no progress in this script.
I manage to make this in a schedule an it works fine. But I want to easy change on and off times from Moasic, changing schedule with a script may also be a possibility. As described above i have two groups defined as 3 byte time/date to set on and off times.
Im not using the date part and want to only use the time from the group as this will run every day. Maybe some of the problem is that the datatype is wrong for this? But need the GA to be intercompatible with the KNX system as i may put it on some of the smart displays to show and change.

So if someone is helping me to make this script work either way, (change schedule script or fixing this script as i first attempted) I (and my better half soulmate) would be very grateful! 

Btw. (@admin @Daniel)
Noticed the users is not able to access schedule menu in Android app when connected local, menu is not visible for either user. But if logged in through cloud, schedule menu is available. Is this correct behaviour?
Reply
#3
Create a scheduled script that runs every minute:
Code:
function tomin(t)
  return t.hour * 60 + t.min
end

ontime = grp.getvalue('31/1/13')
offtime = grp.getvalue('31/1/14')
now = tomin(os.date('*t'))

on = tomin(ontime) <= now and now <= tomin(offtime)
grp.checkwrite('31/1/15', on)
Make sure that you are running the latest firmware. There was a bug that causes grp.getvalue() to return nil in rare cases.

See this for a possible cause that Schedulers are not visible: https://forum.logicmachine.net/showthrea...3#pid28493
Reply
#4
Thanks for answer.
The Sceduler was hidden in the default view. Case solved and I learned that trick :-)

I have upgraded to latest firmware verison, I was at RC2 version.
The script you gave also returns a nil value fault, after firmware upgrade. 
Is there some fault with data inserted from Moasic widget that makes this problem? Do I need to add date as well?
I dont need the date as I will only work with the time of any day.


                 
Reply
#5
Script uses 31/1/x address while you have 32/1/x
Reply
#6
(01.05.2023, 10:29)admin Wrote: Script uses 31/1/x address while you have 32/1/x

Thanks! 
Thats a super typo from me when learning lua and seeks fault on my own. No wonder notihing works...
Your script was mutch more slim and simple!
The script runs flawless now!
Reply


Forum Jump: