Page 8 of 9
Re: dzVents version of the Solar Data Script
Posted: Wednesday 13 March 2019 11:23
by Thugbear
oredin wrote: ↑Wednesday 06 March 2019 17:55
Thugbear wrote: ↑Wednesday 06 March 2019 14:38
...Trimmed my quote...
Hi,
Seems you're using my script and not the one from bramv. I'll check the difference between mine and bramv's to see if there's any difference about the LUX. It could be that i've made an error when I adapted the script with the cloud coverage instead of the okta value.
@jake : You're using the bramv's version of the script, aren't you ?
Hi Oredin, I'm indeed using your script, so perhaps I can also see if it differs. I'll see if i can run bramv next to it and see results. Like right now its at 38k and it is cloudy, rainy and deffi not that high.
Thanks for all the effort and work btw.
Re: dzVents version of the Solar Data Script
Posted: Wednesday 13 March 2019 12:16
by jake
Thugbear wrote:Hi Oredin, I'm indeed using your script, so perhaps I can also see if it differs. I'll see if i can run bramv next to it and see results. Like right now its at 38k and it is cloudy, rainy and deffi not that high.
Thanks for all the effort and work btw.
Under the same conditions I have 40k with the bramv version. Close enough, I guess.
Re: dzVents version of the Solar Data Script
Posted: Wednesday 13 March 2019 13:08
by Thugbear
@jake
OK, I would think it would be lower as that, but I guess that I'm wrong... lets keep an eye out though, as i do feel it is very different from the last time you responded (10k vs 40k).
Might just have to invest in a LUX meter
Re: dzVents version of the Solar Data Script
Posted: Wednesday 13 March 2019 13:29
by jake
Depends on your usage of course. I use it to decide if it is light enough outside, whether or not I should turn on the lights in the Living room in the morning, while the curtains are closed. My inside fibaro sensor thinks it is still dark, but I only need to open the curtains to go beyond this low light level inside..
Re: dzVents version of the Solar Data Script
Posted: Wednesday 13 March 2019 13:50
by Thugbear
True - I'll not be derailing this thread, but I'll have to weigh my own levels. As the levels for outside should trigger different things, and it might have to adjust it in my scripts.
But I'm glad we get this and there is still enough people active with it.
Re: dzVents version of the Solar Data Script
Posted: Sunday 17 March 2019 12:27
by oredin
Hi,
I've compared bramv's calculation and mine. Both are equivalent.
If there's a difference in the results, it could come from the sources of the cloudcover since mine uses DarkSky and Bramv uses a device that can be updated from anything (OpenWeatherMap, for ex.).
As I said earlier in this thread, using the cloucover to compute the Lux value isn't the most accurate method. But since there's no reliable and easy way to get the okta value on Internet, we have to make with the cloudcover
Re: dzVents version of the Solar Data Script
Posted: Monday 25 March 2019 9:07
by Derik
Doe anyone have a complete script as a example include all options..
See multiple scripts only a for a dombo like me in scripts is a example very fine
I do not understand the changes everyone made.
Thanks..
Re: dzVents version of the Solar Data Script
Posted: Friday 29 March 2019 19:55
by gimic
Does somone else have problems with the Weather underground API since 25/03?
i don't get any data anymore. when i paste the url i get the notice that the service has ended... other options?
Re: dzVents version of the Solar Data Script
Posted: Friday 29 March 2019 20:44
by gimic
ok, seen that i've got an outdated version of the script (till V2)
adopting to recent version now without WU..
Re: dzVents version of the Solar Data Script
Posted: Saturday 30 March 2019 18:45
by Derik
bramv wrote: ↑Saturday 08 December 2018 20:17
Sorry raptile. I can't reply to your p.m. yet because I'm too new on the forum.
Here is my version of the script so you can use the openweahtermaps and your own sensors.
I use the cloud information from the open wheathermaps and the baro pressure from my zigbee sensor.
Code: Select all
--[[
Prerequisits
==================================
Requires Domoticz v3.8551 or later
Platform dependent, requires Linux
CHANGE LOG: See http://www.domoticz.com/forum/viewtopic.php?t=19220
Virtual Lux sensor and other real-time solar data
-- Authors ----------------------------------------------------------------
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 - No update of the Lux data when <=0 to get the sunset and sunrise with lastUpdate
V1.4 - use the API instead of updateDevice to update the data of the virtual sensor to be able of using devicechanged['Lux'] in our scripts. (Due to a bug in Domoticz that doesn't catch the devicechanged event of the virtual sensor)
V1.5 - xces - UTC time calculation.
V2.0 - BakSeeDaa - Converted to dzVents and changed quite many things.
v3.0 - Bram Vreugdenhil Converted from Weather underground api calls to data of domoticz devices so you can use OpenWeathermaps sensors or own sensors
]]--
-- Input devices . You can use Openweathermap devices for it. Just add "Open Weather Map" in the hardware setup.
local idxCloudCover = 78 -- (Integer) Device ID of device holding cloudcoverage
local idxBarometer = 75 -- (Integer) Device ID of device barometric presusure
-- Variables to customize (can be nil )------------------------------------------
local idxSolarAzimuth = 1997 -- (Integer) Virtual Azimuth Device ID
local idxSolarAltitude = 1998 -- (Integer) Your virtual Solar Altitude Device ID
local idxRadiation = 1999 -- (Integer) Domoticz virtual Radiation device ID
local idxLux = 1996 -- (Integer) Domoticz virtual Lux device ID
local logToFile = false -- (Boolean) Set to true if you also wish to log to a file. It might get big by time.
local tmpLogFile = '/tmp/logSun.txt'-- Logging to a file if specified
local fetchIntervalMins = 5 -- (Integer) (Minutes, Range 5-60) How often Wunderground API is called
local latitude = 51.9891087 -- Latitude. (Decimal number) Decimal Degrees. E.g. something like 51.748485
local longitude = 4.1554187000 -- Longitude. (Decimal number) Decimal Degrees. E.g.something like 5.629728.
local altitude = 1 -- Altitude. (Integer) Meters above sea level.
-- Please don't make any changes below this line (Except for setting logging level)
local scriptVersion = '3'
return {
active = true,
logging = {
--level = domoticz.LOG_DEBUG, -- Uncomment to override the dzVents global logging setting
marker = 'SOLAR '..scriptVersion
},
on = {
timer = {'every 5 minutes'}
},
data = {
lastOkta = {initial=0},
lastOgimetTime = {initial='198001010000'}
},
execute = function(domoticz, device)
local function leapYear(year)
return year%4==0 and (year%100~=0 or year%400==0)
end
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²
local relativePressure = domoticz.devices(idxBarometer).barometer
local year = os.date('%Y')
local numOfDay = os.date('%j')
local nbDaysInYear = (leapYear(year) and 366 or 365)
local angularSpeed = 360/365.25
local declination = math.deg(math.asin(0.3978 * math.sin(math.rad(angularSpeed) *(numOfDay - (81 - 2 * math.sin((math.rad(angularSpeed) * (numOfDay - 2))))))))
local timeDecimal = (os.date('!%H') + os.date('!%M') / 60) -- Coordinated Universal Time (UTC)
local solarHour = timeDecimal + (4 * longitude / 60 ) -- The solar Hour
local hourlyAngle = 15 * ( 12 - solarHour ) -- hourly Angle of the sun
local sunAltitude = math.deg(math.asin(math.sin(math.rad(latitude))* math.sin(math.rad(declination)) + math.cos(math.rad(latitude)) * math.cos(math.rad(declination)) * math.cos(math.rad(hourlyAngle))))-- the height of the sun in degree, compared with the horizon
local azimuth = math.acos((math.sin(math.rad(declination)) - 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(declination)) * math.sin(math.rad(hourlyAngle))) / math.cos(math.rad(sunAltitude))
if(sinAzimuth<0) then azimuth=360-azimuth end
local sunstrokeDuration = math.deg(2/15 * math.acos(- math.tan(math.rad(latitude)) * math.tan(math.rad(declination)))) -- duration of sunstroke in the day . Not used in this calculation.
local 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
local absolutePressure = relativePressure - domoticz.utils.round((altitude/ 8.3),1) -- hPa
local sinusSunAltitude = math.sin(math.rad(sunAltitude))
local M0 = math.sqrt(1229 + math.pow(614 * sinusSunAltitude,2)) - 614 * sinusSunAltitude
local M = M0 * relativePressure/absolutePressure
domoticz.log('', domoticz.LOG_INFO)
domoticz.log('============== SUN LOG ==================', domoticz.LOG_INFO)
--domoticz.log(city .. ', latitude: ' .. latitude .. ', longitude: ' .. longitude, domoticz.LOG_INFO)
--domoticz.log('Home altitude = ' .. tostring(altitude) .. ' m', domoticz.LOG_DEBUG)
domoticz.log('Angular Speed = ' .. angularSpeed .. ' per day', domoticz.LOG_DEBUG)
domoticz.log('Declination = ' .. declination .. '°', domoticz.LOG_DEBUG)
domoticz.log('Universal Coordinated Time (UTC) '.. timeDecimal ..' H.dd', domoticz.LOG_DEBUG)
domoticz.log('Solar Hour '.. solarHour ..' H.dd', domoticz.LOG_DEBUG)
domoticz.log('Altitude of the sun = ' .. sunAltitude .. '°', domoticz.LOG_INFO)
domoticz.log('Angular hourly = '.. hourlyAngle .. '°', domoticz.LOG_DEBUG)
domoticz.log('Azimuth of the sun = ' .. azimuth .. '°', domoticz.LOG_INFO)
domoticz.log('Duration of the sun stroke of the day = ' .. domoticz.utils.round(sunstrokeDuration,2) ..' H.dd', domoticz.LOG_DEBUG)
domoticz.log('Radiation max in atmosphere = ' .. domoticz.utils.round(RadiationAtm,2) .. ' W/m²', domoticz.LOG_DEBUG)
domoticz.log('Local relative pressure = ' .. relativePressure .. ' hPa', domoticz.LOG_DEBUG)
domoticz.log('Absolute pressure in atmosphere = ' .. absolutePressure .. ' hPa', domoticz.LOG_DEBUG)
domoticz.log('Coefficient of mitigation M = ' .. M ..' M0 = '..M0, domoticz.LOG_DEBUG)
-- In meteorology, an okta is a unit of measurement used to describe the amount of cloud cover
-- at any given location such as a weather station. Sky conditions are estimated in terms of how many
-- eighths of the sky are covered in cloud, ranging from 0 oktas (completely clear sky) through to 8 oktas
-- (completely overcast). In addition, in the synop code there is an extra cloud cover indicator '9'
-- indicating that the sky is totally obscured (i.e. hidden from view),
-- usually due to dense fog or heavy snow.
Cloudpercentage = domoticz.devices(idxCloudCover).percentage
okta = Cloudpercentage/12.5
local Kc = 1-0.75*math.pow(okta/8,3.4) -- Factor of mitigation for the cloud layer
local directRadiation, scatteredRadiation, totalRadiation, Lux, weightedLux
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
totalRadiation=totalRadiation*Kc
domoticz.log('Okta = '..okta.. ' Cloud coverage = ' ..Cloudpercentage .. '%', domoticz.LOG_INFO)
domoticz.log('Kc = ' .. Kc, domoticz.LOG_DEBUG)
domoticz.log('Direct Radiation = '.. domoticz.utils.round(directRadiation,2) ..' W/m²', domoticz.LOG_INFO)
domoticz.log('Scattered Radiation = '.. domoticz.utils.round(scatteredRadiation,2) ..' W/m²', domoticz.LOG_DEBUG)
domoticz.log('Total radiation = ' .. domoticz.utils.round(totalRadiation,2) ..' W/m²', domoticz.LOG_INFO)
domoticz.log('Total Radiation in lux = '.. domoticz.utils.round(Lux,2)..' Lux', domoticz.LOG_DEBUG)
domoticz.log('Total weighted lux = '.. domoticz.utils.round(weightedLux,2)..' Lux', domoticz.LOG_INFO)
-- 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'])
if idxLux and domoticz.devices(idxLux).lux + domoticz.utils.round(weightedLux, 0) > 0 then
domoticz.devices(idxLux).updateLux(domoticz.utils.round(weightedLux,0))
end
if(idxSolarAzimuth) then
domoticz.devices(idxSolarAzimuth).updateCustomSensor(domoticz.utils.round(azimuth,0))
end
if(idxSolarAltitude) then
domoticz.devices(idxSolarAltitude).updateCustomSensor(domoticz.utils.round(sunAltitude,0))
end
-- No update if radiation is already 0. See LUX
if idxRadiation and (domoticz.devices(idxRadiation).rawData[1] + domoticz.utils.round(totalRadiation, 2) > 0) then
domoticz.devices(idxRadiation).updateCustomSensor(domoticz.utils.round(totalRadiation,2))
end
if logToFile then
local logDebug = os.date('%Y-%m-%d %H:%M:%S',os.time())
logDebug=logDebug..' Azimuth:' .. azimuth .. ' Height:' .. sunAltitude
logDebug=logDebug..' Okta:' .. okta..' KC:'.. Kc
logDebug=logDebug..' Direct:'..directRadiation..' inDirect:'..scatteredRadiation..' TotalRadiation:'..totalRadiation..' LuxCloud:'.. domoticz.utils.round(weightedLux,2)
os.execute('echo '..logDebug..' >>'..tmpLogFile) -- compatible Linux & Windows
end
end
}
Sorry..
I am a dombo in scripting...
Is this a Lua dz or?
Do i set time in lua or all?
Edit:
Dz vents.. almost working...
What type of dummy do i need for this:
local idxRadiation
I us a uv dummy only get an error:
2019-03-30 19:10:04.201 Status: dzVents: Error (2.4.15): SOLAR 3: Method updateCustomSensor is not available for device "DZ: UV" (deviceType=UV, deviceSubType=UVN128,UV138). If you believe this is not correct, please report.
Re: dzVents version of the Solar Data Script
Posted: Saturday 30 March 2019 19:07
by jake
Derik wrote:
Sorry..
I am a dombo in scripting...
Is this a Lua dz or?
Do i set time in lua or all?
Hi, to answer the question: this is adz script. You put in in domoticz/scripts/dzvents/scripts. Dzvents had nothing to do with time or all, I believe (I never use the internal editor). It is defined in the script itself
Re: dzVents version of the Solar Data Script
Posted: Saturday 30 March 2019 19:12
by Derik
jake wrote: ↑Saturday 30 March 2019 19:07
Derik wrote:
Sorry..
I am a dombo in scripting...
Is this a Lua dz or?
Do i set time in lua or all?
Hi, to answer the question: this is adz script. You put in in domoticz/scripts/dzvents/scripts. Dzvents had nothing to do with time or all, I believe (I never use the internal editor). It is defined in the script itself
I get it working in dz vents internal..
Only one error:
Code: Select all
2019-03-30 19:10:04.201 Status: dzVents: Error (2.4.15): SOLAR 3: Method updateCustomSensor is not available for device "DZ: UV" (deviceType=UV, deviceSubType=UVN128,UV138). If you believe this is not correct, please report.
Re: dzVents version of the Solar Data Script
Posted: Saturday 30 March 2019 19:57
by gimic
the virtual device is from the type 'solar radiation'
maybe you selected 'UV'?
Re: dzVents version of the Solar Data Script
Posted: Saturday 30 March 2019 20:09
by Derik
gimic wrote: ↑Saturday 30 March 2019 19:57
the virtual device is from the type 'solar radiation'
maybe you selected 'UV'?
Not working
Re: dzVents version of the Solar Data Script
Posted: Sunday 31 March 2019 11:37
by oredin
Derik wrote: ↑Saturday 30 March 2019 20:09
gimic wrote: ↑Saturday 30 March 2019 19:57
the virtual device is from the type 'solar radiation'
maybe you selected 'UV'?
Not working
Hi,
Try with a "Custom Sensor".
Re: dzVents version of the Solar Data Script
Posted: Sunday 31 March 2019 12:04
by Derik
oredin wrote: ↑Sunday 31 March 2019 11:37
Derik wrote: ↑Saturday 30 March 2019 20:09
gimic wrote: ↑Saturday 30 March 2019 19:57
the virtual device is from the type 'solar radiation'
maybe you selected 'UV'?
Not working
Hi,
Try with a "Custom Sensor".
YES working Thanks..
Only 1 question....
Could you ex-plane the function of the solar radiation and what sort of value i must give to this custom sensor
Re: dzVents version of the Solar Data Script
Posted: Sunday 31 March 2019 12:18
by gimic
i have it in Watt/m2
Re: dzVents version of the Solar Data Script
Posted: Sunday 31 March 2019 12:21
by Derik
gimic wrote: ↑Sunday 31 March 2019 12:18
i have it in Watt/m2
And how must i see this value??
Power watt /m²
Or what can i do with this value
Re: dzVents version of the Solar Data Script
Posted: Monday 01 April 2019 10:19
by oredin
Derik wrote: ↑Sunday 31 March 2019 12:21
gimic wrote: ↑Sunday 31 March 2019 12:18
i have it in Watt/m2
And how must i see this value??
Power watt /m²
Or what can i do with this value
Hi,
This value is only used as a step for the whole computation and to compute the Lux value.
If you want to know more about it, look for Solar irradiance.
Re: dzVents version of the Solar Data Script
Posted: Sunday 02 June 2019 20:54
by roblom
Is it just me or is this script not working anymore because the Wundergound stopped with the use of the API?
https://apicommunity.wunderground.com/w ... ground-api