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

Moderator: leecollings

User avatar
jvdz
Posts: 2189
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

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

Post 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
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
Derik
Posts: 1601
Joined: Friday 18 October 2013 23:33
Target OS: Raspberry Pi / ODroid
Domoticz version: BETA
Location: Arnhem/Nijmegen Nederland
Contact:

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

Post 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
Xu4: Beta Extreme antenna RFXcomE,WU Fi Ping ip P1 Gen5 PVOutput Harmony HUE SolarmanPv OTG Winddelen Alive ESP Buienradar MySensors WOL Winddelen counting RPi: Beta SMAspot RFlinkTest Domoticz ...Different backups
User avatar
jvdz
Posts: 2189
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

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

Post 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
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
Derik
Posts: 1601
Joined: Friday 18 October 2013 23:33
Target OS: Raspberry Pi / ODroid
Domoticz version: BETA
Location: Arnhem/Nijmegen Nederland
Contact:

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

Post 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..
Xu4: Beta Extreme antenna RFXcomE,WU Fi Ping ip P1 Gen5 PVOutput Harmony HUE SolarmanPv OTG Winddelen Alive ESP Buienradar MySensors WOL Winddelen counting RPi: Beta SMAspot RFlinkTest Domoticz ...Different backups
User avatar
jvdz
Posts: 2189
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

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

Post 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! ;)
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
Derik
Posts: 1601
Joined: Friday 18 October 2013 23:33
Target OS: Raspberry Pi / ODroid
Domoticz version: BETA
Location: Arnhem/Nijmegen Nederland
Contact:

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

Post 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 ?
Xu4: Beta Extreme antenna RFXcomE,WU Fi Ping ip P1 Gen5 PVOutput Harmony HUE SolarmanPv OTG Winddelen Alive ESP Buienradar MySensors WOL Winddelen counting RPi: Beta SMAspot RFlinkTest Domoticz ...Different backups
User avatar
jvdz
Posts: 2189
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

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

Post 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
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
Derik
Posts: 1601
Joined: Friday 18 October 2013 23:33
Target OS: Raspberry Pi / ODroid
Domoticz version: BETA
Location: Arnhem/Nijmegen Nederland
Contact:

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

Post by Derik »

Jos

I set the switch yesterday to off...
And voorjaar to on
ScreenShot264.png
ScreenShot264.png (21.32 KiB) Viewed 1499 times
So that's why is say when it is going to switch:-)
Xu4: Beta Extreme antenna RFXcomE,WU Fi Ping ip P1 Gen5 PVOutput Harmony HUE SolarmanPv OTG Winddelen Alive ESP Buienradar MySensors WOL Winddelen counting RPi: Beta SMAspot RFlinkTest Domoticz ...Different backups
User avatar
jvdz
Posts: 2189
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

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

Post 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
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
Derik
Posts: 1601
Joined: Friday 18 October 2013 23:33
Target OS: Raspberry Pi / ODroid
Domoticz version: BETA
Location: Arnhem/Nijmegen Nederland
Contact:

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

Post 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?
Xu4: Beta Extreme antenna RFXcomE,WU Fi Ping ip P1 Gen5 PVOutput Harmony HUE SolarmanPv OTG Winddelen Alive ESP Buienradar MySensors WOL Winddelen counting RPi: Beta SMAspot RFlinkTest Domoticz ...Different backups
User avatar
jvdz
Posts: 2189
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

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

Post 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
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
Derik
Posts: 1601
Joined: Friday 18 October 2013 23:33
Target OS: Raspberry Pi / ODroid
Domoticz version: BETA
Location: Arnhem/Nijmegen Nederland
Contact:

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

Post 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...
Xu4: Beta Extreme antenna RFXcomE,WU Fi Ping ip P1 Gen5 PVOutput Harmony HUE SolarmanPv OTG Winddelen Alive ESP Buienradar MySensors WOL Winddelen counting RPi: Beta SMAspot RFlinkTest Domoticz ...Different backups
User avatar
jvdz
Posts: 2189
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

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

Post by jvdz »

Nice 8-)
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
Derik
Posts: 1601
Joined: Friday 18 October 2013 23:33
Target OS: Raspberry Pi / ODroid
Domoticz version: BETA
Location: Arnhem/Nijmegen Nederland
Contact:

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

Post 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 :-)
Xu4: Beta Extreme antenna RFXcomE,WU Fi Ping ip P1 Gen5 PVOutput Harmony HUE SolarmanPv OTG Winddelen Alive ESP Buienradar MySensors WOL Winddelen counting RPi: Beta SMAspot RFlinkTest Domoticz ...Different backups
User avatar
jvdz
Posts: 2189
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

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

Post 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
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
Derik
Posts: 1601
Joined: Friday 18 October 2013 23:33
Target OS: Raspberry Pi / ODroid
Domoticz version: BETA
Location: Arnhem/Nijmegen Nederland
Contact:

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

Post 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..:-)
Xu4: Beta Extreme antenna RFXcomE,WU Fi Ping ip P1 Gen5 PVOutput Harmony HUE SolarmanPv OTG Winddelen Alive ESP Buienradar MySensors WOL Winddelen counting RPi: Beta SMAspot RFlinkTest Domoticz ...Different backups
Larsoss
Posts: 65
Joined: Friday 18 March 2016 10:11
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: Netherlands
Contact:

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

Post 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?
Raspberry 4 - USB boot Domoticz /|\ Raspberry 2B - Dashticz /|\ Tasmota device's /|\ Philips Hue & Yeelight
User avatar
jvdz
Posts: 2189
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

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

Post 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
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
Larsoss
Posts: 65
Joined: Friday 18 March 2016 10:11
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: Netherlands
Contact:

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

Post 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
Raspberry 4 - USB boot Domoticz /|\ Raspberry 2B - Dashticz /|\ Tasmota device's /|\ Philips Hue & Yeelight
User avatar
jvdz
Posts: 2189
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

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

Post 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
Last edited by jvdz on Tuesday 13 October 2020 11:10, edited 1 time in total.
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest