Enable lua (time) script by switch (possible?) Topic is solved
Moderator: leecollings
-
- Posts: 229
- Joined: Wednesday 30 April 2014 20:27
- Target OS: Raspberry Pi / ODroid
- Domoticz version: Stable
- Location: The Netherlands
- Contact:
Enable lua (time) script by switch (possible?)
I would like to use the moon phase script ( viewtopic.php?f=67&t=16526&p=130249#p130249 )
only if a particular switch is on. Is that possible??
Thanks in advance.
only if a particular switch is on. Is that possible??
Thanks in advance.
Re: Enable lua (time) script by switch (possible?)
If you can somehow set 'Status' in the Domoticz database table 'Eventmaster', you can enable (1) or disable (0) a LUA script.
-
- Posts: 229
- Joined: Wednesday 30 April 2014 20:27
- Target OS: Raspberry Pi / ODroid
- Domoticz version: Stable
- Location: The Netherlands
- Contact:
Re: Enable lua (time) script by switch (possible?)
Thanks for your answer.SweetPants wrote:If you can somehow set 'Status' in the Domoticz database table 'Eventmaster', you can enable (1) or disable (0) a LUA script.
My conclusion based on your answer: It is not possible to add the function of a switch (if on >> script runs on time, if off >> script don’t run) to the script itself. Am I right?
Re: Enable lua (time) script by switch (possible?)
I'm not sure if i understand you correctly, but you can have an 'On/Off action' coupled on a switch.
This action can fire an http:// request or run a script://. In your case you should have a script that modfies the database eventmaster table column 'Status' of the script. You should either have the 'ID' or 'Name' of the script to select it in your SQL select statement.
I guess the buienradar script is a 'time' based script, so if 'Status' enabled it will run by itself every minute.
This action can fire an http:// request or run a script://. In your case you should have a script that modfies the database eventmaster table column 'Status' of the script. You should either have the 'ID' or 'Name' of the script to select it in your SQL select statement.
I guess the buienradar script is a 'time' based script, so if 'Status' enabled it will run by itself every minute.
-
- Posts: 229
- Joined: Wednesday 30 April 2014 20:27
- Target OS: Raspberry Pi / ODroid
- Domoticz version: Stable
- Location: The Netherlands
- Contact:
Re: Enable lua (time) script by switch (possible?)
@ SweetPants
I now have the impression that it is possible but I do not quite know how to do it.
It concerns the following code (saved as domoticz/scripts/lua/script_time_maanfase.lua). The script itself works as desired.
I can create a virtual switch. I know a switch has an On and Off Action field, I now think I have to use this fields to achieve my goal.
I know now that Domoticz uses a SQL database. That's where my knowledge stops. So, I need help in compiling the http request that modifies the database. I hope you can help.
Thanks in advance.
I now have the impression that it is possible but I do not quite know how to do it.
It concerns the following code (saved as domoticz/scripts/lua/script_time_maanfase.lua). The script itself works as desired.
Code: Select all
-- Variables to customize ------------------------------------------------
local moonpicture = "MoonPicture" -- name of the uservar to write the name of the moonphase picture to
local checkvar = "MoonphaseCheck" -- name of the uservar to check if update is allowed
local checktime = 3600 -- check allowed every x seconds 3600 = 60 min. Check the wundergroud API limitation before changing this
local city = "<your town>" -- Your city for Wunderground API
local countryCode = "<YOUR COUNTRY CODE>" -- Your country code for Wunderground API
local idxmoonpercentage ='125' -- Your virtual moon percentage illuminated Device ID
local idxmoonage ='131' -- Your virtual moon age Device ID
local idxmoonphase ='132' -- Your virtual moon phase Device ID
local idxmoonrise='124' -- Your virtual moon rise variable ID
local idxmoonset='127' -- Your virtual moon set variable ID
local wuAPIkey = "<your key>" -- Your Weather Underground API Key
local DOMO_IP = "<your domo ip>" -- Domoticz ip address
local DOMO_PORT = "<your domo port>" -- Domoticz port
local tempfilename = '/var/tmp/phase.tmp' -- can be anywhere writeable
local debug=false -- false, true for domoticz log
-------------------------------------------------------------------------
function file_exists(path)
-- function to check if a file exists
local file = io.open(path, "rb")
if file then file:close() end
return file ~= nil
end
function timedifference(s)
-- function to determine the difference in seconds between the current time and a given one
year = string.sub(s, 1, 4)
month = string.sub(s, 6, 7)
day = string.sub(s, 9, 10)
hour = string.sub(s, 12, 13)
minutes = string.sub(s, 15, 16)
seconds = string.sub(s, 18, 19)
t1 = os.time()
t2 = os.time{year=year, month=month, day=day, hour=hour, min=minutes, sec=seconds}
difference = os.difftime (t1, t2)
return difference
end
function may_update(device, timeelapsed)
-- function to check whether an update is allowed
return uservariables_lastupdate[device] == nil or timedifference(uservariables_lastupdate[device]) >= timeelapsed
end
commandArray = {}
time = os.date("*t")
url='http://api.wunderground.com/api/'..wuAPIkey..'/astronomy/q/'..countryCode..'/'..city..'.json'
if (may_update(checkvar,checktime)==true) or (file_exists(tempfilename)==false) then
-- read API Wunderground
if debug then print("Moonphase - Collecting data from: "..url) end
os.execute('curl -s '..url..' > '..tempfilename)
-- NOTE: if the command above doens't work in your situation try
-- read = os.execute('curl -s -o '..tempfilename..' "'..url..'"')
-- instead! Thanks to EdKo66
file = io.open(tempfilename, "r")
s= file:read("*a")
s = (string.gsub(s, "%c+", ""))
file:close()
-- moonrise
moonriseHour, moonriseMinute = string.match(s, [["moonrise": {"hour":"(%d+)","minute":"(%d+)"]])
if debug then print("Moonrise:\t"..moonriseHour..":"..moonriseMinute) end
-- moonset
moonsetHour, moonsetMinute = string.match(s, [["moonset": {"hour":"(%d+)","minute":"(%d+)"]])
if debug then print("Moonset:\t"..moonsetHour..":"..moonsetMinute) end
-- percentage of moon illuminated
percentIlluminated = string.match(s, [["percentIlluminated":"(%d+)"]])
if debug then print("Percent:\t"..percentIlluminated.."%") end
-- age of moon since last new moon
age = string.match(s, [["ageOfMoon":"(%d+)"]])
if debug then print("Age:\t\t"..age) end
-- Phase of the moon
-- set the moonPhaseIcon to your appropriate icon number (8 x)
moonPhase = string.match(s, [["phaseofMoon":"(.-)"]])
if moonPhase=="New Moon" then
moonPhase = "Nieuwe maan"
is_waxing = true
end
if moonPhase=="Waxing Crescent" then
moonPhase = "Wassende halve maan"
is_waxing = true
end
if moonPhase=="First Quarter" then
moonPhase = "Eerste kwartier"
is_waxing = true
end
if moonPhase=="Waxing Gibbous" then
moonPhase = "Wassende maan"
is_waxing = true
end
if moonPhase=="Full" then
moonPhase = "Volle maan"
is_waxing = false
end
if moonPhase=="Waning Gibbous" then
moonPhase = "Afnemende maan"
is_waxing = false
end
if moonPhase=="Last Quarter" then
moonPhase = "Laatste kwartier"
is_waxing = false
end
if moonPhase=="Waning Crescent" then
moonPhase = "Afnemende halve maan"
is_waxing = false
end
-- calculate moonphase picture
if percentIlluminated == '0' then
n='50'
else
if waardecheck==false then
picnumber=math.floor(math.abs(percentIlluminated-100)/2)
else
picnumber=math.floor(50+(percentIlluminated/2))
if picnumber == 100 then
picnumber=99
end
end
n=tostring(picnumber)
if string.len(n)==1 then
n='0'..n
end
end
picture='moon.'..n..'.png'
if debug then print('Picture number: '..n..' '..'Picture name: '..picture) end
commandArray['Variable:'..checkvar]=moonPhase
commandArray['Variable:'..moonpicture]=picture
commandArray[1] = {['UpdateDevice'] = idxmoonphase.."|0|"..moonPhase}
commandArray[2] = {['UpdateDevice'] = idxmoonrise.."|0|"..moonriseHour..":"..moonriseMinute}
commandArray[3] = {['UpdateDevice'] = idxmoonset.."|0|"..moonsetHour..":"..moonsetMinute}
commandArray[4] = {['UpdateDevice'] = idxmoonage.."|0|"..age}
commandArray[5] = {['UpdateDevice'] = idxmoonpercentage.."|0|"..percentIlluminated}
else
if debug then print("MoonPhase - Update not allowed: Difference is "..timedifference(uservariables_lastupdate[checkvar]).." seconds") end
end
return commandArray
I know now that Domoticz uses a SQL database. That's where my knowledge stops. So, I need help in compiling the http request that modifies the database. I hope you can help.
Thanks in advance.
- berny
- Posts: 6
- Joined: Saturday 17 December 2016 13:05
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Location: belgium
- Contact:
Re: Enable lua (time) script by switch (possible?)
Maybe you can create a dummy switch.
If you switch the dummy on, run an bash script that copy your time script from a temp directory to the lua directory.
If you switch the dummy switch off, run a bash script to delete the time script in the lua directory.
If you switch the dummy on, run an bash script that copy your time script from a temp directory to the lua directory.
If you switch the dummy switch off, run a bash script to delete the time script in the lua directory.
Re: Enable lua (time) script by switch (possible?)
is it possible add more Selector actions in a cell??
- Attachments
-
- selector actions.jpg (131.79 KiB) Viewed 4366 times
Re: Enable lua (time) script by switch (possible?)
If you want to ask a non-related question, please open a new topic. This gets confusing and you may not get an answermatteos1 wrote:is it possible add more Selector actions in a cell??
-
- Posts: 229
- Joined: Wednesday 30 April 2014 20:27
- Target OS: Raspberry Pi / ODroid
- Domoticz version: Stable
- Location: The Netherlands
- Contact:
Re: Enable lua (time) script by switch (possible?)
Based on my limited knowledge, I first try this option. So far, I could copy and paste the necessary codes. But in this case, I could not find the suggested code. I made one myself but I failed.berny wrote:Maybe you can create a dummy switch.
If you switch the dummy on, run an bash script that copy your time script from a temp directory to the lua directory.
If you switch the dummy switch off, run a bash script to delete the time script in the lua directory.
Steps I made:
- Created a virtual switch 'Test' idx=12;
- In the /domoticz/ directory, I created a new directory "program_storage" in which I installed the "script_time_maanfase.lua" code;
- The following code was placed in the /domoticz/scripts/ directory. - execute sudo chmod+ program_switch.sh
When I turn the switch 'on' nothing happens > also no errors in domoticz and syslog. Conclusion: I need help in making the next step.
Thanks in advance.
-
- Posts: 272
- Joined: Sunday 11 May 2014 11:09
- Target OS: Windows
- Domoticz version: 2023.1+
- Location: NL
- Contact:
Re: Enable lua (time) script by switch (possible?)
Why making it so complicated ?
Just add the switch to the lua script in an "if then" statement
Or even better put it in function that you can call on the switch (or any other) condition.
The "if then" of "function" consumes no time at al if the condition is not true . (<2 ms)
Just add the switch to the lua script in an "if then" statement
Code: Select all
If otherdevices["ÿour switch"]=="on" then
moon script
end
The "if then" of "function" consumes no time at al if the condition is not true . (<2 ms)
Rpi & Win x64. Using : cam's,RFXCom, LaCrosse, RFY, HuE, google, standard Lua, Tasker, Waze traveltime, NLAlert&grip2+,curtains, vacuum, audioreceiver, smart-heating&cooling + many more (= automate all repetitive simple tasks)
-
- Posts: 229
- Joined: Wednesday 30 April 2014 20:27
- Target OS: Raspberry Pi / ODroid
- Domoticz version: Stable
- Location: The Netherlands
- Contact:
Re: Enable lua (time) script by switch (possible?)
Let me start with the goal first. This setup is for mobile use. An internet connection is therefore not always available. No internet means many error messages in the Domoticz log. I want to avoid those errors, which is the reason for my question.
edited code (original see https://www.domoticz.com/forum/viewtopi ... 49#p130249 )
domoticz log shows
As the log indicates, it does not matter whether the switch is on or off. Even when I use script_device instead of script_time, I get the same errors in domoticz log. I got stuck! Thanks in advance for someone's precious time.
@zicht, thank you for your attention. I tried your suggestion, but it does not work as desired.zicht wrote:Why making it so complicated ?
Just add the switch to the lua script in an "if then" statementCode: Select all
If otherdevices["ÿour switch"]=="on" then moon script end
edited code (original see https://www.domoticz.com/forum/viewtopi ... 49#p130249 )
Code: Select all
-- Variables to customize ------------------------------------------------
local moonpicture = "MoonPicture" -- name of the uservar to write the name of the moonphase picture to
local checkvar = "MoonphaseCheck" -- name of the uservar to check if update is allowed
local checktime = 3600 -- check allowed every x seconds 3600 = 60 min. Check the wundergroud API limitation before changing this
local city = "<your town>" -- Your city for Wunderground API
local countryCode = "<YOUR COUNTRY CODE>" -- Your country code for Wunderground API
local idxmoonpercentage ='125' -- Your virtual moon percentage illuminated Device ID
local idxmoonage ='131' -- Your virtual moon age Device ID
local idxmoonphase ='132' -- Your virtual moon phase Device ID
local idxmoonrise='124' -- Your virtual moon rise variable ID
local idxmoonset='127' -- Your virtual moon set variable ID
local wuAPIkey = "<your key>" -- Your Weather Underground API Key
local DOMO_IP = "<your domo ip>" -- Domoticz ip address
local DOMO_PORT = "<your domo port>" -- Domoticz port
local tempfilename = '/var/tmp/phase.tmp' -- can be anywhere writeable
local debug=false -- false, true for domoticz log
-------------------------------------------------------------------------
if otherdevices["Test"]=="on" then
function file_exists(path)
-- function to check if a file exists
local file = io.open(path, "rb")
if file then file:close() end
return file ~= nil
end
function timedifference(s)
-- function to determine the difference in seconds between the current time and a given one
year = string.sub(s, 1, 4)
month = string.sub(s, 6, 7)
day = string.sub(s, 9, 10)
hour = string.sub(s, 12, 13)
minutes = string.sub(s, 15, 16)
seconds = string.sub(s, 18, 19)
t1 = os.time()
t2 = os.time{year=year, month=month, day=day, hour=hour, min=minutes, sec=seconds}
difference = os.difftime (t1, t2)
return difference
end
function may_update(device, timeelapsed)
-- function to check whether an update is allowed
return uservariables_lastupdate[device] == nil or timedifference(uservariables_lastupdate[device]) >= timeelapsed
end
commandArray = {}
time = os.date("*t")
url='http://api.wunderground.com/api/'..wuAPIkey..'/astronomy/q/'..countryCode..'/'..city..'.json'
if (may_update(checkvar,checktime)==true) or (file_exists(tempfilename)==false) then
-- read API Wunderground
if debug then print("Moonphase - Collecting data from: "..url) end
os.execute('curl -s '..url..' > '..tempfilename)
-- NOTE: if the command above doens't work in your situation try
-- read = os.execute('curl -s -o '..tempfilename..' "'..url..'"')
-- instead! Thanks to EdKo66
file = io.open(tempfilename, "r")
s= file:read("*a")
s = (string.gsub(s, "%c+", ""))
file:close()
-- moonrise
moonriseHour, moonriseMinute = string.match(s, [["moonrise": {"hour":"(%d+)","minute":"(%d+)"]])
if debug then print("Moonrise:\t"..moonriseHour..":"..moonriseMinute) end
-- moonset
moonsetHour, moonsetMinute = string.match(s, [["moonset": {"hour":"(%d+)","minute":"(%d+)"]])
if debug then print("Moonset:\t"..moonsetHour..":"..moonsetMinute) end
-- percentage of moon illuminated
percentIlluminated = string.match(s, [["percentIlluminated":"(%d+)"]])
if debug then print("Percent:\t"..percentIlluminated.."%") end
-- age of moon since last new moon
age = string.match(s, [["ageOfMoon":"(%d+)"]])
if debug then print("Age:\t\t"..age) end
-- Phase of the moon
-- set the moonPhaseIcon to your appropriate icon number (8 x)
moonPhase = string.match(s, [["phaseofMoon":"(.-)"]])
if moonPhase=="New Moon" then
moonPhase = "Nieuwe maan"
is_waxing = true
end
if moonPhase=="Waxing Crescent" then
moonPhase = "Wassende halve maan"
is_waxing = true
end
if moonPhase=="First Quarter" then
moonPhase = "Eerste kwartier"
is_waxing = true
end
if moonPhase=="Waxing Gibbous" then
moonPhase = "Wassende maan"
is_waxing = true
end
if moonPhase=="Full" then
moonPhase = "Volle maan"
is_waxing = false
end
if moonPhase=="Waning Gibbous" then
moonPhase = "Afnemende maan"
is_waxing = false
end
if moonPhase=="Last Quarter" then
moonPhase = "Laatste kwartier"
is_waxing = false
end
if moonPhase=="Waning Crescent" then
moonPhase = "Afnemende halve maan"
is_waxing = false
end
-- calculate moonphase picture
if percentIlluminated == '0' then
n='50'
else
if waardecheck==false then
picnumber=math.floor(math.abs(percentIlluminated-100)/2)
else
picnumber=math.floor(50+(percentIlluminated/2))
if picnumber == 100 then
picnumber=99
end
end
n=tostring(picnumber)
if string.len(n)==1 then
n='0'..n
end
end
picture='moon.'..n..'.png'
if debug then print('Picture number: '..n..' '..'Picture name: '..picture) end
commandArray['Variable:'..checkvar]=moonPhase
commandArray['Variable:'..moonpicture]=picture
commandArray[1] = {['UpdateDevice'] = idxmoonphase.."|0|"..moonPhase}
commandArray[2] = {['UpdateDevice'] = idxmoonrise.."|0|"..moonriseHour..":"..moonriseMinute}
commandArray[3] = {['UpdateDevice'] = idxmoonset.."|0|"..moonsetHour..":"..moonsetMinute}
commandArray[4] = {['UpdateDevice'] = idxmoonage.."|0|"..age}
commandArray[5] = {['UpdateDevice'] = idxmoonpercentage.."|0|"..percentIlluminated}
else
if debug then print("MoonPhase - Update not allowed: Difference is "..timedifference(uservariables_lastupdate[checkvar]).." seconds") end
end
end
return commandArray
Code: Select all
2017-06-06 14:56:00.077 Error: EventSystem: Lua script /home/pi/domoticz/scripts/lua/script_time_maanfasetest.lua did not return a commandArray
2017-06-06 14:56:25.918 Hardware Monitor: Fetching data (System sensors)
2017-06-06 14:56:56.021 Hardware Monitor: Fetching data (System sensors)
2017-06-06 14:57:00.127 Error: EventSystem: Lua script /home/pi/domoticz/scripts/lua/script_time_maanfasetest.lua did not return a commandArray
2017-06-06 14:57:26.123 Hardware Monitor: Fetching data (System sensors)
2017-06-06 14:57:56.225 Hardware Monitor: Fetching data (System sensors)
2017-06-06 14:58:00.177 Error: EventSystem: Lua script /home/pi/domoticz/scripts/lua/script_time_maanfasetest.lua did not return a commandArray
2017-06-06 14:58:26.376 Hardware Monitor: Fetching data (System sensors)
2017-06-06 14:58:36.959 User: Admin initiated a switch command (12/Test/On)
2017-06-06 14:58:36.971 (Test) Lighting 1 (Test)
2017-06-06 14:58:56.478 Hardware Monitor: Fetching data (System sensors)
2017-06-06 14:59:00.226 Error: EventSystem: Lua script /home/pi/domoticz/scripts/lua/script_time_maanfasetest.lua did not return a commandArray
2017-06-06 14:59:26.582 Hardware Monitor: Fetching data (System sensors)
2017-06-06 14:59:56.684 Hardware Monitor: Fetching data (System sensors)
2017-06-06 15:00:00.414 Error: EventSystem: Lua script /home/pi/domoticz/scripts/lua/script_time_maanfasetest.lua did not return a commandArray
2017-06-06 15:00:00.434 LUA: Seizoen aangepast naar Lente
2017-06-06 15:00:00.491 (Seizoen) Light/Switch (Seizoen)
2017-06-06 15:00:26.787 Hardware Monitor: Fetching data (System sensors)
2017-06-06 15:00:56.889 Hardware Monitor: Fetching data (System sensors)
2017-06-06 15:01:00.481 Error: EventSystem: Lua script /home/pi/domoticz/scripts/lua/script_time_maanfasetest.lua did not return a commandArray
2017-06-06 15:01:26.992 Hardware Monitor: Fetching data (System sensors)
2017-06-06 15:01:57.095 Hardware Monitor: Fetching data (System sensors)
2017-06-06 15:02:00.031 Error: EventSystem: Lua script /home/pi/domoticz/scripts/lua/script_time_maanfasetest.lua did not return a commandArray
2017-06-06 15:02:27.198 Hardware Monitor: Fetching data (System sensors)
2017-06-06 15:02:57.301 Hardware Monitor: Fetching data (System sensors)
2017-06-06 15:03:00.081 Error: EventSystem: Lua script /home/pi/domoticz/scripts/lua/script_time_maanfasetest.lua did not return a commandArray
-
- Posts: 272
- Joined: Sunday 11 May 2014 11:09
- Target OS: Windows
- Domoticz version: 2023.1+
- Location: NL
- Contact:
Re: Enable lua (time) script by switch (possible?)
Hi
The functions can be out of the if then as they are called as a subroutine code.
The if then should be a couple of lines later, i am pretty sture thats what is causing the errors in your log.
Now the start of Commandarray is skipped when your switch is off.
have a Try with the below place of the " if then "
The functions can be out of the if then as they are called as a subroutine code.
The if then should be a couple of lines later, i am pretty sture thats what is causing the errors in your log.
Now the start of Commandarray is skipped when your switch is off.
have a Try with the below place of the " if then "
Code: Select all
-- Variables to customize ------------------------------------------------
local moonpicture = "MoonPicture" -- name of the uservar to write the name of the moonphase picture to
local checkvar = "MoonphaseCheck" -- name of the uservar to check if update is allowed
local checktime = 3600 -- check allowed every x seconds 3600 = 60 min. Check the wundergroud API limitation before changing this
local city = "<your town>" -- Your city for Wunderground API
local countryCode = "<YOUR COUNTRY CODE>" -- Your country code for Wunderground API
local idxmoonpercentage ='125' -- Your virtual moon percentage illuminated Device ID
local idxmoonage ='131' -- Your virtual moon age Device ID
local idxmoonphase ='132' -- Your virtual moon phase Device ID
local idxmoonrise='124' -- Your virtual moon rise variable ID
local idxmoonset='127' -- Your virtual moon set variable ID
local wuAPIkey = "<your key>" -- Your Weather Underground API Key
local DOMO_IP = "<your domo ip>" -- Domoticz ip address
local DOMO_PORT = "<your domo port>" -- Domoticz port
local tempfilename = '/var/tmp/phase.tmp' -- can be anywhere writeable
local debug=false -- false, true for domoticz log
-------------------------------------------------------------------------
function file_exists(path)
-- function to check if a file exists
local file = io.open(path, "rb")
if file then file:close() end
return file ~= nil
end
function timedifference(s)
-- function to determine the difference in seconds between the current time and a given one
year = string.sub(s, 1, 4)
month = string.sub(s, 6, 7)
day = string.sub(s, 9, 10)
hour = string.sub(s, 12, 13)
minutes = string.sub(s, 15, 16)
seconds = string.sub(s, 18, 19)
t1 = os.time()
t2 = os.time{year=year, month=month, day=day, hour=hour, min=minutes, sec=seconds}
difference = os.difftime (t1, t2)
return difference
end
function may_update(device, timeelapsed)
-- function to check whether an update is allowed
return uservariables_lastupdate[device] == nil or timedifference(uservariables_lastupdate[device]) >= timeelapsed
end
commandArray = {}
if otherdevices["Test"]=="on" then
time = os.date("*t")
url='http://api.wunderground.com/api/'..wuAPIkey..'/astronomy/q/'..countryCode..'/'..city..'.json'
if (may_update(checkvar,checktime)==true) or (file_exists(tempfilename)==false) then
-- read API Wunderground
if debug then print("Moonphase - Collecting data from: "..url) end
os.execute('curl -s '..url..' > '..tempfilename)
-- NOTE: if the command above doens't work in your situation try
-- read = os.execute('curl -s -o '..tempfilename..' "'..url..'"')
-- instead! Thanks to EdKo66
file = io.open(tempfilename, "r")
s= file:read("*a")
s = (string.gsub(s, "%c+", ""))
file:close()
-- moonrise
moonriseHour, moonriseMinute = string.match(s, [["moonrise": {"hour":"(%d+)","minute":"(%d+)"]])
if debug then print("Moonrise:\t"..moonriseHour..":"..moonriseMinute) end
-- moonset
moonsetHour, moonsetMinute = string.match(s, [["moonset": {"hour":"(%d+)","minute":"(%d+)"]])
if debug then print("Moonset:\t"..moonsetHour..":"..moonsetMinute) end
-- percentage of moon illuminated
percentIlluminated = string.match(s, [["percentIlluminated":"(%d+)"]])
if debug then print("Percent:\t"..percentIlluminated.."%") end
-- age of moon since last new moon
age = string.match(s, [["ageOfMoon":"(%d+)"]])
if debug then print("Age:\t\t"..age) end
-- Phase of the moon
-- set the moonPhaseIcon to your appropriate icon number (8 x)
moonPhase = string.match(s, [["phaseofMoon":"(.-)"]])
if moonPhase=="New Moon" then
moonPhase = "Nieuwe maan"
is_waxing = true
end
if moonPhase=="Waxing Crescent" then
moonPhase = "Wassende halve maan"
is_waxing = true
end
if moonPhase=="First Quarter" then
moonPhase = "Eerste kwartier"
is_waxing = true
end
if moonPhase=="Waxing Gibbous" then
moonPhase = "Wassende maan"
is_waxing = true
end
if moonPhase=="Full" then
moonPhase = "Volle maan"
is_waxing = false
end
if moonPhase=="Waning Gibbous" then
moonPhase = "Afnemende maan"
is_waxing = false
end
if moonPhase=="Last Quarter" then
moonPhase = "Laatste kwartier"
is_waxing = false
end
if moonPhase=="Waning Crescent" then
moonPhase = "Afnemende halve maan"
is_waxing = false
end
-- calculate moonphase picture
if percentIlluminated == '0' then
n='50'
else
if waardecheck==false then
picnumber=math.floor(math.abs(percentIlluminated-100)/2)
else
picnumber=math.floor(50+(percentIlluminated/2))
if picnumber == 100 then
picnumber=99
end
end
n=tostring(picnumber)
if string.len(n)==1 then
n='0'..n
end
end
picture='moon.'..n..'.png'
if debug then print('Picture number: '..n..' '..'Picture name: '..picture) end
commandArray['Variable:'..checkvar]=moonPhase
commandArray['Variable:'..moonpicture]=picture
commandArray[1] = {['UpdateDevice'] = idxmoonphase.."|0|"..moonPhase}
commandArray[2] = {['UpdateDevice'] = idxmoonrise.."|0|"..moonriseHour..":"..moonriseMinute}
commandArray[3] = {['UpdateDevice'] = idxmoonset.."|0|"..moonsetHour..":"..moonsetMinute}
commandArray[4] = {['UpdateDevice'] = idxmoonage.."|0|"..age}
commandArray[5] = {['UpdateDevice'] = idxmoonpercentage.."|0|"..percentIlluminated}
else
if debug then print("MoonPhase - Update not allowed: Difference is "..timedifference(uservariables_lastupdate[checkvar]).." seconds") end
end
end
return commandArray
Rpi & Win x64. Using : cam's,RFXCom, LaCrosse, RFY, HuE, google, standard Lua, Tasker, Waze traveltime, NLAlert&grip2+,curtains, vacuum, audioreceiver, smart-heating&cooling + many more (= automate all repetitive simple tasks)
-
- Posts: 1602
- Joined: Friday 18 October 2013 23:33
- Target OS: Raspberry Pi / ODroid
- Domoticz version: BETA
- Location: Arnhem/Nijmegen Nederland
- Contact:
Re: Enable lua (time) script by switch (possible?)
dear...
Someone have this working, after weather underground is stopped working?
Someone have this working, after weather underground is stopped working?
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
Who is online
Users browsing this forum: No registered users and 1 guest