Real-time solar data : azimuth, Altitude, Lux sensor... [closed]

Moderator: leecollings

Locked
User avatar
Egregius
Posts: 2592
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Real-time solar data : azimuth, Altitude, Lux sensor...

Post by Egregius »

Is wunderground pretty accurate and reliable?
Openweathermap isn't. I get readings like 18.6°, one minute later 19.2, then again 18.6, again 19.2,...
During daytime I now use forecast.io but the number of request is limited to 1000 per day for a free account.
trixwood

Re: Real-time solar data : azimuth, Altitude, Lux sensor...

Post by trixwood »

I was looking at cloud sensors... this popped up:

http://www.noao.edu/staff/gillespie/pro ... ector.html

could it work?

it looks like all it is, is this sensor https://www.adafruit.com/product/1330 sandwiched between two aluminium plates.
And then measure and mapping out the voltages to actually readings.
User avatar
Egregius
Posts: 2592
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Real-time solar data : azimuth, Altitude, Lux sensor...

Post by Egregius »

You also have cloud prediction at forecast.io and openweathermap.
trixwood

Re: Real-time solar data : azimuth, Altitude, Lux sensor...

Post by trixwood »

Not everybody have a working internet connection on the location they run their stuff... :?

http://www.farnham-as.co.uk/2013/04/bui ... ud-sensor/
http://downloads.deusm.com/designnews/2 ... ctions.pdf

Going to build this one:
http://www.chrisramsay.co.uk/posts/2014 ... -part-one/
Derik
Posts: 1602
Joined: Friday 18 October 2013 23:33
Target OS: Raspberry Pi / ODroid
Domoticz version: BETA
Location: Arnhem/Nijmegen Nederland
Contact:

Re: Real-time solar data : azimuth, Altitude, Lux sensor...

Post by Derik »

still something alive..

Code: Select all

 2016-08-21 19:05:01.317 LUA: Lat: 56.84249878Long: 5.85277796Alt: 22.00000000[/quote]
What do i need to do with data?
Fill in  22.00000000

Sensor still red..

Only my api [ i reset him] is counting..:
Where can i search ...
[attachment=0]ScreenShot210.jpg[/attachment]
Attachments
ScreenShot210.jpg
ScreenShot210.jpg (4.52 KiB) Viewed 3901 times
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
trixwood

Re: Real-time solar data : azimuth, Altitude, Lux sensor...

Post by trixwood »

you can look up the long, lat and altitude here, I think: http://elevationmap.net
Derik
Posts: 1602
Joined: Friday 18 October 2013 23:33
Target OS: Raspberry Pi / ODroid
Domoticz version: BETA
Location: Arnhem/Nijmegen Nederland
Contact:

Re: Real-time solar data : azimuth, Altitude, Lux sensor...

Post by Derik »

trixwood wrote:From the original wiki

