Real-time solar data : azimuth, Altitude, Lux sensor... [closed]
Moderator: leecollings
-
- Posts: 147
- Joined: Wednesday 02 August 2017 18:12
- Target OS: Raspberry Pi / ODroid
- Domoticz version: stable
- Location: France
- Contact:
Re: Real-time solar data : azimuth, Altitude, Lux sensor...
Hello!
Why don't use localisation in domoticz parameter ?
Why don't use localisation in domoticz parameter ?
Platforme: Rpbi3b
Domoticz: Last stable
Bridge: RFLINK last stable
Domoticz: Last stable
Bridge: RFLINK last stable
-
- Posts: 28
- Joined: Sunday 11 December 2016 18:30
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Real-time solar data : azimuth, Altitude, Lux sensor...
anyone also experiencing issues with the call to the ohimet.com site?
I am getting:
2017-08-23 20:08:01.044 LUA: curl "http://www.ogimet.com/cgi-bin/getsynop? ... 1708231700"
2017-08-23 20:08:02.208 LUA: ogimet:Status: 501 getsynop: no se pudo conectar a la base de datos
because of this error the real-time-solar-script is not calculation a lux value
I am getting:
2017-08-23 20:08:01.044 LUA: curl "http://www.ogimet.com/cgi-bin/getsynop? ... 1708231700"
2017-08-23 20:08:02.208 LUA: ogimet:Status: 501 getsynop: no se pudo conectar a la base de datos
because of this error the real-time-solar-script is not calculation a lux value
RPI-3 : RFLink + Zigbee2MQTT + Shelly + MySensors + Milight
-
- Posts: 22
- Joined: Sunday 11 June 2017 14:06
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Real-time solar data : azimuth, Altitude, Lux sensor...
I am experiencing the same since about 7 hours ago.Misterik wrote: ↑Wednesday 23 August 2017 20:22 anyone also experiencing issues with the call to the ohimet.com site?
I am getting:
2017-08-23 20:08:01.044 LUA: curl "http://www.ogimet.com/cgi-bin/getsynop? ... 1708231700"
2017-08-23 20:08:02.208 LUA: ogimet:Status: 501 getsynop: no se pudo conectar a la base de datos
because of this error the real-time-solar-script is not calculation a lux value
-
- Posts: 28
- Joined: Sunday 11 December 2016 18:30
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Real-time solar data : azimuth, Altitude, Lux sensor...
Looks like the problem is resolved. Script is up and running again.
RPI-3 : RFLink + Zigbee2MQTT + Shelly + MySensors + Milight
-
- Posts: 485
- Joined: Thursday 17 September 2015 10:13
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
Re: Real-time solar data : azimuth, Altitude, Lux sensor...
With permission of the original author jmleglise I have translated this script into dzVents and I also made several changes to it.
The dzVents script has been put in the Wiki, after the ordinary Lua script.
For any questions or comments about the dzVents version of the script, please use the designated thread.
The dzVents script has been put in the Wiki, after the ordinary Lua script.
For any questions or comments about the dzVents version of the script, please use the designated thread.
-
- Posts: 667
- Joined: Wednesday 08 March 2017 9:42
- Target OS: Linux
- Domoticz version: 3.8993
- Location: Amsterdam
- Contact:
Re: Real-time solar data : azimuth, Altitude, Lux sensor...
Hi There all,
Can someone help me, i want create a second LUX device where i only see the numbers. Or a user variable.
Then in script it update this device or variable. So i can use it in a blocky. When lux < 100 turn lights on
Thanks
Can someone help me, i want create a second LUX device where i only see the numbers. Or a user variable.
Then in script it update this device or variable. So i can use it in a blocky. When lux < 100 turn lights on
Thanks
RPi3 B+, Debain Stretch, Domoticz, Homebridge, Dashticz, RFLink, Milight, Z-Wave, Fibaro, Nanoleaf, Nest, Harmony Hub, Now try to understand pass2php
-
- Posts: 722
- Joined: Friday 02 October 2015 12:12
- Target OS: Raspberry Pi / ODroid
- Domoticz version: beta
- Location: Finland
- Contact:
Re: Real-time solar data : azimuth, Altitude, Lux sensor...
In case there aren''t any major changes (according to wiki I'd say no there is not) then this script is designed to update three sensors one of them which is Lux (and thus indeed showing the lux as a number in sValue) - problem solved?
- najtram
- Posts: 62
- Joined: Wednesday 26 April 2017 11:50
- Target OS: Raspberry Pi / ODroid
- Domoticz version: v4.9700
- Location: Netherlands
- Contact:
Re: Real-time solar data : azimuth, Altitude, Lux sensor...
I'm getting the following error:
Could someone help me to identify the problem?2017-11-09 09:42:11.946 Error: EventSystem: in /home/pi/domoticz/scripts/lua/script_time_SolarSensor.lua: /home/pi/domoticz/scripts/lua/script_time_SolarSensor.lua:149: bad argument #1 to 'gsub' (string expected, got nil)
RFLink Gateway → 433Mhz/KAKU switches
Z-Wave → Z-Stick Gen5+
ZigBee → ConBee II
Bluetooth → Soma Smart Shades
Opentherm Gateway → Remeha iSense - Tzerra boiler
ESP8266+CC1101 → ITHO ecofan RFT
P1 cable → DSMR 2.2+ Landys +gyr E350
LAN → Enphase Envoy
Z-Wave → Z-Stick Gen5+
ZigBee → ConBee II
Bluetooth → Soma Smart Shades
Opentherm Gateway → Remeha iSense - Tzerra boiler
ESP8266+CC1101 → ITHO ecofan RFT
P1 cable → DSMR 2.2+ Landys +gyr E350
LAN → Enphase Envoy
- najtram
- Posts: 62
- Joined: Wednesday 26 April 2017 11:50
- Target OS: Raspberry Pi / ODroid
- Domoticz version: v4.9700
- Location: Netherlands
- Contact:
Re: Real-time solar data : azimuth, Altitude, Lux sensor...
Problem is solved while nothing changed. (except maybe the data retreived from somewhere).
RFLink Gateway → 433Mhz/KAKU switches
Z-Wave → Z-Stick Gen5+
ZigBee → ConBee II
Bluetooth → Soma Smart Shades
Opentherm Gateway → Remeha iSense - Tzerra boiler
ESP8266+CC1101 → ITHO ecofan RFT
P1 cable → DSMR 2.2+ Landys +gyr E350
LAN → Enphase Envoy
Z-Wave → Z-Stick Gen5+
ZigBee → ConBee II
Bluetooth → Soma Smart Shades
Opentherm Gateway → Remeha iSense - Tzerra boiler
ESP8266+CC1101 → ITHO ecofan RFT
P1 cable → DSMR 2.2+ Landys +gyr E350
LAN → Enphase Envoy
-
- Posts: 229
- Joined: Friday 03 April 2015 20:44
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Location: Germany (near dutch border)
- Contact:
Re: Real-time solar data : azimuth, Altitude, Lux sensor...
Ogimet was unreachable.. that caused it.
Cheers, Hans
Cheers, Hans
-
- Posts: 1
- Joined: Sunday 02 April 2017 8:36
- Target OS: NAS (Synology & others)
- Domoticz version: 3.8
- Location: Belgium
- Contact:
Re: Real-time solar data : azimuth, Altitude, Lux sensor...
Hi all,
Tried to load the script but it seems I cannot get the data out of JSON.lua. I have placed next text at top of the file
local localhost = '127.0.0.1:8080' -- Set your port. (Not the universal IP).
local city = "LOKEREN" -- Your city for Wunderground API
local countryCode = "BE" -- Your country code for Wunderground API
local idxLux ='502' -- Your virtual Lux Device ID
local idxSolarAzimuth ='534' -- Your virtual Azimuth Device ID
local idxSolarAltitude ='533' -- Your virtual Solar Altitude Device ID
local idxUserVarOcta='2' -- Your user variable ID , named octa
local wuAPIkey = "f4xxxxxxxxxxxxxx" -- Your Weather Underground API Key
local latitude = '51.0' -- your home
local longitude = 3.9 -- your home
local altitude = 3.0 -- Your home altitude : run once in debug = 1 to found your altitude in Log and write it here
local WMOID = '06431' -- Your nearest SYNOP Station for ogimet. Very important !
local DEBUG = 1
but getting the feedback Error: EventSystem: in Lux_Lua: [string " --[[ Virtual Lux sensor and other re..."]:70: attempt to index field 'current_observation' (a nil value) for the line 70: local latitude = jsonLocation.current_observation.display_location.latitude
How do I have to adapt my JSON.lua file to let the program work?
Working on an Asustor NAS and I have adapted the lines so the script can access the file
Tried to load the script but it seems I cannot get the data out of JSON.lua. I have placed next text at top of the file
local localhost = '127.0.0.1:8080' -- Set your port. (Not the universal IP).
local city = "LOKEREN" -- Your city for Wunderground API
local countryCode = "BE" -- Your country code for Wunderground API
local idxLux ='502' -- Your virtual Lux Device ID
local idxSolarAzimuth ='534' -- Your virtual Azimuth Device ID
local idxSolarAltitude ='533' -- Your virtual Solar Altitude Device ID
local idxUserVarOcta='2' -- Your user variable ID , named octa
local wuAPIkey = "f4xxxxxxxxxxxxxx" -- Your Weather Underground API Key
local latitude = '51.0' -- your home
local longitude = 3.9 -- your home
local altitude = 3.0 -- Your home altitude : run once in debug = 1 to found your altitude in Log and write it here
local WMOID = '06431' -- Your nearest SYNOP Station for ogimet. Very important !
local DEBUG = 1
but getting the feedback Error: EventSystem: in Lux_Lua: [string " --[[ Virtual Lux sensor and other re..."]:70: attempt to index field 'current_observation' (a nil value) for the line 70: local latitude = jsonLocation.current_observation.display_location.latitude
How do I have to adapt my JSON.lua file to let the program work?
Working on an Asustor NAS and I have adapted the lines so the script can access the file
- jvdz
- Posts: 2189
- Joined: Tuesday 30 December 2014 19:25
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 4.107
- Location: Netherlands
- Contact:
Re: Real-time solar data : azimuth, Altitude, Lux sensor...
sounds a lot like an earlier report in this thread... did you check it and the subsequent answers?
http://www.domoticz.com/forum/viewtopic ... 077#p71185
Jos
http://www.domoticz.com/forum/viewtopic ... 077#p71185
Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
-
- Posts: 41
- Joined: Thursday 14 July 2016 20:49
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Real-time solar data : azimuth, Altitude, Lux sensor...
I have finally got it almost to work, but I get an error.
2017-11-17 22:20:00.788 Error: EventSystem: in /home/pi/domoticz/scripts/lua/script_time_SolarSensor.lua: /home/pi/domoticz/scripts/lua/script_time_SolarSensor.lua:199: attempt to perform arithmetic on a nil value
And I have no clue att all why I get this. Anyone who could help me with this?
2017-11-17 22:20:00.788 Error: EventSystem: in /home/pi/domoticz/scripts/lua/script_time_SolarSensor.lua: /home/pi/domoticz/scripts/lua/script_time_SolarSensor.lua:199: attempt to perform arithmetic on a nil value
And I have no clue att all why I get this. Anyone who could help me with this?
- jvdz
- Posts: 2189
- Joined: Tuesday 30 December 2014 19:25
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 4.107
- Location: Netherlands
- Contact:
Re: Real-time solar data : azimuth, Altitude, Lux sensor...
I would need to see your exact script to assist.
Jos
Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
-
- Posts: 41
- Joined: Thursday 14 July 2016 20:49
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Real-time solar data : azimuth, Altitude, Lux sensor...
-- Variables to customize ------------------------------------------------
local localhost = '127.0.0.1:1881' -- Set your port. (Not the universal IP).
local city = "Falkenberg" -- Your city for Wunderground API
local countryCode = "SN" -- Your country code for Wunderground API
local idxLux ='282' -- Your virtual Lux Device ID
local idxSolarAzimuth ='279' -- Your virtual Azimuth Device ID
local idxSolarAltitude ='280' -- Your virtual Solar Altitude Device ID
local idxUserVarOcta='1' -- Your user variable ID , named octa
local wuAPIkey = "46922dddab4cd962" -- Your Weather Underground API Key
local latitude = 56.902733 -- your home
local longitude = 12.488801 -- your home
local altitude = 1 -- Your home altitude : run once in debug = 1 to found your altitude in Log and write it here
local WMOID = '02539' -- Your nearest SYNOP Station for ogimet. Very important !
local DEBUG = 1 -- 0 , 1 for domoticz log , 2 for file log
-- Below , edit at your own risk ------------------------------------------
function leapYear(year)
return year%4==0 and (year%100~=0 or year%400==0)
end
function split(s, delimiter)
result = {};
for match in (s..delimiter):gmatch("(.-)"..delimiter) do
table.insert(result, match);
end
return result;
end
function round(num, dec)
if num == 0 then
return 0
else
local mult = 10^(dec or 0)
return math.floor(num * mult + 0.5) / mult
end
end
commandArray = {}
time = os.date("*t")
if ((time.min % 5)==0) then -- Run every 5 minutes. Check the wundergroud API limitation before changing this
json = (loadfile "/home/pi/domoticz/scripts/lua/JSON.lua")() -- For Linux
local arbitraryTwilightLux=6.32 -- W/m² egal 800 Lux (the theoritical value is 4.74 but I have more accurate result with 6.32...)
local constantSolarRadiation = 1361 -- Solar Constant W/m²
if (uservariables['octa'] == nil) then print("Error : Did you create the Uservariable octa ?") end
-- API Wunderground
local config=assert(io.popen('curl http://api.wunderground.com/api/46922dd ... nberg.json'))
local location = config:read('*all')
config:close()
local jsonLocation = json:decode(location)
if( DEBUG == 1) then
local latitude = jsonLocation.current_observation.display_location.latitude
local longitude = jsonLocation.current_observation.display_location.longitude
local altitude = jsonLocation.current_observation.display_location.elevation
print('Lat: '..latitude..'Long: '..longitude..'Alt: '..altitude)
end
relativePressure = jsonLocation.current_observation.pressure_mb -- if you have an another way to get the Pressure, (local barometer ...) then you may optimize the script and avoid the call to api.wunderground)
----------------------------------
local year = os.date("%Y")
local numOfDay = os.date("%j")
if leapYear(year) == true then
nbDaysInYear = 366 -- How many days in the year ?
else
nbDaysInYear = 365
end
angularSpeed = 360/365.25
local Declinaison = math.deg(math.asin(0.3978 * math.sin(math.rad(angularSpeed) *(numOfDay - (81 - 2 * math.sin((math.rad(angularSpeed) * (numOfDay - 2))))))))
timeDecimal = (os.date("!%H") + os.date("!%M") / 60) -- Coordinated Universal Time (UTC)
solarHour = timeDecimal + (4 * longitude / 60 ) -- The solar Hour
hourlyAngle = 15 * ( 12 - solarHour ) -- hourly Angle of the sun
sunAltitude = math.deg(math.asin(math.sin(math.rad(latitude))* math.sin(math.rad(Declinaison)) + math.cos(math.rad(latitude)) * math.cos(math.rad(Declinaison)) * math.cos(math.rad(hourlyAngle))))-- the height of the sun in degree, compared with the horizon
local azimuth = math.acos((math.sin(math.rad(Declinaison)) - math.sin(math.rad(latitude)) * math.sin(math.rad(sunAltitude))) / (math.cos(math.rad(latitude)) * math.cos(math.rad(sunAltitude) ))) * 180 / math.pi -- deviation of the sun from the North, in degree
local sinAzimuth = (math.cos(math.rad(Declinaison)) * math.sin(math.rad(hourlyAngle))) / math.cos(math.rad(sunAltitude))
if(sinAzimuth<0) then azimuth=360-azimuth end
sunstrokeDuration = math.deg(2/15 * math.acos(- math.tan(math.rad(latitude)) * math.tan(math.rad(Declinaison)))) -- duration of sunstroke in the day . Not used in this calculation.
RadiationAtm = constantSolarRadiation * (1 +0.034 * math.cos( math.rad( 360 * numOfDay / nbDaysInYear ))) -- Sun radiation (in W/m²) in the entrance of atmosphere.
-- Coefficient of mitigation M
absolutePressure = relativePressure - round((altitude/ 8.3),1) -- hPa
sinusSunAltitude = math.sin(math.rad(sunAltitude))
M0 = math.sqrt(1229 + math.pow(614 * sinusSunAltitude,2)) - 614 * sinusSunAltitude
M = M0 * relativePressure/absolutePressure
if (DEBUG == 1) then
print('<b style="color:Blue"============== SUN LOG ==================</b>')
print(os.date("%Y-%m-%d %H:%M:%S", os.time()))
print(city .. ", latitude:" .. latitude .. ", longitude:" .. longitude)
print("Home altitude = " .. tostring(altitude) .. " m")
print("number Of Day = " .. numOfDay)
if nbDaysInYear==366 then
print(year .." is a leap year !")
else
print(year.." is not a leap year")
end
print("Angular Speed = " .. angularSpeed .. " per day")
print("Declinaison = " .. Declinaison .. "°")
print("Universel Coordinated Time (UTC)".. timeDecimal .." H.dd")
print("Solar Hour ".. solarHour .." H.dd")
print("Altitude of the sun = " .. sunAltitude .. "°")
print("Angular hourly = ".. hourlyAngle .. "°")
print("Azimuth of the sun = " .. azimuth .. "°")
print("Duration of the sunstroke of the day = " .. round(sunstrokeDuration,2) .." H.dd") -- not used
print("Radiation max in atmosphere = " .. round(RadiationAtm,2) .. " W/m²")
print("Local relative pressure = " .. relativePressure .. " hPa")
print("Absolute pressure in atmosphere = " .. absolutePressure .. " hPa")
print("Coefficient of mitigation M = " .. M .." M0:"..M0)
end
-- Get SYNOP message from Ogimet web site
hourUTCminus1 = os.date("!%H")-1
if string.len(hourUTCminus1) == 1 then
hourUTCminus1 = "0" .. hourUTCminus1
end
UTC = os.date("%Y%m%d").. hourUTCminus1.."00" -- os.date("!%M")
if (DEBUG == 1) then
local WMOID = jsonLocation.current_observation.display_location.wmo
end
cmd='curl "http://www.ogimet.com/cgi-bin/getsynop? ... gin='..UTC..'"'
if( DEBUG == 1) then print(cmd) end
local ogimet=assert(io.popen(cmd))
local synop = ogimet:read('*all')
ogimet:close()
if( DEBUG == 1) then print('ogimet:'..synop) end
if string.find(synop,"Status: 500") == nil
then
rslt = split(synop,",")
CodeStation = rslt[1]
rslt = split(synop, " "..CodeStation.. " ")
Trame = string.gsub(rslt[2], "=", "")
Trame = CodeStation .." ".. Trame
rslt = split(Trame, " ")
Octa = string.sub(rslt[3], 1, 1) -- 3rd char is the cloud layer. 0=no cloud , 1-8= cloudy from 1 to 8 max , 9 =Fog , / = no data
if Octa == "/" then -- not defined ? take the previous value
Octa = uservariables['octa']
elseif Octa == "9" then
Octa = 8
end
else
Octa = uservariables['octa']
end
--os.execute('curl "http://127.0.0.1:8081/json.htm?type=com ... ring(Octa)..'"')
commandArray[#commandArray + 1] = {['Variable:octa'] = tostring(Octa)}
Kc=1-0.75*math.pow(Octa/8,3.4) -- Factor of mitigation for the cloud layer
if sunAltitude > 1 then -- Below 1° of Altitude , the formulae reach their limit of precision.
directRadiation = RadiationAtm * math.pow(0.6,M) * sinusSunAltitude
scatteredRadiation = RadiationAtm * (0.271 - 0.294 * math.pow(0.6,M)) * sinusSunAltitude
totalRadiation = scatteredRadiation + directRadiation
Lux = totalRadiation / 0.0079 -- Radiation in Lux. 1 Lux = 0,0079 W/m²
weightedLux = Lux * Kc -- radiation of the Sun with the cloud layer
elseif sunAltitude <= 1 and sunAltitude >= -7 then -- apply theoretical Lux of twilight
directRadiation = 0
scatteredRadiation = 0
arbitraryTwilightLux=arbitraryTwilightLux-(1-sunAltitude)/8*arbitraryTwilightLux
totalRadiation = scatteredRadiation + directRadiation + arbitraryTwilightLux
Lux = totalRadiation / 0.0079 -- Radiation in Lux. 1 Lux = 0,0079 W/m²
weightedLux = Lux * Kc -- radiation of the Sun with the cloud layer
elseif sunAltitude < -7 then -- no management of nautical and astronomical twilight...
directRadiation = 0
scatteredRadiation = 0
totalRadiation = 0
Lux = 0
weightedLux = 0 -- should be around 3,2 Lux for the nautic twilight. Nevertheless.
end
if (DEBUG == 1) then
print("Station SYNOP = " .. WMOID)
print( Octa .. " Octa")
print("Kc = " .. Kc)
print("Direct Radiation = ".. round(directRadiation,2) .." W/m²")
print("Scattered Radiation = ".. round(scatteredRadiation,2) .." W/m²")
print("Total radiation = " .. round(totalRadiation,2) .." W/m²")
print("Total Radiation in lux = ".. round(Lux,2).." Lux")
print("and at last, Total weighted lux = ".. round(weightedLux,2).." Lux")
end
if tonumber(otherdevices_svalues['Lux'])+round(weightedLux,0)>0 -- No update if Lux is already 0. So lastUpdate of the Lux sensor will keep the time when Lux has reached 0. (Kind of timeofday['SunsetInMinutes'])
then
-- commandArray[#commandArray + 1] = {['UpdateDevice'] = idxLux..'|0|'..tostring(round(weightedLux,0))} -- THis form is not recommended. due to limitation of the eventsystem of Domoticz
commandArray[#commandArray + 1]={['OpenURL']="http://"..localhost.."/json.htm?type=command¶m=udevice&idx="..idxLux.."&nvalue=0&svalue="..tostring(round(weightedLux,0)) }
end
-- commandArray[#commandArray + 1] = {['UpdateDevice'] = idxSolarAzimuth..'|0|'..tostring(round(azimuth,0))}
commandArray[#commandArray + 1]={['OpenURL']="http://"..localhost.."/json.htm?type=command¶m=udevice&idx="..idxSolarAzimuth.."&nvalue=0&svalue="..tostring(round(azimuth,0)) }
-- commandArray[#commandArray + 1] = {['UpdateDevice'] = idxSolarAltitude..'|0|'..tostring(round(sunAltitude,0))}
commandArray[#commandArray + 1]={['OpenURL']="http://"..localhost.."/json.htm?type=command¶m=udevice&idx="..idxSolarAltitude.."&nvalue=0&svalue="..tostring(round(sunAltitude,0)) }
if (DEBUG == 2) then
logDebug=os.date("%Y-%m-%d %H:%M:%S",os.time())
logDebug=logDebug.." Azimuth:" .. azimuth .. " Height:" .. sunAltitude
logDebug=logDebug.." Octa:" .. Octa.." KC:".. Kc
logDebug=logDebug.." Direct:"..directRadiation.." inDirect:"..scatteredRadiation.." TotalRadiation:"..totalRadiation.." LuxCloud:".. round(weightedLux,2)
os.execute('echo '..logDebug..' >>logSun.txt') -- compatible Linux & Windows
end
end
return commandArray
local localhost = '127.0.0.1:1881' -- Set your port. (Not the universal IP).
local city = "Falkenberg" -- Your city for Wunderground API
local countryCode = "SN" -- Your country code for Wunderground API
local idxLux ='282' -- Your virtual Lux Device ID
local idxSolarAzimuth ='279' -- Your virtual Azimuth Device ID
local idxSolarAltitude ='280' -- Your virtual Solar Altitude Device ID
local idxUserVarOcta='1' -- Your user variable ID , named octa
local wuAPIkey = "46922dddab4cd962" -- Your Weather Underground API Key
local latitude = 56.902733 -- your home
local longitude = 12.488801 -- your home
local altitude = 1 -- Your home altitude : run once in debug = 1 to found your altitude in Log and write it here
local WMOID = '02539' -- Your nearest SYNOP Station for ogimet. Very important !
local DEBUG = 1 -- 0 , 1 for domoticz log , 2 for file log
-- Below , edit at your own risk ------------------------------------------
function leapYear(year)
return year%4==0 and (year%100~=0 or year%400==0)
end
function split(s, delimiter)
result = {};
for match in (s..delimiter):gmatch("(.-)"..delimiter) do
table.insert(result, match);
end
return result;
end
function round(num, dec)
if num == 0 then
return 0
else
local mult = 10^(dec or 0)
return math.floor(num * mult + 0.5) / mult
end
end
commandArray = {}
time = os.date("*t")
if ((time.min % 5)==0) then -- Run every 5 minutes. Check the wundergroud API limitation before changing this
json = (loadfile "/home/pi/domoticz/scripts/lua/JSON.lua")() -- For Linux
local arbitraryTwilightLux=6.32 -- W/m² egal 800 Lux (the theoritical value is 4.74 but I have more accurate result with 6.32...)
local constantSolarRadiation = 1361 -- Solar Constant W/m²
if (uservariables['octa'] == nil) then print("Error : Did you create the Uservariable octa ?") end
-- API Wunderground
local config=assert(io.popen('curl http://api.wunderground.com/api/46922dd ... nberg.json'))
local location = config:read('*all')
config:close()
local jsonLocation = json:decode(location)
if( DEBUG == 1) then
local latitude = jsonLocation.current_observation.display_location.latitude
local longitude = jsonLocation.current_observation.display_location.longitude
local altitude = jsonLocation.current_observation.display_location.elevation
print('Lat: '..latitude..'Long: '..longitude..'Alt: '..altitude)
end
relativePressure = jsonLocation.current_observation.pressure_mb -- if you have an another way to get the Pressure, (local barometer ...) then you may optimize the script and avoid the call to api.wunderground)
----------------------------------
local year = os.date("%Y")
local numOfDay = os.date("%j")
if leapYear(year) == true then
nbDaysInYear = 366 -- How many days in the year ?
else
nbDaysInYear = 365
end
angularSpeed = 360/365.25
local Declinaison = math.deg(math.asin(0.3978 * math.sin(math.rad(angularSpeed) *(numOfDay - (81 - 2 * math.sin((math.rad(angularSpeed) * (numOfDay - 2))))))))
timeDecimal = (os.date("!%H") + os.date("!%M") / 60) -- Coordinated Universal Time (UTC)
solarHour = timeDecimal + (4 * longitude / 60 ) -- The solar Hour
hourlyAngle = 15 * ( 12 - solarHour ) -- hourly Angle of the sun
sunAltitude = math.deg(math.asin(math.sin(math.rad(latitude))* math.sin(math.rad(Declinaison)) + math.cos(math.rad(latitude)) * math.cos(math.rad(Declinaison)) * math.cos(math.rad(hourlyAngle))))-- the height of the sun in degree, compared with the horizon
local azimuth = math.acos((math.sin(math.rad(Declinaison)) - math.sin(math.rad(latitude)) * math.sin(math.rad(sunAltitude))) / (math.cos(math.rad(latitude)) * math.cos(math.rad(sunAltitude) ))) * 180 / math.pi -- deviation of the sun from the North, in degree
local sinAzimuth = (math.cos(math.rad(Declinaison)) * math.sin(math.rad(hourlyAngle))) / math.cos(math.rad(sunAltitude))
if(sinAzimuth<0) then azimuth=360-azimuth end
sunstrokeDuration = math.deg(2/15 * math.acos(- math.tan(math.rad(latitude)) * math.tan(math.rad(Declinaison)))) -- duration of sunstroke in the day . Not used in this calculation.
RadiationAtm = constantSolarRadiation * (1 +0.034 * math.cos( math.rad( 360 * numOfDay / nbDaysInYear ))) -- Sun radiation (in W/m²) in the entrance of atmosphere.
-- Coefficient of mitigation M
absolutePressure = relativePressure - round((altitude/ 8.3),1) -- hPa
sinusSunAltitude = math.sin(math.rad(sunAltitude))
M0 = math.sqrt(1229 + math.pow(614 * sinusSunAltitude,2)) - 614 * sinusSunAltitude
M = M0 * relativePressure/absolutePressure
if (DEBUG == 1) then
print('<b style="color:Blue"============== SUN LOG ==================</b>')
print(os.date("%Y-%m-%d %H:%M:%S", os.time()))
print(city .. ", latitude:" .. latitude .. ", longitude:" .. longitude)
print("Home altitude = " .. tostring(altitude) .. " m")
print("number Of Day = " .. numOfDay)
if nbDaysInYear==366 then
print(year .." is a leap year !")
else
print(year.." is not a leap year")
end
print("Angular Speed = " .. angularSpeed .. " per day")
print("Declinaison = " .. Declinaison .. "°")
print("Universel Coordinated Time (UTC)".. timeDecimal .." H.dd")
print("Solar Hour ".. solarHour .." H.dd")
print("Altitude of the sun = " .. sunAltitude .. "°")
print("Angular hourly = ".. hourlyAngle .. "°")
print("Azimuth of the sun = " .. azimuth .. "°")
print("Duration of the sunstroke of the day = " .. round(sunstrokeDuration,2) .." H.dd") -- not used
print("Radiation max in atmosphere = " .. round(RadiationAtm,2) .. " W/m²")
print("Local relative pressure = " .. relativePressure .. " hPa")
print("Absolute pressure in atmosphere = " .. absolutePressure .. " hPa")
print("Coefficient of mitigation M = " .. M .." M0:"..M0)
end
-- Get SYNOP message from Ogimet web site
hourUTCminus1 = os.date("!%H")-1
if string.len(hourUTCminus1) == 1 then
hourUTCminus1 = "0" .. hourUTCminus1
end
UTC = os.date("%Y%m%d").. hourUTCminus1.."00" -- os.date("!%M")
if (DEBUG == 1) then
local WMOID = jsonLocation.current_observation.display_location.wmo
end
cmd='curl "http://www.ogimet.com/cgi-bin/getsynop? ... gin='..UTC..'"'
if( DEBUG == 1) then print(cmd) end
local ogimet=assert(io.popen(cmd))
local synop = ogimet:read('*all')
ogimet:close()
if( DEBUG == 1) then print('ogimet:'..synop) end
if string.find(synop,"Status: 500") == nil
then
rslt = split(synop,",")
CodeStation = rslt[1]
rslt = split(synop, " "..CodeStation.. " ")
Trame = string.gsub(rslt[2], "=", "")
Trame = CodeStation .." ".. Trame
rslt = split(Trame, " ")
Octa = string.sub(rslt[3], 1, 1) -- 3rd char is the cloud layer. 0=no cloud , 1-8= cloudy from 1 to 8 max , 9 =Fog , / = no data
if Octa == "/" then -- not defined ? take the previous value
Octa = uservariables['octa']
elseif Octa == "9" then
Octa = 8
end
else
Octa = uservariables['octa']
end
--os.execute('curl "http://127.0.0.1:8081/json.htm?type=com ... ring(Octa)..'"')
commandArray[#commandArray + 1] = {['Variable:octa'] = tostring(Octa)}
Kc=1-0.75*math.pow(Octa/8,3.4) -- Factor of mitigation for the cloud layer
if sunAltitude > 1 then -- Below 1° of Altitude , the formulae reach their limit of precision.
directRadiation = RadiationAtm * math.pow(0.6,M) * sinusSunAltitude
scatteredRadiation = RadiationAtm * (0.271 - 0.294 * math.pow(0.6,M)) * sinusSunAltitude
totalRadiation = scatteredRadiation + directRadiation
Lux = totalRadiation / 0.0079 -- Radiation in Lux. 1 Lux = 0,0079 W/m²
weightedLux = Lux * Kc -- radiation of the Sun with the cloud layer
elseif sunAltitude <= 1 and sunAltitude >= -7 then -- apply theoretical Lux of twilight
directRadiation = 0
scatteredRadiation = 0
arbitraryTwilightLux=arbitraryTwilightLux-(1-sunAltitude)/8*arbitraryTwilightLux
totalRadiation = scatteredRadiation + directRadiation + arbitraryTwilightLux
Lux = totalRadiation / 0.0079 -- Radiation in Lux. 1 Lux = 0,0079 W/m²
weightedLux = Lux * Kc -- radiation of the Sun with the cloud layer
elseif sunAltitude < -7 then -- no management of nautical and astronomical twilight...
directRadiation = 0
scatteredRadiation = 0
totalRadiation = 0
Lux = 0
weightedLux = 0 -- should be around 3,2 Lux for the nautic twilight. Nevertheless.
end
if (DEBUG == 1) then
print("Station SYNOP = " .. WMOID)
print( Octa .. " Octa")
print("Kc = " .. Kc)
print("Direct Radiation = ".. round(directRadiation,2) .." W/m²")
print("Scattered Radiation = ".. round(scatteredRadiation,2) .." W/m²")
print("Total radiation = " .. round(totalRadiation,2) .." W/m²")
print("Total Radiation in lux = ".. round(Lux,2).." Lux")
print("and at last, Total weighted lux = ".. round(weightedLux,2).." Lux")
end
if tonumber(otherdevices_svalues['Lux'])+round(weightedLux,0)>0 -- No update if Lux is already 0. So lastUpdate of the Lux sensor will keep the time when Lux has reached 0. (Kind of timeofday['SunsetInMinutes'])
then
-- commandArray[#commandArray + 1] = {['UpdateDevice'] = idxLux..'|0|'..tostring(round(weightedLux,0))} -- THis form is not recommended. due to limitation of the eventsystem of Domoticz
commandArray[#commandArray + 1]={['OpenURL']="http://"..localhost.."/json.htm?type=command¶m=udevice&idx="..idxLux.."&nvalue=0&svalue="..tostring(round(weightedLux,0)) }
end
-- commandArray[#commandArray + 1] = {['UpdateDevice'] = idxSolarAzimuth..'|0|'..tostring(round(azimuth,0))}
commandArray[#commandArray + 1]={['OpenURL']="http://"..localhost.."/json.htm?type=command¶m=udevice&idx="..idxSolarAzimuth.."&nvalue=0&svalue="..tostring(round(azimuth,0)) }
-- commandArray[#commandArray + 1] = {['UpdateDevice'] = idxSolarAltitude..'|0|'..tostring(round(sunAltitude,0))}
commandArray[#commandArray + 1]={['OpenURL']="http://"..localhost.."/json.htm?type=command¶m=udevice&idx="..idxSolarAltitude.."&nvalue=0&svalue="..tostring(round(sunAltitude,0)) }
if (DEBUG == 2) then
logDebug=os.date("%Y-%m-%d %H:%M:%S",os.time())
logDebug=logDebug.." Azimuth:" .. azimuth .. " Height:" .. sunAltitude
logDebug=logDebug.." Octa:" .. Octa.." KC:".. Kc
logDebug=logDebug.." Direct:"..directRadiation.." inDirect:"..scatteredRadiation.." TotalRadiation:"..totalRadiation.." LuxCloud:".. round(weightedLux,2)
os.execute('echo '..logDebug..' >>logSun.txt') -- compatible Linux & Windows
end
end
return commandArray
-
- Posts: 485
- Joined: Thursday 17 September 2015 10:13
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
Re: Real-time solar data : azimuth, Altitude, Lux sensor...
"Det gaur inte"
Weather Underground uses different country codes than standard ISO. You have selected the correct code for Sweden which is "SN". However that doesn't seem to work very well. If you try "SE" instead, it will work.
Try this URL for testing (Put your personal key into it first):
Code: Select all
http://api.wunderground.com/api/PUT-YOUR-KEY-HERE/conditions/q/SE/Falkenberg.json
-
- Posts: 41
- Joined: Thursday 14 July 2016 20:49
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Real-time solar data : azimuth, Altitude, Lux sensor...
"De gaur inte heller, huar ett inte var de kan va pönött."
It didn't do the trick. Still same error.
The key is updated with a new, by the way.
It didn't do the trick. Still same error.
The key is updated with a new, by the way.
-
- Posts: 41
- Joined: Thursday 14 July 2016 20:49
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Real-time solar data : azimuth, Altitude, Lux sensor...
Now I got it working. Did read in an eralier post that there something wrong with the script
So I replaced this: if tonumber(otherdevices_svalues['Lux'])+round(weightedLux,0)>0
with this: if tonumber(otherdevices_svalues['Lux']) ~= round(weightedLux,0)
then it was up and running.
So I replaced this: if tonumber(otherdevices_svalues['Lux'])+round(weightedLux,0)>0
with this: if tonumber(otherdevices_svalues['Lux']) ~= round(weightedLux,0)
then it was up and running.
-
- Posts: 65
- Joined: Monday 21 August 2017 19:52
- Target OS: Windows
- Domoticz version: 3.8153
- Location: Rhoon
- Contact:
Re: Real-time solar data : azimuth, Altitude, Lux sensor...
I've stopped the script from running because of the bugs in the beta software last month, but that seems fixed now. So I started the script again and now I get the following error:
Anyone else with the same problem or with a solution?
Code: Select all
Lua script Real time weather data did not return a commandArray
-
- Posts: 667
- Joined: Wednesday 08 March 2017 9:42
- Target OS: Linux
- Domoticz version: 3.8993
- Location: Amsterdam
- Contact:
Re: Real-time solar data : azimuth, Altitude, Lux sensor...
His All,
Is there a alternative link for: http://www.ogimet.com
I get every day some errors:
Cheers,
Is there a alternative link for: http://www.ogimet.com
I get every day some errors:
Code: Select all
2018-02-20 01:20:05.463 Error: Error opening url: http://www.ogimet.com/cgi-bin/getsynop?block=06240&begin=201802192301
2018-02-20 03:20:05.663 Error: Error opening url: http://www.ogimet.com/cgi-bin/getsynop?block=06240&begin=201802200101
2018-02-20 05:20:05.376 Error: Error opening url: http://www.ogimet.com/cgi-bin/getsynop?block=06240&begin=201802200301
RPi3 B+, Debain Stretch, Domoticz, Homebridge, Dashticz, RFLink, Milight, Z-Wave, Fibaro, Nanoleaf, Nest, Harmony Hub, Now try to understand pass2php
Who is online
Users browsing this forum: No registered users and 0 guests