Page 3 of 4

Re: LUA: Summer / Winter from timeofday or other...

Posted: Wednesday 15 August 2018 11:47
by jvdz
Not sure I understand what you want that isn't working.
You say you want "4 dummys" ...explain what you mean with that please and maybe post what you have tried already so we have something to start from.

Jos

Re: LUA: Summer / Winter from timeofday or other...

Posted: Tuesday 21 August 2018 8:29
by Derik
jvdz wrote: Wednesday 15 August 2018 11:47 Not sure I understand what you want that isn't working.
You say you want "4 dummys" ...explain what you mean with that please and maybe post what you have tried already so we have something to start from.

Jos
Dear Jos...
I have now 4 dummy for the seasons, they switch with a separate cron
this is the 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
-- The script is run once a time.day when the virtual switch 'time.day' gets flipped (every sunset & sunrise)
commandArray = {}

time = os.date("*t")
Seizoen = '????'
-- 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 = 'D.M.: Winter'
elseif (time.month == 3)
or (time.month == 4)
or (time.month == 5)
or (time.month == 6 and time.day < 21) then
   Seizoen = 'D.M.: Voorjaar'
elseif (time.month == 6)
or (time.month == 7)
or (time.month == 8)
or (time.month == 9 and time.day < 21) then
   Seizoen = 'D.M.: Zomer'
elseif (time.month == 9)
or (time.month == 10)
or (time.month == 11)
or (time.month == 12 and time.day < 21) then
   Seizoen = 'D.M.: Herfst'
else
   print('Something wrong in the season logic :)')
end
if Seizoen ~= '????' and otherdevices[Seizoen] ~= 'On' then
   -- reset all switches to Off
   print('Het seizoen is veranderd, het is nu '..Seizoen)
   commandArray['D.M.: Winter'] = 'Off'
   commandArray['D.M.: Voorjaar'] = 'Off'
   commandArray['D.M.: Zomer'] = 'Off'
   commandArray['D.M.: Herfst'] = 'Off'
   -- reset current season to On
   commandArray[Seizoen] = 'On'
end

return commandArray
What i hope to get is a working lua in the intern lua option in Domoticz..
This is better for my cpu.
And i do have the script in the DB from Domoticz much easier then everytime after a problem setup all the crons etc..

And what i should like in Domoticz is option to switch a Dummy for all the months..
I see every strange option in the timer setting in a dummy switch
Only no month option.
So a option to set months in a dummy is a good looking new feature i think:

Someone did try it for me in DZ vents:
viewtopic.php?p=189175#p189175
Sorry i cannot script any thing so i hope you great guys...

Thanks

Re: LUA: Summer / Winter from timeofday or other...

Posted: Tuesday 21 August 2018 9:27
by jvdz
Ah, ok, but why do you want to use 4 dummy switches in stead of simply using 1 text sensor called Seizoen and then setting it to Voorjaar/Zomer/Herfst/Winter.... So the same as the original script you used which sets a Variable? forget this question, went back in this thread and see we went through this already 2 years ago. :D
The below script should be close to set 4 dummy sensors... this one is without a general On/Off switch, just setting the 4 season switches.

Jos

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
-- The script is run once a time.day when the virtual switch 'time.day' gets flipped (every sunset & sunrise)
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
	if otherdevices["D.M.: Winter"] == 'Off' then
		commandArray['D.M.: Winter'] = 'On'
		commandArray['D.M.: Voorjaar'] = 'Off'
		commandArray['D.M.: Zomer'] = 'Off'
		commandArray['D.M.: Herfst'] = 'Off'
	end
elseif (time.month == 3)
or (time.month == 4)
or (time.month == 5)
or (time.month == 6 and time.day < 21) then
	if otherdevices["D.M.: Voorjaar"] == 'Off' then
		commandArray['D.M.: Winter'] = 'Off'
		commandArray['D.M.: Voorjaar'] = 'On'
		commandArray['D.M.: Zomer'] = 'Off'
		commandArray['D.M.: Herfst'] = 'Off'
	end
