Page 2 of 4
Re: LUA: Summer / Winter from timeofday or other...
Posted: Sunday 14 February 2016 16:58
by sincze
The wiki is always available for help
https://www.domoticz.com/wiki/User_variables
It has a nice description on how to fill user variables that you can use in domoticz.
And it uses this nice function:
Code: Select all
function WhichSeason()
local tNow = os.date("*t")
local dayofyear = tNow.yday
local season
if (dayofyear >= 79) and (dayofyear < 172) then season = "Spring"
elseif (dayofyear >= 172) and (dayofyear < 266) then season = "Summer"
elseif (dayofyear >= 266) and (dayofyear < 355) then season = "Autumn"
else season = "Winter"
end
return season
end
Re: LUA: Summer / Winter from timeofday or other...
Posted: Sunday 14 February 2016 18:47
by Derik
jvdz wrote:Derik wrote:The option from Jos, is without any hard to get stuff...... I got him working in a few minutes....
Without cron is better for my backup...
Did you see my post above your's since we posted around the same time?
Jos
Yes i am happy with your code works perfect....
Re: LUA: Summer / Winter from timeofday or other...
Posted: Saturday 20 February 2016 20:26
by Jan Jansen
Today I made a beginning with user variables and LUA.

- Knipsel 1.PNG (73.06 KiB) Viewed 4245 times
I would like to connect a switch to the user variable dark but I did not succeed, using blockly.

