Page 1 of 4
LUA: Summer / Winter from timeofday or other...
Posted: Thursday 06 August 2015 13:54
by jcjames13009
Hi,
Do we have possibility to retreive season (Winter, Summer, etc...) using Lua script.
something like timeofday['Nighttime'] but for season.
Couldn't find something in the forum and net
Thansk in advance
JC
Re: LUA: Summer / Winter from timeofday or other...
Posted: Thursday 06 August 2015 14:13
by jannl
Seasons are fixed, 4 dates every year, why not hard code that?
Re: LUA: Summer / Winter from timeofday or other...
Posted: Thursday 06 August 2015 14:16
by ThinkPad
Hardcoding it is also done by people using other home automation systems:
http://board.homeseer.com/showthread.php?t=155133
Re: LUA: Summer / Winter from timeofday or other...
Posted: Thursday 06 August 2015 16:45
by jcjames13009
That's what I was thinking about. But wanted to know before if there were an easier solution.
Thanks
JC
Re: LUA: Summer / Winter from timeofday or other...
Posted: Thursday 06 August 2015 17:09
by jannl
Normally hardcoding is the easy way.
Re: LUA: Summer / Winter from timeofday or other...
Posted: Friday 14 August 2015 13:03
by jcjames13009
Hi
That's what I did:
Solution 1: Use dummy switches one for each season
- Capture Saisons 1.PNG (58.84 KiB) Viewed 6845 times
with the following lua script that set each switch to "ON" or "OFF" depending on season change date
Code: Select all
-- script_device_SaisonSW.lua
-- Ce script permet de gérer des switches virtuel pour chaque saison:
-- Printemps / Eté / Automne / Hiver
-- Le changement d'état se fait à date fixe:
-- 21/03 pour le printemps
-- 21/06 pour l'été
-- 21/09 pour l'automne
-- 21/12 pour l'hiver
-- Le script est lancé une fois par jour lors du basculement du switch virtuel 'Jour' synchronisé sur l'heure de levé et couché du soleil
local SWPrintemps = 'Printemps' -- Switch virtuel printemps
local SWEte = 'Eté' -- Switch virtuel été
local SWAutomne = 'Automne' -- Switch virtuel automne
local SWHiver = 'Hiver' -- Switch virtuel hiver
commandArray = {}
-- Récuperation de l'heure
time = os.time()
mois = tonumber(os.date('%m', time))
jours = tonumber(os.date('%d', time))
if devicechanged['Jour'] == 'On' then
if (mois == 03 and jours >= 21 and otherdevices[SWPrintemps] == 'Off') then
-- print(' > C\'est le printemps') -- Pour debug
commandArray[SWPrintemps]='On' -- C'est le printemps
commandArray[SWEte]='Off'
commandArray[SWAutomne]='Off'
commandArray[SWHiver]='Off'
end
if (mois == 06 and jours >= 21 and otherdevices[SWEte] == 'Off') then
-- print(' > C\'est l\'été') -- Pour debug
commandArray[SWPrintemps]='Off'
commandArray[SWEte]='On' -- C'est l'été
commandArray[SWAutomne]='Off'
commandArray[SWHiver]='Off'
end
if (mois == 09 and jours >= 21 and otherdevices[SWAutomne] == 'Off') then
-- print(' > C\'est l\'automne') -- Pour debug
commandArray[SWPrintemps]='Off'
commandArray[SWEte]='Off'
commandArray[SWAutomne]='On' -- C'est l'automne
commandArray[SWHiver]='Off'
end
if (mois == 12 and jours >= 21 and otherdevices[SWHiver] == 'Off') then
-- print(' > C\'est l\'hiver') -- Pour debug
commandArray[SWPrintemps]='Off'
commandArray[SWEte]='Off'
commandArray[SWAutomne]='Off'
commandArray[SWHiver]='On' -- C'est l'hiver
end
end
return commandArray
Solution 2: Use user variable
- Capture Saisons 2.PNG (4.64 KiB) Viewed 6845 times
with the following lua script that change the value of the variable at season change date
Code: Select all
-- script_device_SaisonVU.lua
-- Ce script permet de gérer la valeur d'une variable utilisateur en fonction de la saision :
-- Printemps / Eté / Automne / Hiver
-- Le changement d'état se fait à date fixe :
-- 21/03 pour le printemps
-- 21/06 pour l'été
-- 21/09 pour l'automne
-- 21/12 pour l'hiver
-- Le script est lancé une fois par jour lors du basculement du switch virtuel 'Jour' synchronisé sur l'heure de levé et couché du soleil
commandArray = {}
-- Récuperation de l'heure
time = os.time()
mois = tonumber(os.date('%m', time))
jours = tonumber(os.date('%d', time))
if devicechanged['Jour'] == 'On' then
if mois == 03 and jours >= 21 then
-- print(' > C\'est le printemps') -- Pour debug
commandArray['Variable:Saison'] = 'Printemps' -- C'est le printemps
end
if mois == 06 and jours >= 21 then
-- print(' > C\'est l\'été') -- Pour debug
commandArray['Variable:Saison'] = 'Eté' -- C'est l'été
end
if mois == 09 and jours >= 21 then
-- print(' > C\'est l\'automne') -- Pour debug
commandArray['Variable:Saison'] = 'Automne' -- C'est l'automne
end
if mois == 12 and jours >= 21 then
-- print(' > C\'est l\'hiver') -- Pour debug
commandArray['Variable:Saison'] = 'Hiver' -- C'est l'hiver
end
end
return commandArray
Maybe it can help someone.
JC
Re: LUA: Summer / Winter from timeofday or other...
Posted: Friday 14 August 2015 23:11
by ThinkPad
Thanks for sharing. I don't understand French very well, but i can 'read' how the script works luckily
Where do you use this for?
Can user variable be used in Blockly?
IF Var_Season = Summer
DO SET light1 = On
?
Otherwise if it is just for showing text, you could also use a text sensor and update it with this:
Code: Select all
commandArray['OpenURL'] = "http://127.0.0.1:8080/json.htm?type=command¶m=udevice&idx=IDX&nvalue=0&svalue=TEXT"
Text sensor can be created by Setup > Hardware > Dummy hardware. Then at the dummy hardware click 'Create device', type 'text'
Re: LUA: Summer / Winter from timeofday or other...
Posted: Sunday 16 August 2015 20:09
by jcjames13009
Hi,
Thanks for the tip about Text Sensor. I didn't knew about taht
Cannot answer you for user variables in Blocky. I never tested it before.
And sorry for the text in french. Google works fine for transaltaion (just tested it). But I'll try to do an english version
I'll use this feature to manage humidity extraction (VMC in French). To let the extractor running at max speed during the night in summer when outside temp is lower that inside one to cool down (a bit) the house. Stop extraction in winter during the night to don't waste eating.
I plan to use it also to manage pool water pump and cleaning robot time slots depending on season.
Will post corresponding scrips as well
JC
Re: LUA: Summer / Winter from timeofday or other...
Posted: Sunday 16 August 2015 20:23
by ThinkPad
But how do you control the extractor? By the virtual switches method you described?
IF Fan = Off AND Summer = On
DO SET Fan = Off
Like that?
Re: LUA: Summer / Winter from timeofday or other...
Posted: Saturday 13 February 2016 21:46
by Derik
Someone has this working???
Found some scripts [ thanks to the maker?? ] only cannot get this working..?
Code: Select all
-- script_device_season.lua
-- This script allows you to manage the value of a user variable depending on this season:
-- Spring Summer Fall Winter
-- The change of state is a fixed date:
-- Lente: 1 maart t/m 31 mei
-- Zomer: 1 juni t/m 31 augustus
-- Herfst: 1 september t/m 30 november
-- Winter: 1 december t/m 28 februari
-- The script is run once a day when the virtual switch 'Day' gets flipped (every sunset & sunrise)
commandArray = {}
time = os.time()
month = tonumber(os.date('%m', time))
day = tonumber(os.date('%d', time))
if devicechanged['IsDonker (virt)'] == 'On' then
if month == 03 and day >= 21 then
print('Het seizoen is veranderd, het is nu lente')
commandArray['Variable:Seizoen'] = 'Lente'
commandArray['OpenURL'] = "http://192.168.5.70:8080/json.htm?type=command¶m=udevice&idx=253&nvalue=0&svalue=Lente"
end
if month == 06 and day >= 21 then
print('Het seizoen is veranderd, het is nu zomer')
commandArray['Variable:Seizoen'] = 'Zomer'
commandArray['OpenURL'] = "http://192.168.5.70:8080/json.htm?type=command¶m=udevice&idx=253&nvalue=0&svalue=Zomer"
end
if month == 09 and day >= 21 then
print('Het seizoen is veranderd, het is nu herfst')
commandArray['Variable:Seizoen'] = 'Herfst'
commandArray['OpenURL'] = "http://192.168.5.70:8080/json.htm?type=command¶m=udevice&idx=253&nvalue=0&svalue=Herfst"
end
if month == 12 and day >= 21 then
print('Het seizoen is veranderd, het is nu lente')
commandArray['Variable:Seizoen'] = 'Winter'
commandArray['OpenURL'] = "http://191.168.5.70:8080/json.htm?type=command¶m=udevice&idx=253&nvalue=0&svalue=Winter"
end
end
return commandArray
Please help
Or perhaps some one have 4 dummy switches that are flipping by the seasons...
Re: LUA: Summer / Winter from timeofday or other...
Posted: Sunday 14 February 2016 11:47
by jvdz
Which part isn't working for you?
You do have a virtual device called "IsDonker (virt)" which is set to On each day?
You realize that the tests for month&day will be valid multiple days on and after the 21st of the specified month?
Jos
Re: LUA: Summer / Winter from timeofday or other...
Posted: Sunday 14 February 2016 11:55
by Derik
jvdz wrote:Which part isn't working for you?
You do have a virtual device called "IsDonker (virt)" which is set to On each day?
You realize that the tests for month&day will be valid multiple days on and after the 21st of the specified month?
Jos
The hole part is not working because i do not understand this script...
isdonker dos not say a thing for me.
What i am simple looking for is ...
4 switches that switching on or of whe a season is active
Re: LUA: Summer / Winter from timeofday or other...
Posted: Sunday 14 February 2016 13:22
by jvdz
Understood, a learning experience for you.
So what are your exact switchnames to use for the 4 seasons?
Jos
Re: LUA: Summer / Winter from timeofday or other...
Posted: Sunday 14 February 2016 13:27
by Derik
All dummys:
Voorjaar : IDX:4194
Zomer : IDX: 4195
Herfst : IDX: 4196
Winter: IDX: 4197
Re: LUA: Summer / Winter from timeofday or other...
Posted: Sunday 14 February 2016 13:47
by jvdz
Something like this should be close.
Save the below code as script_time_season.lua. It will run each minute and will only change the Switches to the appropriate setting when something changes.
Let me know when you have questions.
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 = '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 ~= '????' and otherdevices[Seizoen] ~= 'On' then
-- reset all switches to Off
print('Het seizoen is veranderd, het is nu '..Seizoen)
commandArray['Winter'] = 'Off'
commandArray['Voorjaar'] = 'Off'
commandArray['Zomer'] = 'Off'
commandArray['Herfst'] = 'Off'
-- reset current season to On
commandArray[Seizoen] = 'On'
end
return commandArray
Jos
Re: LUA: Summer / Winter from timeofday or other...
Posted: Sunday 14 February 2016 14:07
by Derik
Jos...
Thanks, if you are a girl i .......you...
Code: Select all
6-02-14 13:56:54.166 (D.M.: CV Opentherm) Thermostat (Max_CH Water Setpoint)
2016-02-14 13:56:57.530 (D.M.: Slave 1) General/Percentage (Slave 1: Cpu)
2016-02-14 13:56:59.050 (D.M.: Zwave) Usage (Unknown)
2016-02-14 13:56:59.054 (D.M.: Zwave) General/kWh (kWh Meter)
2016-02-14 13:56:59.483 (D.M.: Zwave) Usage (Z: Pomp)
2016-02-14 13:56:59.492 (D.M.: Zwave) General/kWh (kWh Meter)
2016-02-14 13:56:59.607 (D.M. :Winddelen) General/kWh (D.M.: 3x Jonge Held)
2016-02-14 13:56:59.906 (D.M.: Zwave) Usage (Unknown)
2016-02-14 13:56:59.910 (D.M.: Zwave) General/kWh (kWh Meter)
2[b]016-02-14 13:57:00.395 LUA: Het seizoen is veranderd, het is nu Winter[/b]
2016-02-14 13:57:01.867 (D.M.: P1) P1 Smart Meter (D.M. P1: Stroom)
2016-02-14 13:57:08.099 (D.M.: Zwave) Usage (Z: Pellet)
Really great work!!!!
Thanks!!!
One question. why do i need no IDX?
A option to place your code in the wiki...
Re: LUA: Summer / Winter from timeofday or other...
Posted: Sunday 14 February 2016 14:13
by deennoo
Hello.
There is a free API d'or this.
This not a LUA script but works great, you need to create a dummy text device.
We create it on Easydomoticz.com a Domoticz french forum.
File: saison.sh
#!/bin/bash
saison=$(curl -s "
http://domogeek.entropialux.com/season")
echo $saison
if [ $saison = "autumn" ];then
saisonfr="Automne"
elif [ $saison = "winter" ];then
saisonfr="Hiver"
elif [ $saison = "spring" ];then
saisonfr="Printemps"
elif [ $saison = "summer" ];then
saisonfr="Eté"
fi
echo $saisonfr
curl "
http://192.168.0.21:8080/json.htm?type= ... =$saisonfr
To finish i call it everyday with a cron.
Re: LUA: Summer / Winter from timeofday or other...
Posted: Sunday 14 February 2016 14:15
by jvdz
Derik wrote:Jos...
Thanks, if you are a girl i .......you...
Not sure where you got the girl impression from but ... No ... very Male.
Derik wrote:One question. why do i need no IDX?
A option to place your code in the wiki...
Why use the IDX when you can use the standard LUA Event tables like specified on this WiKi page? :
https://www.domoticz.com/wiki/Events
The IDX is only needed for the special devices like when using a Sensor or Text device.
Jos
Re: LUA: Summer / Winter from timeofday or other...
Posted: Sunday 14 February 2016 14:16
by Derik
deennoo wrote:Hello.
There is a free API d'or this.
This not a LUA script but works great, you need to create a dummy text device.
We create it on Easydomoticz.com a Domoticz french forum.
File: saison.sh
#!/bin/bash
saison=$(curl -s "
http://domogeek.entropialux.com/season")
echo $saison
if [ $saison = "autumn" ];then
saisonfr="Automne"
elif [ $saison = "winter" ];then
saisonfr="Hiver"
elif [ $saison = "spring" ];then
saisonfr="Printemps"
elif [ $saison = "summer" ];then
saisonfr="Eté"
fi
echo $saisonfr
curl "
http://192.168.0.21:8080/json.htm?type= ... =$saisonfr
To finish i call it everyday with a cron.
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...
Re: LUA: Summer / Winter from timeofday or other...
Posted: Sunday 14 February 2016 16:48
by jvdz
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