elseif (time.month == 6)
or (time.month == 7)
or (time.month == 8)
or (time.month == 9 and time.day < 21) then
	if otherdevices["D.M.: Zomer"] == 'Off' then
		commandArray['D.M.: Winter'] = 'Off'
		commandArray['D.M.: Voorjaar'] = 'Off'
		commandArray['D.M.: Zomer'] = 'On'
		commandArray['D.M.: Herfst'] = 'Off'
	end
elseif (time.month == 9)
or (time.month == 10)
or (time.month == 11)
or (time.month == 12 and time.day < 21) then
	if otherdevices["D.M.: Herfst"] == 'Off' then
		commandArray['D.M.: Winter'] = 'Off'
		commandArray['D.M.: Voorjaar'] = 'Off'
		commandArray['D.M.: Zomer'] = 'Of'
		commandArray['D.M.: Herfst'] = 'On'
	end
else
   print('Something wrong in the season logic :)')
end
return commandArray

Re: LUA: Summer / Winter from timeofday or other...

Posted: Tuesday 21 August 2018 23:04
by Derik
jvdz wrote: Tuesday 21 August 2018 9:27 Ah, ok, but why do you want to use 4 dummy switches in stead of simply using 1 text sensor called Seizoen and then setting it to Voorjaar/Zomer/Herfst/Winter.... So the same as the original script you used which sets a Variable? forget this question, went back in this thread and see we went through this already 2 years ago. :D
The below script should be close to set 4 dummy sensors... this one is without a general On/Off switch, just setting the 4 season switches.

Jos

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
-- The script is run once a time.day when the virtual switch 'time.day' gets flipped (every sunset & sunrise)
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
	if otherdevices["D.M.: Winter"] == 'Off' then
		commandArray['D.M.: Winter'] = 'On'
		commandArray['D.M.: Voorjaar'] = 'Off'
		commandArray['D.M.: Zomer'] = 'Off'
		commandArray['D.M.: Herfst'] = 'Off'
	end
elseif (time.month == 3)
or (time.month == 4)
or (time.month == 5)
or (time.month == 6 and time.day < 21) then
	if otherdevices["D.M.: Voorjaar"] == 'Off' then
		commandArray['D.M.: Winter'] = 'Off'
		commandArray['D.M.: Voorjaar'] = 'On'
		commandArray['D.M.: Zomer'] = 'Off'
		commandArray['D.M.: Herfst'] = 'Off'
	end
elseif (time.month == 6)
or (time.month == 7)
or (time.month == 8)
or (time.month == 9 and time.day < 21) then
	if otherdevices["D.M.: Zomer"] == 'Off' then
		commandArray['D.M.: Winter'] = 'Off'
		commandArray['D.M.: Voorjaar'] = 'Off'
		commandArray['D.M.: Zomer'] = 'On'
		commandArray['D.M.: Herfst'] = 'Off'
	end
elseif (time.month == 9)
or (time.month == 10)
or (time.month == 11)
or (time.month == 12 and time.day < 21) then
	if otherdevices["D.M.: Herfst"] == 'Off' then
		commandArray['D.M.: Winter'] = 'Off'
		commandArray['D.M.: Voorjaar'] = 'Off'
		commandArray['D.M.: Zomer'] = 'Of'
		commandArray['D.M.: Herfst'] = 'On'
	end
else
   print('Something wrong in the season logic :)')
end
return commandArray
Thanks give it a try...
Is it a time or a device lua?

And is it possible to switch a protected switch?

edit:
I try this.
As a lua all and a time and device
I set voorjaar to on, and the others to off....
So when the script works... it should switch to te summer.. i think?[ or is there a other time every minute i read.. ]
Only that is not happens

I see also no thing in the log..

Re: LUA: Summer / Winter from timeofday or other...

Posted: Tuesday 21 August 2018 23:22
by jvdz
This needs to be time to run it one time each minute.
There will only be an entry in the log when the season changes.
Just try reading & understanding the logic as it will benefit you when you can follow what script do! ;)

Re: LUA: Summer / Winter from timeofday or other...

Posted: Wednesday 22 August 2018 8:30
by Derik
jvdz wrote: Tuesday 21 August 2018 23:22 This needs to be time to run it one time each minute.
There will only be an entry in the log when the season changes.
Just try reading & understanding the logic as it will benefit you when you can follow what script do! ;)