Code: Select all

  --  API Wunderground
       local config=assert(io.popen('curl http://api.wunderground.com/api/'..wuAPIkey..'/conditions/q/'..countryCode..'/'..city..'.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)
  
without weathe underground you need to repalce that with:

Code: Select all

relativePressure = 1012
or read it from a pressure sensor...

That yould fix your nil... now I am also stuck on the cloud coverage not coming in.... :-)
How can i read it from a pressure sensor?
And where and How to fill in?
ScreenShot211.jpg
ScreenShot211.jpg (112.85 KiB) Viewed 3892 times
When i got this script working i going to drink a very large BEER...
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
trixwood

Re: Real-time solar data : azimuth, Altitude, Lux sensor...

Post by trixwood »

Code: Select all

    --[[      Virtual Lux sensor and other real-time solar data
 
    ~/domoticz/scripts/lua/script_time_SolarSensor.lua
 
    -- Autors  ----------------------------------------------------------------
    V1.0 - Sébastien Joly - Great original work
    V1.1 - Neutrino - Adaptation to Domoticz
    V1.2 - Jmleglise - An acceptable approximation of the lux below 1° altitude for Dawn and dusk + translation + several changes to be more userfriendly.
    V1.3 - Jmleglise - keep the time of black night in lasptUpdate
    ]]--
 
    -- Variables to customize ------------------------------------------------
       local city = "Paris"            -- Your city for Wunderground API
       local countryCode = "FR"            -- Your country code for Wunderground API
       local idxLux ='72'            -- Your virtual Lux Device ID
       local idxSolarAzimuth ='85'       -- Your virtual Azimuth Device ID
       local idxSolarAltitude ='84'       -- Your virtual Solar Altitude Device ID
       local idxUserVarOcta='2'           -- Your user variable ID , named octa
       local wuAPIkey = "xxxxxxxxe5db6e4c" -- Your Weather Underground API Key
       local latitude = 48.xxxx88        -- your home
       local longitude = 2.xxxx00       -- your home
       local altitude = 27              -- Your home altitude : run once in debug = 1 to found your altitude in Log and write it here
       local WMOID = '07145'    -- Your nearest SYNOP Station for ogimet (to get Cloud layer). Run once with debug=1 to get it in the log. (or, better, choose it there : http://www.ogimet.com/gsynop_nav.phtml.en )
       local DEBUG = 0             -- 0 , 1 for domoticz log , 2 for file log
       -- and customize the URL of api.wunderground around line 104 according to your country.
 
    -- 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
       --json = (loadfile "D:\\Domoticz\\scripts\\lua\\json.lua")()  -- For Windows
 
       local indexArray=0
       local arbitraryTwilightLux=4.74     -- W/m²  egal 600 Lux
       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/'..wuAPIkey..'/conditions/q/'..countryCode..'/'..city..'.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 en 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?block='..WMOID..'&begin='..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
       --commandArray['Variable:octa']=tostring(Octa)  -- store the  octa variable
       --os.execute('curl "http://127.0.0.1:8081/json.htm?type=command&param=updateuservariable&idx='..idxUserVarOcta..'&vname=octa&vtype=0&vvalue='..tostring(Octa)..'"')
       commandArray[indexArray] = {['Variable:octa'] = tostring(Octa)}
       indexArray=indexArray+1
 
       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 >= -6  then -- apply theoretical Lux of twilight
          directRadiation = 0
          scatteredRadiation = 0
          arbitraryTwilightLux=arbitraryTwilightLux-(1-sunAltitude)/7*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 < -6 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
       -- cmd='curl "http://127.0.0.1:8081/json.htm?type=command&param=udevice&idx='..idxLux..'&svalue='..tostring(round(weightedLux,0))..'"'
       -- if( DEBUG == 1) then print(cmd) end
       -- os.execute(cmd)
 
	if tonumber(otherdevices_svalues['Lux'])+round(weightedLux,0)>0   -- No update if Lux is already 0. So lastUpdate of the sensor switch will keep the time of day when Lux has reached 0. (Kind of timeofday['SunsetInMinutes'])
	then
		commandArray[indexArray] = {['UpdateDevice'] = idxLux..'|0|'..tostring(round(weightedLux,0))}
		indexArray=indexArray+1
	end
       commandArray[indexArray] = {['UpdateDevice'] = idxSolarAzimuth..'|0|'..tostring(round(azimuth,0))} 
       indexArray=indexArray+1
       commandArray[indexArray] = {['UpdateDevice'] = idxSolarAltitude..'|0|'..tostring(round(sunAltitude,0))}
       indexArray=indexArray+1
 
       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')  -- Windows platform !!
       end
    end
    return commandArray
currently on wiki...

which you need to fill in:

Code: Select all

    -- Variables to customize ------------------------------------------------
       local city = "Paris"            -- Your city
       local countryCode = "FR"            -- Your country code for Wunderground API
       local idxLux ='72'            -- Your virtual Lux Device ID
       local idxSolarAzimuth ='85'       -- Your virtual Azimuth Device ID
       local idxSolarAltitude ='84'       -- Your virtual Solar Altitude Device ID
       local idxUserVarOcta='2'           -- Your user variable ID , named octa
       local wuAPIkey = "xxxxxxxxe5db6e4c" -- Your Weather Underground API Key
       local latitude = 48.xxxx88        -- your home   
       local longitude = 2.xxxx00       -- your home
       local altitude = 35              -- Your home altitude : run once in debug = 1 to found your altitude in Log and write it here
       local WMOID = '07145'    -- Your nearest SYNOP Station for ogimet (to get Cloud layer). Run once with debug=1 to get it in the log. (or, better, choose it there : http://www.ogimet.com/gsynop_nav.phtml.en )
       local DEBUG = 1             -- 0 , 1 for domoticz log , 2 for file log
       -- and customize the URL of api.wunderground around line 104 according to your country.

Code: Select all

      local latitude = 48.xxxx88        -- your home   
       local longitude = 2.xxxx00       -- your home
       local altitude = 35              -- Your home altitude : run once in debug = 1 to found your altitude in Log and write it here
look up and fill in the value's from http://elevationmap.net

without weather underground:

replace

Code: Select all

  --  API Wunderground
       local config=assert(io.popen('curl http://api.wunderground.com/api/'..wuAPIkey..'/conditions/q/'..countryCode..'/'..city..'.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)
with

Code: Select all

relativePressure = 1012
or, i think that will work...

Code: Select all

relativePressure = tonumber(otherdevices_svalues['YourPressureSensor']) 
that's how far I got, still, do not have it running...

and at least change:

Code: Select all

if  ((time.min % 5)==0) 
into one minute waiting, we do not use weatherundergroudn.. and waiting 5 minutes is too long for test/debug purpuse...

Code: Select all

if  ((time.min % 1)==0) 
Derik
Posts: 1602
Joined: Friday 18 October 2013 23:33
Target OS: Raspberry Pi / ODroid
Domoticz version: BETA
Location: Arnhem/Nijmegen Nederland
Contact:

Re: Real-time solar data : azimuth, Altitude, Lux sensor...

Post by Derik »

I throw the towel .. :oops: :oops:
If someone has him working and wants to help me .. :idea: :D

All day... :cry: :roll:
And not going ... :-(

Hope Trixwood helps. ... [ love you xxx ]
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
Derik
Posts: 1602
Joined: Friday 18 October 2013 23:33
Target OS: Raspberry Pi / ODroid
Domoticz version: BETA
Location: Arnhem/Nijmegen Nederland
Contact:

Re: Real-time solar data : azimuth, Altitude, Lux sensor...

Post by Derik »

Perhaps i have a linaro user instead of pi?
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
trixwood

Re: Real-time solar data : azimuth, Altitude, Lux sensor...

Post by trixwood »

Well it crashed for me on:

Code: Select all

       -- if (DEBUG == 1) then
          --local WMOID = jsonLocation.current_observation.display_location.wmo
       -- end
so i commented that out...

My lux sensor is called "Sun Lux", so change 'Lux' into the name you have chosen yourself.(around line 190)... since it does not use the defaults idx but a name...

Code: Select all

	if tonumber(otherdevices_svalues['Lux'])+round(weightedLux,0)>0 
-- No update if Lux is already 0. So lastUpdate of the sensor switch will keep the time of day when Lux has reached 0. (Kind of timeofday['SunsetInMinutes'])
- So to get it working... setup the virtual sensors
- use a time lua event with the wiki code...
- Fill in the default value (idx, long, lat, etc... put debug=1 to see nice values in log for testing..)
- Use to look up Station ID in the netherlands:

http://www.ogimet.com/cgi-bin/gsynop?la ... =18&vsg=Sg

You could use 06260
- Remove weatherundergroudn api, and use a pressure sensor of domoticz***
- Remove the jsonLocation thing code line... (whatever it is...)
- Change the name "Lux", to your sensor name around line 190 (somebody should fix this... it leads to confusing...)

*** (much beter solution anyway, if you are going to use weatherunderground then do it through domoticz hardware and read that value from there...)

and whalla!

Code: Select all

2016-08-21 21:02:00.553 LUA: Azimuth of the sun = 293.47327387855°
2016-08-21 21:02:00.553 LUA: Duration of the sunstroke of the day = 14.05 H.dd
2016-08-21 21:02:00.553 LUA: Radiation max en atmosphere = 1331.36 W/m²
2016-08-21 21:02:00.553 LUA: Local relative pressure = 1012 hPa
2016-08-21 21:02:00.553 LUA: Absolute pressure in atmosphere = 1011.4 hPa
2016-08-21 21:02:00.553 LUA: Coefficient of mitigation M = 80.973898320526 M0:80.925890080415
2016-08-21 21:02:00.553 LUA: curl "http://www.ogimet.com/cgi-bin/getsynop?block=07145&begin=201608211800"
2016-08-21 21:02:01.616 LUA: ogimet:07145,2016,08,21,18,00,AAXX 21184 07145 01775 12703 10208 20088 30036 40240 53009 69962 70186 81101 333 10214 20136 60007 81850 90710 91116 93100 555 60005=
2016-08-21 21:02:01.616 LUA: Station SYNOP = 07145
2016-08-21 21:02:01.616 LUA: 1 Octa
2016-08-21 21:02:01.616 LUA: Kc = 0.99936238972415
2016-08-21 21:02:01.616 LUA: Direct Radiation = 0 W/m²
2016-08-21 21:02:01.616 LUA: Scattered Radiation = 0 W/m²
2016-08-21 21:02:01.616 LUA: Total radiation = 1.98 W/m²
2016-08-21 21:02:01.616 LUA: Total Radiation in lux = 251.25 Lux
2016-08-21 21:02:01.616 LUA: and at last, Total weighted lux = 251.09 Lux
That would work... on a time event...
Derik
Posts: 1602
Joined: Friday 18 October 2013 23:33
Target OS: Raspberry Pi / ODroid
Domoticz version: BETA
Location: Arnhem/Nijmegen Nederland
Contact:

Re: Real-time solar data : azimuth, Altitude, Lux sensor...

Post by Derik »

mmm
Your are FU^*^*ing good.....
Only... you are going to fast for me..

Please your code here??
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
trixwood

Re: Real-time solar data : azimuth, Altitude, Lux sensor...

Post by trixwood »

Look for the: VERANDER HIER what you need to change... (throughout the code, thus also at the end of the code :-)
If your sensors are correct and you make it a time,event... it updates every minutes...

Code: Select all

 --[[      Virtual Lux sensor and other real-time solar data
 
    ~/domoticz/scripts/lua/script_time_SolarSensor.lua
 
    -- Autors  ----------------------------------------------------------------
    V1.0 - Sébastien Joly - Great original work
    V1.1 - Neutrino - Adaptation to Domoticz
    V1.2 - Jmleglise - An acceptable approximation of the lux below 1° altitude for Dawn and dusk + translation + several changes to be more userfriendly.
    V1.3 - Jmleglise - keep the time of black night in lasptUpdate
    ]]--
 
    -- Variables to customize ------------------------------------------------
       local city = "Somewhere"            -- Your city for Wunderground API
      -- local countryCode = "FR"            -- Your country code for Wunderground API
      
      
    --- ******************
      -- VERANDER HIER!!!
    --- ******************
    --  de idx van de sensors en uservariable..      
       local idxLux ='450'            -- Your virtual Lux Device ID
       local idxSolarAzimuth ='451'       -- Your virtual Azimuth Device ID
       local idxSolarAltitude ='452'       -- Your virtual Solar Altitude Device ID
       local idxUserVarOcta='2'           -- Your user variable ID , named octa
     --  local wuAPIkey = "xxxxxxxxe5db6e4c" -- Your Weather Underground API Key

    --- ******************
    -- VERANDER HIER!!! ZOEK OP MET http://elevationmap.net
    --- ******************
       local latitude = 55.934321      -- your home
       local longitude = 4.206940       -- your home
       local altitude = 5              -- Your home altitude : run once in debug = 1 to found your altitude in Log and write it here
   
    --- ******************
    --- ZOEK OP MET http://www.ogimet.com/cgi-bin/gsynop?lang=en&esc=2&nav=Yes&lat=50N&lon=005E&proy=orto&base=bluem&ano=2016&mes=08&day=21hora=18&vsg=Sg
    --- ******************
    
       local WMOID = '06260'  --De Bilt: '06260'    -- Your nearest SYNOP Station for ogimet (to get Cloud layer). Run once with debug=1 to get it in the log. (or, better, choose it there : http://www.ogimet.com/gsynop_nav.phtml.en )
  
    --- ******************
  
       local DEBUG = 1             -- 0 , 1 for domoticz log , 2 for file log
       -- and customize the URL of api.wunderground around line 104 according to your country.
 
    -- 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 % 1)==0)  then -- Run every 5 minutes. Check the wundergroud API limitation before changing this
 
       local indexArray=0
       local arbitraryTwilightLux=4.74     -- W/m²  egal 600 Lux
       local constantSolarRadiation = 1361 -- Solar Constant W/m²
 
       if (uservariables['octa'] == nil) then print("Error : Did you create the Uservariable octa ?") end
 
        relativePressure = 1012 
      
      
      
      
     -- ******************
     -- VERANDER HIER!!!  DE Naam van de pressure sensor, uncomment als je die gebruikt..
     -- ******************
 
       -- relativePressure = tonumber(otherdevices_svalues['Pressure SENSOR']) 
       




       
       ----------------------------------
       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 en 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?block='..WMOID..'&begin='..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
       --commandArray['Variable:octa']=tostring(Octa)  -- store the  octa variable
       --os.execute('curl "http://127.0.0.1:8081/json.htm?type=command&param=updateuservariable&idx='..idxUserVarOcta..'&vname=octa&vtype=0&vvalue='..tostring(Octa)..'"')
       commandArray[indexArray] = {['Variable:octa'] = tostring(Octa)}
       indexArray=indexArray+1
 
       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 >= -6  then -- apply theoretical Lux of twilight
          directRadiation = 0
          scatteredRadiation = 0
          arbitraryTwilightLux=arbitraryTwilightLux-(1-sunAltitude)/7*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 < -6 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
       -- cmd='curl "http://127.0.0.1:8081/json.htm?type=command&param=udevice&idx='..idxLux..'&svalue='..tostring(round(weightedLux,0))..'"'
       -- if( DEBUG == 1) then print(cmd) end
       -- os.execute(cmd)




    --- ******************
    -- VERANDER HIER!!!  DE Naam van de Lux sensor
    --- ******************
 
	if tonumber(otherdevices_svalues['Sun Lux'])+round(weightedLux,0)>0   -- No update if Lux is already 0. So lastUpdate of the sensor switch will keep the time of day when Lux has reached 0. (Kind of timeofday['SunsetInMinutes'])
	then
		commandArray[indexArray] = {['UpdateDevice'] = idxLux..'|0|'..tostring(round(weightedLux,0))}
		indexArray=indexArray+1
	end

    --- ******************
    -- VERANDER HIER!!!  KLAAR
    --- ******************




 
       commandArray[indexArray] = {['UpdateDevice'] = idxSolarAzimuth..'|0|'..tostring(round(azimuth,0))} 
       indexArray=indexArray+1
       commandArray[indexArray] = {['UpdateDevice'] = idxSolarAltitude..'|0|'..tostring(round(sunAltitude,0))}
       indexArray=indexArray+1
 
       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')  -- Windows platform !!
       end
    end
    return commandArray

Derik
Posts: 1602
Joined: Friday 18 October 2013 23:33
Target OS: Raspberry Pi / ODroid
Domoticz version: BETA
Location: Arnhem/Nijmegen Nederland
Contact:

Re: Real-time solar data : azimuth, Altitude, Lux sensor...

Post by Derik »

Code: Select all

2016-08-21 21:51:00.940 Error: EventSystem: in /home/linaro/domoticz/scripts/lua/script_time_SolarSensor.lua: .../linaro/domoticz/scripts/lua/script_time_SolarSensor.lua:117: attempt to perform arithmetic on global 'relativePressure' (a nil value)
Still got this error:

This is what i made:

Code: Select all

   -- Variables to customize ------------------------------------------------
       local city = "Nijmegen"            -- Your city for Wunderground API
      -- local countryCode = "FR"            -- Your country code for Wunderground API
      
      
    --- ******************
      -- VERANDER HIER!!!
    --- ******************
    --  de idx van de sensors en uservariable..      
       local idxLux ='4750'            -- Your virtual Lux Device ID
       local idxSolarAzimuth ='4752'       -- Your virtual Azimuth Device ID
       local idxSolarAltitude ='4790'       -- Your virtual Solar Altitude Device ID
       local idxUserVarOcta='2'           -- Your user variable ID , named octa
     --  local wuAPIkey = "xxxxxxxxe5db6e4c" -- Your Weather Underground API Key

    --- ******************
    -- VERANDER HIER!!! ZOEK OP MET http://elevationmap.net
    --- ******************
       local latitude = 59.87957     -- your home
       local longitude =  5.82391      -- your home
       local altitude = 5              -- Your home altitude : run once in debug = 1 to found your altitude in Log and write it here
   
    --- ******************
    --- ZOEK OP MET http://www.ogimet.com/cgi-bin/gsynop?lang=en&esc=2&nav=Yes&lat=50N&lon=005E&proy=orto&base=bluem&ano=2016&mes=08&day=21hora=18&vsg=Sg
    --- ******************
    
       local WMOID = '06725'  --Deelen: '06260'    -- Your nearest SYNOP Station for ogimet (to get Cloud layer). Run once with debug=1 to get it in the log. (or, better, choose it there : http://www.ogimet.com/gsynop_nav.phtml.en )
  
    --- ******************
  
       local DEBUG = 1             -- 0 , 1 for domoticz log , 2 for file log
       -- and customize the URL of api.wunderground around line 104 according to your country.
 
    -- 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 % 1)==0)  then -- Run every 5 minutes. Check the wundergroud API limitation before changing this
 
       local indexArray=0
       local arbitraryTwilightLux=4.74     -- W/m²  egal 600 Lux
       local constantSolarRadiation = 1361 -- Solar Constant W/m²
 
       if (uservariables['octa'] == nil) then print("Error : Did you create the Uservariable octa ?") end
 
       relativePressure = 1012 
      
      
      
      
     -- ******************
     -- VERANDER HIER!!!  DE Naam van de pressure sensor, uncomment als je die gebruikt..
     -- ******************
 
       relativePressure = tonumber(otherdevices_svalues['WuB: Temp']) 
       




       
       ----------------------------------
       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 en 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?block='..WMOID..'&begin='..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
       --commandArray['Variable:octa']=tostring(Octa)  -- store the  octa variable
       --os.execute('curl "http://127.0.0.1:8081/json.htm?type=command&param=updateuservariable&idx='..idxUserVarOcta..'&vname=octa&vtype=0&vvalue='..tostring(Octa)..'"')
       commandArray[indexArray] = {['Variable:octa'] = tostring(Octa)}
       indexArray=indexArray+1
 
       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 >= -6  then -- apply theoretical Lux of twilight
          directRadiation = 0
          scatteredRadiation = 0
          arbitraryTwilightLux=arbitraryTwilightLux-(1-sunAltitude)/7*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 < -6 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
       -- cmd='curl "http://127.0.0.1:8081/json.htm?type=command&param=udevice&idx='..idxLux..'&svalue='..tostring(round(weightedLux,0))..'"'
       -- if( DEBUG == 1) then print(cmd) end
       -- os.execute(cmd)




    --- ******************
    -- VERANDER HIER!!!  DE Naam van de Lux sensor
    --- ******************
 
   if tonumber(otherdevices_svalues['D.M.: Lux'])+round(weightedLux,0)>0   -- No update if Lux is already 0. So lastUpdate of the sensor switch will keep the time of day when Lux has reached 0. (Kind of timeofday['SunsetInMinutes'])
   then
      commandArray[indexArray] = {['UpdateDevice'] = idxLux..'|0|'..tostring(round(weightedLux,0))}
      indexArray=indexArray+1
   end

    --- ******************
    -- VERANDER HIER!!!  KLAAR
    --- ******************
Stil that relative i am not good in math..:-(
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
Derik
Posts: 1602
Joined: Friday 18 October 2013 23:33
Target OS: Raspberry Pi / ODroid
Domoticz version: BETA
Location: Arnhem/Nijmegen Nederland
Contact:

Re: Real-time solar data : azimuth, Altitude, Lux sensor...

Post by Derik »

And Trixwood how did you name the Dummy's..
In the wiki are the names different...
Sun Azimuth or Solar azimuth and D or degrees
Sun altitude or Solar Altitude etc etc etc..
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
trixwood

Re: Real-time solar data : azimuth, Altitude, Lux sensor...

Post by trixwood »

Screen Shot 2016-08-21 at 22.21.32.png
Screen Shot 2016-08-21 at 22.21.32.png (73.69 KiB) Viewed 3849 times
Screen Shot 2016-08-21 at 22.20.50.png
Screen Shot 2016-08-21 at 22.20.50.png (43.5 KiB) Viewed 3849 times
trixwood

Re: Real-time solar data : azimuth, Altitude, Lux sensor...

Post by trixwood »

i just setup weatherunderdround...I gonna find out,
in the mean time does it run with 1012 as relativePressure instead of the sensor...??
Derik
Posts: 1602
Joined: Friday 18 October 2013 23:33
Target OS: Raspberry Pi / ODroid
Domoticz version: BETA
Location: Arnhem/Nijmegen Nederland
Contact:

Re: Real-time solar data : azimuth, Altitude, Lux sensor...

Post by Derik »

Something ALIVE....!!!!!!!
ScreenShot213.jpg
ScreenShot213.jpg (25.03 KiB) Viewed 3842 times

2 -- for my own presure sensor
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
Derik
Posts: 1602
Joined: Friday 18 October 2013 23:33
Target OS: Raspberry Pi / ODroid
Domoticz version: BETA
Location: Arnhem/Nijmegen Nederland
Contact:

Re: Real-time solar data : azimuth, Altitude, Lux sensor...

Post by Derik »

Code: Select all

2016-08-21 22:39:00.833 LUA:
2016-08-21 22:39:00.833 LUA: 2016-08-21 22:39:00
2016-08-21 22:39:00.834 LUA: Nijmegen, latitude:59.87957, longitude:5.82391
2016-08-21 22:39:00.834 LUA: Home altitude = 5 m
2016-08-21 22:39:00.834 LUA: number Of Day = 234
2016-08-21 22:39:00.834 LUA: 2016 is a leap year !
2016-08-21 22:39:00.834 LUA: Angular Speed = 0.98562628336756 per day
2016-08-21 22:39:00.834 LUA: Declinaison = 11.710720522258�
2016-08-21 22:39:00.834 LUA: Universel Coordinated Time (UTC)20.65 H.dd
2016-08-21 22:39:00.834 LUA: Solar Hour 21.038260666667 H.dd
2016-08-21 22:39:00.834 LUA: Altitude of the sun = -15.783463415723�
2016-08-21 22:39:00.834 LUA: Angular hourly = -135.57391�
2016-08-21 22:39:00.834 LUA: Azimuth of the sun = 314.57981118914�
2016-08-21 22:39:00.834 LUA: Duration of the sunstroke of the day = 14.04 H.dd
2016-08-21 22:39:00.834 LUA: Radiation max en atmosphere = 1331.36 W/m�
2016-08-21 22:39:00.834 LUA: Local relative pressure = 1012 hPa
2016-08-21 22:39:00.835 LUA: Absolute pressure in atmosphere = 1011.4 hPa
2016-08-21 22:39:00.835 LUA: Coefficient of mitigation M = 337.85917749437 M0:337.65886572906
2016-08-21 22:39:00.835 LUA: curl "http://www.ogimet.com/cgi-bin/getsynop?block=06725&begin=201608211900"
2016-08-21 22:39:01.053 LUA: ogimet:06725,2016,08,21,19,00,AAXX 21194 06725 23/// /0302 10103 20051 38533 48571 52016 333 55300 20022 60005 91107 91202=
06725,2016,08,21,20,00,AAXX 21204 06725 23/// /1002 10087 20038 38538 48576 53021 333 55300 20004 60005 91107 91203=
2016-08-21 22:39:01.055 LUA: Station SYNOP = 06725
2016-08-21 22:39:01.055 LUA: 0 Octa
2016-08-21 22:39:01.055 LUA: Kc = 1
2016-08-21 22:39:01.055 LUA: Direct Radiation = 0 W/m�
2016-08-21 22:39:01.056 LUA: Scattered Radiation = 0 W/m�
2016-08-21 22:39:01.056 LUA: Total radiation = 0 W/m�
2016-08-21 22:39:01.056 LUA: Total Radiation in lux = 0 Lux
2016-08-21 22:39:01.056 LUA: and at last, Total weighted lux = 0 Lux
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
trixwood

Re: Real-time solar data : azimuth, Altitude, Lux sensor...

Post by trixwood »

Ok, so that works... now for the last part if you use the sensor from Weatherunderground hardware:

instead of:

Code: Select all

   relativePressure = tonumber(otherdevices_svalues['Pressure SENSOR']) 
use:

Code: Select all

      temp, hum, uv, pres = otherdevices_svalues['Weather TempHumBaro']:match("([^;]+);([^;]+);([^;]+);([^;]+)")
      relativePressure = tonumber(pres)
 
Where "Weather TempHumBaro" is the combined temp/humidity/pressure sensor so we have to decode it...
Screen Shot 2016-08-21 at 22.44.56.png
Screen Shot 2016-08-21 at 22.44.56.png (28.2 KiB) Viewed 3840 times
Locked

Who is online

Users browsing this forum: No registered users and 1 guest