- Knipsel 2.PNG (21.07 KiB) Viewed 4245 times
I hope somebody can help.
I can not write LUA programs, I only use blockly. But today, and foor the first time, I managed to copy a program from the WIKI into Domoticz.
Thanks in advance.
Re: LUA: Summer / Winter from timeofday or other...
Posted: Sunday 08 January 2017 23:35
by Martijn85
Thanks for the script @jvdz I have changed it a little so there`s only one selector switch.

- 2017_01_08_23_33_47_Domoticz.png (63.94 KiB) Viewed 4026 times
This is the (changed) LUA script:
Code: Select all
-- script_time_season.lua
-- The change of state is a fixed date:
-- Lente: 21 maart t/m 20 juni
-- Zomer: 21 juni t/m 20 september
-- Herfst: 21 september t/m 20 december
-- Winter: 21 december t/m 20 maart
commandArray = {}
time = os.date("*t")
-- check once a minute for the season to change
if (time.month == 12 and time.day >= 21)
or (time.month == 1)
or (time.month == 2)
or (time.month == 3 and time.day < 21) then
Seizoen = 'Winter'
elseif (time.month == 3)
or (time.month == 4)
or (time.month == 5)
or (time.month == 6 and time.day < 21) then
Seizoen = 'Voorjaar'
elseif (time.month == 6)
or (time.month == 7)
or (time.month == 8)
or (time.month == 9 and time.day < 21) then
Seizoen = 'Zomer'
elseif (time.month == 9)
or (time.month == 10)
or (time.month == 11)
or (time.month == 12 and time.day < 21) then
Seizoen = 'Herfst'
else
print('Something wrong in the season logic :)')
end
if Seizoen == 'Voorjaar' then
commandArray['Seizoen'] = 'Set Level: 10'
elseif Seizoen == 'Zomer' then
commandArray['Seizoen'] = 'Set Level: 20'
elseif Seizoen == 'Herfst' then
commandArray['Seizoen'] = 'Set Level: 30'
elseif Seizoen == 'Winter' then
commandArray['Seizoen'] = 'Set Level: 40'
else
print('Het seizoen is veranderd, het is nu '..Seizoen)
end
return commandArray
Re: LUA: Summer / Winter from timeofday or other...
Posted: Monday 20 February 2017 11:45
by mikeoo
Martijn85 wrote:Thanks for the script @jvdz I have changed it a little so there`s only one selector switch.
2017_01_08_23_33_47_Domoticz.png
This is the (changed) LUA script:
Code: Select all
-- script_time_season.lua
-- The change of state is a fixed date:
-- Lente: 21 maart t/m 20 juni
-- Zomer: 21 juni t/m 20 september
-- Herfst: 21 september t/m 20 december
-- Winter: 21 december t/m 20 maart
commandArray = {}
time = os.date("*t")
-- check once a minute for the season to change
if (time.month == 12 and time.day >= 21)
or (time.month == 1)
or (time.month == 2)
or (time.month == 3 and time.day < 21) then
Seizoen = 'Winter'
elseif (time.month == 3)
or (time.month == 4)
or (time.month == 5)
or (time.month == 6 and time.day < 21) then
Seizoen = 'Voorjaar'
elseif (time.month == 6)
or (time.month == 7)
or (time.month == 8)
or (time.month == 9 and time.day < 21) then
Seizoen = 'Zomer'
elseif (time.month == 9)
or (time.month == 10)
or (time.month == 11)
or (time.month == 12 and time.day < 21) then
Seizoen = 'Herfst'
else
print('Something wrong in the season logic :)')
end
if Seizoen == 'Voorjaar' then
commandArray['Seizoen'] = 'Set Level: 10'
elseif Seizoen == 'Zomer' then
commandArray['Seizoen'] = 'Set Level: 20'
elseif Seizoen == 'Herfst' then
commandArray['Seizoen'] = 'Set Level: 30'
elseif Seizoen == 'Winter' then
commandArray['Seizoen'] = 'Set Level: 40'
else
print('Het seizoen is veranderd, het is nu '..Seizoen)
end
return commandArray
Nice one thanks for the script. Only the Print commands are not working because the IF is always true for 1 of the 4 so it will never gets to the else.
Your seasons picture (switch) is not correct . Lente needs to be Zomer
Tweaked your scripts a bit and added colors to the print commands.Only the PRINT command is now logged every minute. Still looking for a way to adjust it to only once.
Code: Select all
-- script_time_season.lua
-- The change of state is a fixed date:
-- Lente: 21 maart t/m 20 juni
-- Zomer: 21 juni t/m 20 september
-- Herfst: 21 september t/m 20 december
-- Winter: 21 december t/m 20 maart
commandArray = {}
time = os.date("*t")
-- check once a minute for the season to change
if (time.month == 12 and time.day >= 21)
or (time.month == 1)
or (time.month == 2)
or (time.month == 3 and time.day < 21) then
Seizoen = 'Winter'
elseif (time.month == 3)
or (time.month == 4)
or (time.month == 5)
or (time.month == 6 and time.day < 21) then
Seizoen = 'Lente'
elseif (time.month == 6)
or (time.month == 7)
or (time.month == 8)
or (time.month == 9 and time.day < 21) then
Seizoen = 'Zomer'
elseif (time.month == 9)
or (time.month == 10)
or (time.month == 11)
or (time.month == 12 and time.day < 21) then
Seizoen = 'Herfst'
else
print('<font color="red">Logica van de seizoenen kloppen niet!!!</font>')
end
if Seizoen == 'Lente' then
commandArray['Seizoen'] = 'Set Level: 10'
print('<font color="blue">Seizoen aangepast naar Lente</font>')
elseif Seizoen == 'Zomer' then
commandArray['Seizoen'] = 'Set Level: 20'
print('<font color="blue">Seizoen aangepast naar Zomer</font>')
elseif Seizoen == 'Herfst' then
commandArray['Seizoen'] = 'Set Level: 30'
print('<font color="blue">Seizoen aangepast naar Herfst</font>')
elseif Seizoen == 'Winter' then
commandArray['Seizoen'] = 'Set Level: 40'
print('<font color="blue">Seizoen aangepast naar Winter</font>')
else
print('<font color="blue">Geen actie nodig voor het aanpassen van de seizoenen</font>')
end
return commandArray
Re: LUA: Summer / Winter from timeofday or other...
Posted: Wednesday 15 March 2017 22:02
by Martijn85
Thanks for the update/tweak!
mikeoo wrote:Only the PRINT command is now logged every minute. Still looking for a way to adjust it to only once.
That would be nice indeed! For now i have added this:
Code: Select all
-- check every 720 minutes for the season to change
if((time.min % 720)==0) then
end
Now it's running every 12 hours, not every minute.
The complete script:
Code: Select all
-- script_time_season.lua
-- The change of state is a fixed date:
-- Lente: 21 maart t/m 20 juni
-- Zomer: 21 juni t/m 20 september
-- Herfst: 21 september t/m 20 december
-- Winter: 21 december t/m 20 maart
commandArray = {}
time = os.date("*t")
-- check every 720 minutes for the season to change
if((time.min % 720)==0) then
-- check once a minute for the season to change
if (time.month == 12 and time.day >= 21)
or (time.month == 1)
or (time.month == 2)
or (time.month == 3 and time.day < 21) then
Seizoen = 'Winter'
elseif (time.month == 3)
or (time.month == 4)
or (time.month == 5)
or (time.month == 6 and time.day < 21) then
Seizoen = 'Lente'
elseif (time.month == 6)
or (time.month == 7)
or (time.month == 8)
or (time.month == 9 and time.day < 21) then
Seizoen = 'Zomer'
elseif (time.month == 9)
or (time.month == 10)
or (time.month == 11)
or (time.month == 12 and time.day < 21) then
Seizoen = 'Herfst'
else
print('<font color="red">Logica van de seizoenen kloppen niet!!!</font>')
end
if Seizoen == 'Lente' then
commandArray['Seizoen'] = 'Set Level: 10'
print('<font color="blue">Seizoen aangepast naar Lente</font>')
elseif Seizoen == 'Zomer' then
commandArray['Seizoen'] = 'Set Level: 20'
print('<font color="blue">Seizoen aangepast naar Zomer</font>')
elseif Seizoen == 'Herfst' then
commandArray['Seizoen'] = 'Set Level: 30'
print('<font color="blue">Seizoen aangepast naar Herfst</font>')
elseif Seizoen == 'Winter' then
commandArray['Seizoen'] = 'Set Level: 40'
print('<font color="blue">Seizoen aangepast naar Winter</font>')
else
print('<font color="blue">Geen actie nodig voor het aanpassen van de seizoenen</font>')
end
end
return commandArray
Re: LUA: Summer / Winter from timeofday or other...
Posted: Tuesday 30 May 2017 22:23
by mlamie
Thanks for the nice lua script. Now I have to find a good use case