mmm I think i have to wait until 21-9 and the the switch is going to Herfst ?

Re: LUA: Summer / Winter from timeofday or other...

Posted: Wednesday 22 August 2018 9:35
by jvdz
Are the 4 switched set to to proper status, which is what the script does?
You could simply change their settings by changing the "D.M.: Zomer" to Off and see whether the script changes it back.

Jos

Re: LUA: Summer / Winter from timeofday or other...

Posted: Wednesday 22 August 2018 16:58
by Derik
Jos

I set the switch yesterday to off...
And voorjaar to on
ScreenShot264.png
ScreenShot264.png (21.32 KiB) Viewed 1678 times
So that's why is say when it is going to switch:-)

Re: LUA: Summer / Winter from timeofday or other...

Posted: Wednesday 22 August 2018 17:12
by jvdz
It should change at the next minute interval!
Are you getting any errors in the log for the script as it seems you have different devicenames in that image?

Jos

Re: LUA: Summer / Winter from timeofday or other...

Posted: Wednesday 22 August 2018 19:11
by Derik
jvdz wrote: Wednesday 22 August 2018 17:12 It should change at the next minute interval!
Are you getting any errors in the log for the script as it seems you have different devicenames in that image?

Jos

Jos..
SORRY sorry..
I set after all my dummy's a D ....

So it is working GREAT!!!
Thanks..!!

I now iäm asking to much..
Only can you make a script voor all the months of a year?
Or build this is Domoticz???
I use some dummy's for the months of a year
Only now i am switching them manually [ cannot script :-( ]
Looks a extra option in Domoticz.

I use them for my terrarium for the bearded dragon his winter period..

Or can i give it a try with this script:-)
In stead of zomer, voorjaar etc months?

Re: LUA: Summer / Winter from timeofday or other...

Posted: Wednesday 22 August 2018 19:57
by jvdz
Derik wrote: Wednesday 22 August 2018 19:11 Jos..
SORRY sorry..
I set after all my dummy's a D ....

So it is working GREAT!!!
Thanks..!!
Nice..
Derik wrote: Wednesday 22 August 2018 19:11 [ cannot script :-( ]
Sounds like a nice challenge... It is really not that difficult, just to start is the hard thing.
Derik wrote: Wednesday 22 August 2018 19:11 Only can you make a script voor all the months of a year?
Or build this is Domoticz???
I use some dummy's for the months of a year
Only now i am switching them manually
So what exactly are you looking for? You really want 12 Dummy Switches for this?
You mentioned you already have switches you use manually? What are their names?
So: Lets first get the requirements layed out properly before starting to design something. ;)

Jos

Re: LUA: Summer / Winter from timeofday or other...

Posted: Wednesday 22 August 2018 20:58
by Derik
Jos,

I did give it a try

And i am happy en proud with myself:

Code: Select all

-- script_time maanden.lua

commandArray = {}
time = os.date("*t")
-- check once a minute for the months to change
if (time.month == 1) then
	if otherdevices["D.M.: Januari D"] == 'Off' then
		commandArray['D.M.: Januari D'] = 'On'
		commandArray['D.M.: Februari D'] = 'Off'
		commandArray['D.M.: Maart D'] = 'Off'
		commandArray['D.M.: April D'] = 'Off'
		commandArray['D.M.: Mei D'] = 'Off'
		commandArray['D.M.: Juni D'] = 'Off'
		commandArray['D.M.: Juli D'] = 'Off'
		commandArray['D.M.: Augustus D'] = 'Off'
		commandArray['D.M.: September D'] = 'Off'
		commandArray['D.M.: Oktober D'] = 'Off'
		commandArray['D.M.: November D'] = 'Off'
		commandArray['D.M.: December D'] = 'Off'
	end
elseif (time.month == 2) then
	if otherdevices ["D.M.: Februari D"] == 'Off' then
		commandArray['D.M.: Januari D'] = 'Off'
		commandArray['D.M.: Februari D'] = 'On'
		commandArray['D.M.: Maart D'] = 'Off'
		commandArray['D.M.: April D'] = 'Off'
		commandArray['D.M.: Mei D'] = 'Off'
		commandArray['D.M.: Juni D'] = 'Off'
		commandArray['D.M.: Juli D'] = 'Off'
		commandArray['D.M.: Augustus D'] = 'Off'
		commandArray['D.M.: September D'] = 'Off'
		commandArray['D.M.: Oktober D'] = 'Off'
		commandArray['D.M.: November D'] = 'Off'
		commandArray['D.M.: December D'] = 'Off'
	end
