LUA: Summer / Winter from timeofday or other...
Moderator: leecollings
- jcjames13009
- Posts: 33
- Joined: Monday 09 March 2015 15:24
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2023.2
- Location: France / Marseille
- Contact:
LUA: Summer / Winter from timeofday or other...
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
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
-
- Posts: 625
- Joined: Thursday 02 October 2014 6:36
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2022.2
- Location: Geleen
- Contact:
Re: LUA: Summer / Winter from timeofday or other...
Seasons are fixed, 4 dates every year, why not hard code that?
-
- Posts: 890
- Joined: Tuesday 30 September 2014 8:49
- Target OS: Linux
- Domoticz version: beta
- Location: The Netherlands
- Contact:
Re: LUA: Summer / Winter from timeofday or other...
Hardcoding it is also done by people using other home automation systems: http://board.homeseer.com/showthread.php?t=155133
I am not active on this forum anymore.
- jcjames13009
- Posts: 33
- Joined: Monday 09 March 2015 15:24
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2023.2
- Location: France / Marseille
- Contact:
Re: LUA: Summer / Winter from timeofday or other...
That's what I was thinking about. But wanted to know before if there were an easier solution.
Thanks
JC
Thanks
JC
-
- Posts: 625
- Joined: Thursday 02 October 2014 6:36
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2022.2
- Location: Geleen
- Contact:
Re: LUA: Summer / Winter from timeofday or other...
Normally hardcoding is the easy way.
- jcjames13009
- Posts: 33
- Joined: Monday 09 March 2015 15:24
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2023.2
- Location: France / Marseille
- Contact:
Re: LUA: Summer / Winter from timeofday or other...
Hi
That's what I did:
Solution 1: Use dummy switches one for each season
with the following lua script that set each switch to "ON" or "OFF" depending on season change date
Solution 2: Use user variable
with the following lua script that change the value of the variable at season change date
Maybe it can help someone.
JC
That's what I did:
Solution 1: Use dummy switches one for each season
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
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
JC
-
- Posts: 890
- Joined: Tuesday 30 September 2014 8:49
- Target OS: Linux
- Domoticz version: beta
- Location: The Netherlands
- Contact:
Re: LUA: Summer / Winter from timeofday or other...
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:
Text sensor can be created by Setup > Hardware > Dummy hardware. Then at the dummy hardware click 'Create device', type 'text'
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"
I am not active on this forum anymore.
- jcjames13009
- Posts: 33
- Joined: Monday 09 March 2015 15:24
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2023.2
- Location: France / Marseille
- Contact:
Re: LUA: Summer / Winter from timeofday or other...
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
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
-
- Posts: 890
- Joined: Tuesday 30 September 2014 8:49
- Target OS: Linux
- Domoticz version: beta
- Location: The Netherlands
- Contact:
Re: LUA: Summer / Winter from timeofday or other...
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?
I am not active on this forum anymore.
-
- 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...
Someone has this working???
Found some scripts [ thanks to the maker?? ] only cannot get this working..?
Please help
Or perhaps some one have 4 dummy switches that are flipping by the seasons...
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
Or perhaps some one have 4 dummy switches that are flipping by the seasons...
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
- 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...
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
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
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
-
- 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...
The hole part is not working because i do not understand this script...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
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
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
- 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...
Understood, a learning experience for you.
So what are your exact switchnames to use for the 4 seasons?
Jos
So what are your exact switchnames to use for the 4 seasons?
Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
-
- 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...
All dummys:
Voorjaar : IDX:4194
Zomer : IDX: 4195
Herfst : IDX: 4196
Winter: IDX: 4197
Voorjaar : IDX:4194
Zomer : IDX: 4195
Herfst : IDX: 4196
Winter: IDX: 4197
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
- 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...
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.
Jos
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
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
-
- 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...
Jos...
Thanks, if you are a girl i .......you...
Really great work!!!!
Thanks!!!
One question. why do i need no IDX?
A option to place your code in the wiki...
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)
Thanks!!!
One question. why do i need no IDX?
A option to place your code in the wiki...
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
-
- Posts: 784
- Joined: Wednesday 10 December 2014 13:06
- Target OS: Linux
- Domoticz version: beta
- Location: Bordeaux France
- Contact:
Re: LUA: Summer / Winter from timeofday or other...
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.
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.
Domoticz stable 3.5877 for real & Domoticz beta for test
Rfxtrxe / RFLink / Milight / Yeelight / Tasmota / MQTT / BLE / Zigate
http://domo-attitude.fr
Rfxtrxe / RFLink / Milight / Yeelight / Tasmota / MQTT / BLE / Zigate
http://domo-attitude.fr
- 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...
Not sure where you got the girl impression from but ... No ... very Male.Derik wrote:Jos...
Thanks, if you are a girl i .......you...
Why use the IDX when you can use the standard LUA Event tables like specified on this WiKi page? :Derik wrote:One question. why do i need no IDX?
A option to place your code in the wiki...
https://www.domoticz.com/wiki/Events
The IDX is only needed for the special devices like when using a Sensor or Text device.
Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
-
- 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...
The option from Jos, is without any hard to get stuff...... I got him working in a few minutes....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.
Without cron is better for my backup...
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
- 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...
Did you see my post above your's since we posted around the same time?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...
Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
Who is online
Users browsing this forum: No registered users and 0 guests