Re: LUA: Summer / Winter from timeofday or other...
Posted: Tuesday 30 May 2017 22:26
by Derik
mlamie wrote:Thanks for the nice lua script. Now I have to find a good use case

Same switch for other stuff in winter and summer
lights longer or shorter
etc
Re: LUA: Summer / Winter from timeofday or other...
Posted: Friday 02 June 2017 14:15
by Jan Jansen
Martijn85 wrote:Thanks for the update/tweak!
mikeoo wrote:Only the PRINT command is now logged every minute. Still looking for a way to adjust it to only once.
That would be nice indeed! For now i have added this:
Code: Select all
-- check every 720 minutes for the season to change
if((time.min % 720)==0) then
end
Now it's running every 12 hours, not every minute.
The complete script:
Code: Select all
-- script_time_season.lua
-- The change of state is a fixed date:
-- Lente: 21 maart t/m 20 juni
-- Zomer: 21 juni t/m 20 september
-- Herfst: 21 september t/m 20 december
-- Winter: 21 december t/m 20 maart
commandArray = {}
time = os.date("*t")
-- check every 720 minutes for the season to change
if((time.min % 720)==0) then
-- check once a minute for the season to change
if (time.month == 12 and time.day >= 21)
or (time.month == 1)
or (time.month == 2)
or (time.month == 3 and time.day < 21) then
Seizoen = 'Winter'
elseif (time.month == 3)
or (time.month == 4)
or (time.month == 5)
or (time.month == 6 and time.day < 21) then
Seizoen = 'Lente'
elseif (time.month == 6)
or (time.month == 7)
or (time.month == 8)
or (time.month == 9 and time.day < 21) then
Seizoen = 'Zomer'
elseif (time.month == 9)
or (time.month == 10)
or (time.month == 11)
or (time.month == 12 and time.day < 21) then
Seizoen = 'Herfst'
else
print('<font color="red">Logica van de seizoenen kloppen niet!!!</font>')
end
if Seizoen == 'Lente' then
commandArray['Seizoen'] = 'Set Level: 10'
print('<font color="blue">Seizoen aangepast naar Lente</font>')
elseif Seizoen == 'Zomer' then
commandArray['Seizoen'] = 'Set Level: 20'
print('<font color="blue">Seizoen aangepast naar Zomer</font>')
elseif Seizoen == 'Herfst' then
commandArray['Seizoen'] = 'Set Level: 30'
print('<font color="blue">Seizoen aangepast naar Herfst</font>')
elseif Seizoen == 'Winter' then
commandArray['Seizoen'] = 'Set Level: 40'
print('<font color="blue">Seizoen aangepast naar Winter</font>')
else
print('<font color="blue">Geen actie nodig voor het aanpassen van de seizoenen</font>')
end
end
return commandArray
I tried the customized script but the relevant selector is updated every hour . I don't know what's wrong.
Re: LUA: Summer / Winter from timeofday or other...
Posted: Friday 02 June 2017 14:34
by jvdz
Jan Jansen wrote:
I tried the customized script but the relevant selector is updated every hour . I don't know what's wrong.
Makes sense i think, as the variable time.min will contain a value between 0 and 59 so the below statement is true when it is 0:
Right?
Jos
Re: LUA: Summer / Winter from timeofday or other...
Posted: Friday 02 June 2017 15:11
by Jan Jansen
I only see that it does not work as desired. Lua is still a challenge for me. This certainly applies to the variable time.
Re: LUA: Summer / Winter from timeofday or other...
Posted: Friday 02 June 2017 16:32
by jvdz
Without testing I guess that statement should be
Code: Select all
if (((time.hour*60+time.min) % 720) == 0) then
Jos
Re: LUA: Summer / Winter from timeofday or other...
Posted: Saturday 03 June 2017 19:57
by Jan Jansen
@ Jos
Your statement is ok.
Re: LUA: Summer / Winter from timeofday or other...
Posted: Tuesday 06 June 2017 22:56
by zicht
Jan Jansen wrote:Today I made a beginning with user variables and LUA.
Knipsel 1.PNG
I would like to connect a switch to the user variable dark but I did not succeed, using blockly.
Knipsel 2.PNG
I hope somebody can help.
I can not write LUA programs, I only use blockly. But today, and foor the first time, I managed to copy a program from the WIKI into Domoticz.
Thanks in advance.
Hi !
Since you do not know lua :
I dont use blocky, but i see you have a string variable ?
Are you i Blockey also using string compaire and not boolean values ?
mixing things can mess things up.
Try using some text like "ok" and "nok" instead of true an false just to test --> but on both so in the user var and in the blocky both the same of course.
Re: LUA: Summer / Winter from timeofday or other...
Posted: Monday 26 June 2017 10:39
by niki_lauda
Martijn85 wrote:Thanks for the update/tweak!
mikeoo wrote:Only the PRINT command is now logged every minute. Still looking for a way to adjust it to only once.
That would be nice indeed! For now i have added this:
Code: Select all
-- check every 720 minutes for the season to change
if((time.min % 720)==0) then
end
Now it's running every 12 hours, not every minute.
The complete script:
Code: Select all
-- script_time_season.lua
-- The change of state is a fixed date:
-- Lente: 21 maart t/m 20 juni
-- Zomer: 21 juni t/m 20 september
-- Herfst: 21 september t/m 20 december
-- Winter: 21 december t/m 20 maart
commandArray = {}
time = os.date("*t")
-- check every 720 minutes for the season to change
if((time.min % 720)==0) then
-- check once a minute for the season to change
if (time.month == 12 and time.day >= 21)
or (time.month == 1)
or (time.month == 2)
or (time.month == 3 and time.day < 21) then
Seizoen = 'Winter'
elseif (time.month == 3)
or (time.month == 4)
or (time.month == 5)
or (time.month == 6 and time.day < 21) then
Seizoen = 'Lente'
elseif (time.month == 6)
or (time.month == 7)
or (time.month == 8)
or (time.month == 9 and time.day < 21) then
Seizoen = 'Zomer'
elseif (time.month == 9)
or (time.month == 10)
or (time.month == 11)
or (time.month == 12 and time.day < 21) then
Seizoen = 'Herfst'
else
print('<font color="red">Logica van de seizoenen kloppen niet!!!</font>')
end
if Seizoen == 'Lente' then
commandArray['Seizoen'] = 'Set Level: 10'
print('<font color="blue">Seizoen aangepast naar Lente</font>')
elseif Seizoen == 'Zomer' then
commandArray['Seizoen'] = 'Set Level: 20'
print('<font color="blue">Seizoen aangepast naar Zomer</font>')
elseif Seizoen == 'Herfst' then
commandArray['Seizoen'] = 'Set Level: 30'
print('<font color="blue">Seizoen aangepast naar Herfst</font>')
elseif Seizoen == 'Winter' then
commandArray['Seizoen'] = 'Set Level: 40'
print('<font color="blue">Seizoen aangepast naar Winter</font>')
else
print('<font color="blue">Geen actie nodig voor het aanpassen van de seizoenen</font>')
end
end
return commandArray
How do I get, in lua, the content 'Seizoen'. One thing what I would like to do is not to set the level to 20 when its already set to 20.
Re: LUA: Summer / Winter from timeofday or other...
Posted: Monday 26 June 2017 17:36
by jvdz
Just add an and relation to the If like: (untested)
Code: Select all
if Seizoen == 'Lente' and otherdevices['Seizoen'] ~= 10 then
commandArray['Seizoen'] = 'Set Level: 10'
print('<font color="blue">Seizoen aangepast naar Lente</font>')
elseif Seizoen == 'Zomer' and otherdevices['Seizoen'] ~= 20 then
commandArray['Seizoen'] = 'Set Level: 20'
print('<font color="blue">Seizoen aangepast naar Zomer</font>')
elseif Seizoen == 'Herfst' and otherdevices['Seizoen'] ~= 30 then
commandArray['Seizoen'] = 'Set Level: 30'
print('<font color="blue">Seizoen aangepast naar Herfst</font>')
elseif Seizoen == 'Winter' and otherdevices['Seizoen'] ~= 40 then
commandArray['Seizoen'] = 'Set Level: 40'
print('<font color="blue">Seizoen aangepast naar Winter</font>')
else
print('<font color="blue">Geen actie nodig voor het aanpassen van de seizoenen</font>')
end
Could be that you need to test for otherdevices_svalues['Seizoen'] to get the current value and I can't check that now.
Jos
Re: LUA: Summer / Winter from timeofday or other...
Posted: Monday 26 June 2017 20:06
by niki_lauda
jvdz wrote:Just add an and relation to the If like: (untested)
Code: Select all
if Seizoen == 'Lente' and otherdevices['Seizoen'] ~= 10 then
commandArray['Seizoen'] = 'Set Level: 10'
print('<font color="blue">Seizoen aangepast naar Lente</font>')
elseif Seizoen == 'Zomer' and otherdevices['Seizoen'] ~= 20 then
commandArray['Seizoen'] = 'Set Level: 20'
print('<font color="blue">Seizoen aangepast naar Zomer</font>')
elseif Seizoen == 'Herfst' and otherdevices['Seizoen'] ~= 30 then
commandArray['Seizoen'] = 'Set Level: 30'
print('<font color="blue">Seizoen aangepast naar Herfst</font>')
elseif Seizoen == 'Winter' and otherdevices['Seizoen'] ~= 40 then
commandArray['Seizoen'] = 'Set Level: 40'
print('<font color="blue">Seizoen aangepast naar Winter</font>')
else
print('<font color="blue">Geen actie nodig voor het aanpassen van de seizoenen</font>')
end
Could be that you need to test for otherdevices_svalues['Seizoen'] to get the current value and I can't check that now.
Jos
Tested. Doesn't work.
Code: Select all
elseif Seizoen == 'Zomer' and otherdevices['Seizoen'] ~=20 then
commandArray['Seizoen'] = 'Set Level: 20'
print('<font color="red"> de zomer is begonnen!!!</font>')
swiches every minute 2017-06-26 20:14:06.915 LUA: Open
2017-06-26 20:14:07.292 LUA: de zomer is begonnen!!!
2017-06-26 20:14:07.296 EventSystem: Script event triggered: seizoen
Re: LUA: Summer / Winter from timeofday or other...
Posted: Monday 26 June 2017 20:58
by niki_lauda
Found it!
elseif Seizoen == 'Zomer' and otherdevices['Seizoen'] ~= 'Zomer' then
Re: LUA: Summer / Winter from timeofday or other...
Posted: Monday 26 June 2017 21:53
by jvdz
Good you sorted it. This is why I mentioned it could also be otherdevices_svalues['Seizoen'] which I believe should be set to the level of the Selector switch. I can't test it to verify at the moment.
Jos
Re: LUA: Summer / Winter from timeofday or other...
Posted: Wednesday 15 August 2018 11:32
by Derik
Old topic..
Only....
Dear all..
I will try to hav this script [ seizoenen with 4 dummys ] in the intern lua option from Domoticz..
Only that is not working, with this script
Is there perhaps someone that have this working?
Now i do it with a cron, only need to backup this all.
When i got this into the intern it it is much easier...
Perhaps someone can make this work??
En is there anyone that have a script for all the months of a year?
Like to have every month in domoticz, with some dummy
So i can make my dragon happy
in some months he needs more uvb the others:-)
I did try this with google calendar... only i get that option not working..