elseif (time.month == 3) then
	if otherdevices ["D.M.: Maart D"] == 'Off' then
		commandArray['D.M.: Januari D'] = 'Off'
		commandArray['D.M.: Februari D'] = 'Off'
		commandArray['D.M.: Maart D'] = 'On'
		commandArray['D.M.: April D'] = 'Off'
		commandArray['D.M.: Mei D'] = 'Off'
		commandArray['D.M.: Juni D'] = 'Off'
		commandArray['D.M.: Juli D'] = 'Off'
		commandArray['D.M.: Augustus D'] = 'Off'
		commandArray['D.M.: September D'] = 'Off'
		commandArray['D.M.: Oktober D'] = 'Off'
		commandArray['D.M.: November D'] = 'Off'
		commandArray['D.M.: December D'] = 'Off'
	end
elseif (time.month == 4) then
	if otherdevices ["D.M.: April D"] == 'Off' then
		commandArray['D.M.: Januari D'] = 'Off'
		commandArray['D.M.: Februari D'] = 'Off'
		commandArray['D.M.: Maart D'] = 'Off'
		commandArray['D.M.: April D'] = 'On'
		commandArray['D.M.: Mei D'] = 'Off'
		commandArray['D.M.: Juni D'] = 'Off'
		commandArray['D.M.: Juli D'] = 'Off'
		commandArray['D.M.: Augustus D'] = 'Off'
		commandArray['D.M.: September D'] = 'Off'
		commandArray['D.M.: Oktober D'] = 'Off'
		commandArray['D.M.: November D'] = 'Off'
		commandArray['D.M.: December D'] = 'Off'
	end
elseif (time.month == 5) then
	if otherdevices ["D.M.: Mei D"] == 'Off' then
		commandArray['D.M.: Januari D'] = 'Off'
		commandArray['D.M.: Februari D'] = 'Off'
		commandArray['D.M.: Maart D'] = 'Off'
		commandArray['D.M.: April D'] = 'Off'
		commandArray['D.M.: Mei D'] = 'On'
		commandArray['D.M.: Juni D'] = 'Off'
		commandArray['D.M.: Juli D'] = 'Off'
		commandArray['D.M.: Augustus D'] = 'Off'
		commandArray['D.M.: September D'] = 'Off'
		commandArray['D.M.: Oktober D'] = 'Off'
		commandArray['D.M.: November D'] = 'Off'
		commandArray['D.M.: December D'] = 'Off'
	end
elseif (time.month == 6) then
	if otherdevices ["D.M.: Juni D"] == 'Off' then
		commandArray['D.M.: Januari D'] = 'Off'
		commandArray['D.M.: Februari D'] = 'Off'
		commandArray['D.M.: Maart D'] = 'Off'
		commandArray['D.M.: April D'] = 'Off'
		commandArray['D.M.: Mei D'] = 'Off'
		commandArray['D.M.: Juni D'] = 'On'
		commandArray['D.M.: Juli D'] = 'Off'
		commandArray['D.M.: Augustus D'] = 'Off'
		commandArray['D.M.: September D'] = 'Off'
		commandArray['D.M.: Oktober D'] = 'Off'
		commandArray['D.M.: November D'] = 'Off'
		commandArray['D.M.: December D'] = 'Off'
	end
elseif (time.month == 7) then
	if otherdevices ["D.M.: Juli D"] == 'Off' then
		commandArray['D.M.: Januari D'] = 'Off'
		commandArray['D.M.: Februari D'] = 'Off'
		commandArray['D.M.: Maart D'] = 'Off'
		commandArray['D.M.: April D'] = 'Off'
		commandArray['D.M.: Mei D'] = 'Off'
		commandArray['D.M.: Juni D'] = 'Off'
		commandArray['D.M.: Juli D'] = 'On'
		commandArray['D.M.: Augustus D'] = 'Off'
		commandArray['D.M.: September D'] = 'Off'
		commandArray['D.M.: Oktober D'] = 'Off'
		commandArray['D.M.: November D'] = 'Off'
		commandArray['D.M.: December D'] = 'Off'
	end
elseif (time.month == 8) then
	if otherdevices ["D.M.: Augustus D"] == 'Off' then
		commandArray['D.M.: Januari D'] = 'Off'
		commandArray['D.M.: Februari D'] = 'Off'
		commandArray['D.M.: Maart D'] = 'Off'
		commandArray['D.M.: April D'] = 'Off'
		commandArray['D.M.: Mei D'] = 'Off'
		commandArray['D.M.: Juni D'] = 'Off'
		commandArray['D.M.: Juli D'] = 'Off'
		commandArray['D.M.: Augustus D'] = 'On'
		commandArray['D.M.: September D'] = 'Off'
		commandArray['D.M.: Oktober D'] = 'Off'
		commandArray['D.M.: November D'] = 'Off'
		commandArray['D.M.: December D'] = 'Off'
	end
elseif (time.month == 9) then
	if otherdevices ["D.M.: September D"] == 'Off' then
		commandArray['D.M.: Januari D'] = 'Off'
		commandArray['D.M.: Februari D'] = 'Off'
		commandArray['D.M.: Maart D'] = 'Off'
		commandArray['D.M.: April D'] = 'Off'
		commandArray['D.M.: Mei D'] = 'Off'
		commandArray['D.M.: Juni D'] = 'Off'
		commandArray['D.M.: Juli D'] = 'Off'
		commandArray['D.M.: Augustus D'] = 'Off'
		commandArray['D.M.: September D'] = 'On'
		commandArray['D.M.: Oktober D'] = 'Off'
		commandArray['D.M.: November D'] = 'Off'
		commandArray['D.M.: December D'] = 'Off'
	end
elseif (time.month == 10) then
	if otherdevices ["D.M.: Oktober D"] == 'Off' then
		commandArray['D.M.: Januari D'] = 'Off'
		commandArray['D.M.: Februari D'] = 'Off'
		commandArray['D.M.: Maart D'] = 'Off'
		commandArray['D.M.: April D'] = 'Off'
		commandArray['D.M.: Mei D'] = 'Off'
		commandArray['D.M.: Juni D'] = 'Off'
		commandArray['D.M.: Juli D'] = 'Off'
		commandArray['D.M.: Augustus D'] = 'Off'
		commandArray['D.M.: September D'] = 'Off'
		commandArray['D.M.: Oktober D'] = 'On'
		commandArray['D.M.: November D'] = 'Off'
		commandArray['D.M.: December D'] = 'Off'
	end
elseif (time.month == 11) then
	if otherdevices ["D.M.: November D"] == 'Off' then
		commandArray['D.M.: Januari D'] = 'Off'
		commandArray['D.M.: Februari D'] = 'Off'
		commandArray['D.M.: Maart D'] = 'Off'
		commandArray['D.M.: April D'] = 'Off'
		commandArray['D.M.: Mei D'] = 'Off'
		commandArray['D.M.: Juni D'] = 'Off'
		commandArray['D.M.: Juli D'] = 'Off'
		commandArray['D.M.: Augustus D'] = 'Off'
		commandArray['D.M.: September D'] = 'Off'
		commandArray['D.M.: Oktober D'] = 'Off'
		commandArray['D.M.: November D'] = 'On'
		commandArray['D.M.: December D'] = 'Off'
	end
elseif (time.month == 12) then
	if otherdevices ["D.M.: December D"] == 'Off' then
		commandArray['D.M.: Januari D'] = 'Off'
		commandArray['D.M.: Februari D'] = 'Off'
		commandArray['D.M.: Maart D'] = 'Off'
		commandArray['D.M.: April D'] = 'Off'
		commandArray['D.M.: Mei D'] = 'Off'
		commandArray['D.M.: Juni D'] = 'Off'
		commandArray['D.M.: Juli D'] = 'Off'
		commandArray['D.M.: Augustus D'] = 'Off'
		commandArray['D.M.: September D'] = 'Off'
		commandArray['D.M.: Oktober D'] = 'Off'
		commandArray['D.M.: November D'] = 'Off'
		commandArray['D.M.: December D'] = 'On'
	end
else
   print('Er is iets mis in het script van Maanden :)')
end
return commandArray
12 dummy's
And looks working great

THANKS...

Re: LUA: Summer / Winter from timeofday or other...

Posted: Wednesday 22 August 2018 21:05
by jvdz
Nice 8-)

Re: LUA: Summer / Winter from timeofday or other...

Posted: Wednesday 22 August 2018 21:12
by Derik
jvdz wrote: Wednesday 22 August 2018 21:05Nice 8-)
Thanks

Perhaps it is not the best way to do..
Only i am proud of it :-)

Re: LUA: Summer / Winter from timeofday or other...

Posted: Wednesday 22 August 2018 21:31
by jvdz
There are always other, some might say better, ways to get there but more important is you get there and understand how you got there!
Jos

Re: LUA: Summer / Winter from timeofday or other...

Posted: Saturday 06 October 2018 15:35
by Derik
mmm

Here i am again...

My boys do have a bearded dragon...
And for his sleaping time i need the weeks of the year...
So i can set his UV time etc etc
In the winter he needs les uv light then in summer...

So is there someone that give me a example script where i can make the weeks of a year..

And when whe are on this point...
Days also should be great...

months weeks days.. i think there is no more left..:-)

Re: LUA: Summer / Winter from timeofday or other...

Posted: Tuesday 13 October 2020 10:32
by Larsoss
niki_lauda wrote: Monday 26 June 2017 10:39
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.
Just a serious, very late pick-up on this topic .. Sorry for that ..

If I understand correctly, all I have to do is.
1. Copy Lua script and paste into new Lua script
2. Create a dummy switch with the name (seizoen), then create a selector with the names (lente,zomer,herfst,winter)

Or do I also have to do something in the user variables?

Re: LUA: Summer / Winter from timeofday or other...

Posted: Tuesday 13 October 2020 10:40
by jvdz
Larsoss wrote: Tuesday 13 October 2020 10:32 If I understand correctly, all I have to do is.
1. Copy Lua script and paste into new Lua script
2. Create a dummy switch with the name (seizoen), then create a selector with the names (lente,zomer,herfst,winter)
Yes: Create a TIME Script and Selector Switch named 'Seizoen'.
Larsoss wrote: Tuesday 13 October 2020 10:32 Or do I also have to do something in the user variables?
nope

Jos

Re: LUA: Summer / Winter from timeofday or other...

Posted: Tuesday 13 October 2020 10:47
by Larsoss
jvdz wrote: Tuesday 13 October 2020 10:40
Larsoss wrote: Tuesday 13 October 2020 10:32 If I understand correctly, all I have to do is.
1. Copy Lua script and paste into new Lua script
2. Create a dummy switch with the name (seizoen), then create a selector with the names (lente,zomer,herfst,winter)
Yes: Create a TIME Script and Selector Switch named 'Seizoen'.
Larsoss wrote: Tuesday 13 October 2020 10:32 Or do I also have to do something in the user variables?
nope

Jos
OK, Cool for now..
And now only select once the season? And the rest go's automatic?

Image

so this is what it looks like

Re: LUA: Summer / Winter from timeofday or other...

Posted: Tuesday 13 October 2020 10:55
by jvdz
I see it will currently update the selector switch every 720 seconds. The below code will simply update when it is changed/wrong.

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 = {}
-- 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' and otherdevices_svalues['Seizoen'] ~= '10' then
   commandArray['Seizoen'] = 'Set Level: 10'
   print('<font color="blue">Seizoen aangepast naar Lente</font>')
 elseif Seizoen == 'Zomer' and otherdevices_svalues['Seizoen'] ~= '20' then
   commandArray['Seizoen'] = 'Set Level: 20'
   print('<font color="blue">Seizoen aangepast naar Zomer</font>')
elseif Seizoen == 'Herfst' and otherdevices_svalues['Seizoen'] ~= '30' then
   commandArray['Seizoen'] = 'Set Level: 30'
   print('<font color="blue">Seizoen aangepast naar Herfst</font>')
elseif Seizoen == 'Winter' and otherdevices_svalues['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

return commandArray