dzVents version of the Solar Data Script  [SOLVED]

Moderator: leecollings

Locked
Bishop
Posts: 22
Joined: Sunday 11 June 2017 14:06
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: dzVents version of the Solar Data Script

Post by Bishop »

Since a few days I noticed my Lux value wasn't update every 5 minutes. So I went to check the logs and every now and then, few times per hour, it seems Domoticz is unable to reach ogimet.com. Is anyone else experiencing the same?

Code: Select all

2018-06-25 09:25:05.617 Error: Error opening url: http://www.ogimet.com/cgi-bin/getsynop?block=06370&begin=20180625060
Ray-Man
Posts: 29
Joined: Friday 12 December 2014 19:03
Target OS: Linux
Domoticz version: 2021.1
Location: Zwolle
Contact:

Re: dzVents version of the Solar Data Script

Post by Ray-Man »

I can't seem to get the script working:

Code: Select all

2018-06-25 21:31:00.330 Status: dzVents: Error (2.4.6): SOLAR 2.2.1: An error occured when calling event handler Zonnestand2
2018-06-25 21:31:00.330 Status: dzVents: Error (2.4.6): SOLAR 2.2.1: ...moticz/scripts/dzVents/generated_scripts/Zonnestand2.lua:143: attempt to index field 'current_observation' (a nil value)
I really want to change to the dzVents version because the LUA one seems to run every second (after a while).
Does anyone has a solution for this nil value thing?
Bruno
Posts: 2
Joined: Wednesday 11 July 2018 11:45
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: dzVents version of the Solar Data Script

Post by Bruno »

I'm a domoticz newbie and interested in the automation of my Somfy sunscreen.
Is it possible to use this script in Belgium en with adaptations have to be made?
How can the dzVents script be activate in the domoticz event system?
Can somebody help me please?
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: dzVents version of the Solar Data Script

Post by waaren »

Bruno wrote: Wednesday 18 July 2018 10:01 I'm a domoticz newbie and interested in the automation of my Somfy sunscreen.
Is it possible to use this script in Belgium en with adaptations have to be made?
How can the dzVents script be activate in the domoticz event system?
Can somebody help me please?
@Bruno, to activate this- or any other dVents script in domoticz please read the dzVents wiki and specific the Using dzVents with domoticz section.

Script should work in Belgium without changes if you enter all the right settings in the config part. (between lines
-- Variables to customize ------------------------------------------------

and

-- Please don't make any changes below this line (Except for setting logging level)
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Bruno
Posts: 2
Joined: Wednesday 11 July 2018 11:45
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: dzVents version of the Solar Data Script

Post by Bruno »

@ waaren

Thank you for your quick answer and the link.
I'll do my best to try to understand the explanation and to create a dzvents event in domoticz but i am not a programmer at all :cry:
All other parameters in the wuSettings file have been entered as asked.
jake
Posts: 742
Joined: Saturday 30 May 2015 22:40
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Contact:

Re: dzVents version of the Solar Data Script

Post by jake »

Bruno wrote:@ waaren

Thank you for your quick answer and the link.
I'll do my best to try to understand the explanation and to create a dzvents event in domoticz but i am not a programmer at all :cry:
All other parameters in the wuSettings file have been entered as asked.
I also wasn't a programmer, but... Just start ;)
I use the dzvents wiki a lot and combine it with examples from other scripts in the forums.
emece67
Posts: 1
Joined: Tuesday 31 July 2018 12:38
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.97
Location: MAD
Contact:

Re: dzVents version of the Solar Data Script

Post by emece67 »

Hi all,

As many of us have surely noted, WU does not give anymore free API keys, so new users of WU (and Domoticz, like me) do not have a way to get the pressure data needed by this script.

But I've noticed that the Ogimet service (at least the station I'm using) does report such pressure values, so a single query to Ogimet can give both cloud cover & pressure values. I'm now in the process of modifying the script to use only Ogimet but, in the meanwhile, does anybody know of a reason to prefer the pressure values reported by WU instead of the ones from Ogimet?

I'm wodering, also, about the reason to use the latitude/longitude values from WU instead of those in Domoticz settings. I'll try to modify the script to use these.

But, be patient, I'm really new to domoticz (just 2 days) and to Lua (just a few hours).

Regards.
Information must flow.
pascal
Posts: 9
Joined: Sunday 28 September 2014 15:31
Target OS: Raspberry Pi / ODroid
Domoticz version: V4.9700
Contact:

Re: dzVents version of the Solar Data Script

Post by pascal »

hello,
Lua script is working properly, DzEvent script not really, virtual sensors are not updated, and there is not any error reported. Strange
Any idea? :roll:
Thanks
jake
Posts: 742
Joined: Saturday 30 May 2015 22:40
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Contact:

Re: dzVents version of the Solar Data Script

Post by jake »

I decided to finaly replace the old LUA version of the script by the DzVents version.

I copied the script from the initial post and came across these errors:

line 207:

Code: Select all

if(sinAzimuth		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.
This 'error' is displayed when I view the post with the tapatalk app only. Opening this topic in a web browser displays the correct code:
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.

Line 253:

Code: Select all

elseif sunAltitude = -7 then -- apply theoretical Lux of twilight
Should be:

Code: Select all

elseif sunAltitude == -7 then -- apply theoretical Lux of twilight
JCLB
Posts: 7
Joined: Saturday 15 August 2015 17:45
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: dzVents version of the Solar Data Script

Post by JCLB »

Someone should adapt the script by using data from other sources, and use domoticz virtual sensors whenever possible, why try to get data from WU or Accu or DarkSky as they're all included in domoticz, script would be more simple and concentrate on maths and not API calls:
  • pressure read from weather sensor (with idx for each one, up to you to choose between real ones and virtual
  • latitude, longitude, altitude set manually
  • cloud cover fetched from DarkSky API in this script instead of the dying ogimet or from a local virtual sensor with this script viewtopic.php?f=61&t=22090&p=188573 and then change the calcul to use % instead of octa
oredin
Posts: 14
Joined: Saturday 27 October 2018 13:01
Target OS: -
Domoticz version:
Contact:

Re: dzVents version of the Solar Data Script

Post by oredin »

Hi,

I just discovered this script and since the WU API is not available anymore, I took the liberty to adapt the dzEvent script to use Dark Sky API.
I made some changes to follow JCLB's advices about :
- the pressure (which is defaulted to Dark Sky but can be taken from a device)
- latitude, longitude and altitude have to be set manually since I didn't find another way to detect them
- Cloud cover is retrieved from Dark Sky API and the subsequent algorithm is modified (even if I didn't renamed the variable "okta")

It's a shame that the cloud cover isn't supported by the Dark Sky hardware in DZ. I could have made it "datasource independent" so that it relies only on dz devices.

The script is avaiblable at https://github.com/russandol-sarl/dz-solarData.

Feel free to share ! If you have any improvements in mind, you can tell me and I'll see what I can do.
hestia
Posts: 357
Joined: Monday 25 December 2017 23:06
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.1
Location: Paris
Contact:

Re: dzVents version of the Solar Data Script

Post by hestia »

oredin wrote: Saturday 27 October 2018 20:34 Hi,

I just discovered this script and since the WU API is not available anymore, I took the liberty to adapt the dzEvent script to use Dark Sky API.
I made some changes to follow JCLB's advices about :
- the pressure (which is defaulted to Dark Sky but can be taken from a device)
- latitude, longitude and altitude have to be set manually since I didn't find another way to detect them
- Cloud cover is retrieved from Dark Sky API and the subsequent algorithm is modified (even if I didn't renamed the variable "okta")

It's a shame that the cloud cover isn't supported by the Dark Sky hardware in DZ. I could have made it "datasource independent" so that it relies only on dz devices.

The script is avaiblable at https://github.com/russandol-sarl/dz-solarData.

Feel free to share ! If you have any improvements in mind, you can tell me and I'll see what I can do.
Hi,
I've writen a DzVents script to get values from DarkSky, with pressure and cloud cover => all put in dz device
It works fine except for the rain because rain sensors are a strange thing in Domoticz - I work on it when I time and when it's raining ;-)
I also have rain expectation for the next 1h, 12 and 24h (for a future watering system)
This could be a start to split the datasources from the algorithm
Updated 10-March 2019

Code: Select all

--[[ Script to get some values from darksky API and calculate rain expectation for next hours
Meteo_V0R9d
from https://www.domoticz.com/forum/viewtopic.php?t=22090 (Cloud cover from darksky by aleph0)

to read: https://darksky.net/dev/docs

extract from several emails with DarkSky support to understand their data:
<<precipProbability is the probability of any precipitation at all in the corresponding hour,
while *precipIntensity* is the expected amount of precipitation.
Technically *precipIntensity* is a rate, but it is per hour, so the number is also the expected amount for the hour for which it's reported>>
<<for the next 24 hours, you simply want to sum precipIntensity for each hour,
since it is the expected precipitation amount per hour for those hours>>
<<Regarding the probabilities for "current" conditions:
think of the probabilities as representing our uncertainty about events rather than a direct probability of an event occurring.
Because there are not stations at every location in the world and their data is not perfect, even historical observations have some uncertainty>>

]]--
local debug=0
local DOMAIN = 'Meteo'
local TIME_INTERVAL = 'every 10 minutes' -- 'every ...'
local coord='48.444444,2.233379' -- latitude,longitude
local api_key='xxxxxxxxxxxxxxxxxxxxxxxxxxx' -- darkSky secret key

-- Devices to update with API result
local dev_temp_hum_baro = 299 -- dummy receive Temp+Hum+Baro / Type Temp + Humidity + Baro
local dev_temperature = 300 -- dummy receive temperature / Type Temp
local dev_rain = 301 -- dummy receive rain in mm / Type Rain
local dev_rainExp = 366 -- dummy receive rain in mm / Type Rain
local dev_humidity = 302 -- dummy receive humidity / Type Humidity
local dev_barometer = 303 -- dummy receive pressure / SubType Barometer
local dev_wind = 298 -- dummy receive wind measures (Vent+Temp+Ressentie) / Type Wind

-- to choose between custom and %. With custom you could choose the icon!
local dev_cloudCoverPerCent = 339 -- or nill / dummy receive cloudCover / SubType Percentage            -- to choose between custom and %
local dev_cloudCover = 309 -- or nill / dummy receive cloudCover / SubType Custom Sensor with unit = %  -- With custom you could choose the icon!
local dev_uvIndex = 306 -- dummy receive uvIndex / Type UV
local dev_visibility = 310 -- dummy receive visibility / SubType Visibility
local dev_ozone = 308 -- dummy receive ozone / SubType Custom Sensor

-- Devices to update with calculation with API result
local dev_rain1h = 317 -- dummy receive 1h expected rain in mm / Custom sensor (mm)
local dev_rain12h = 318 -- dummy receive 12h expected rain in mm / Custom sensor (mm)
local dev_rain24h = 319 -- dummy receive 24h expected rain in mm / Custom sensor (mm)

return {
	active = true,
	logging = {
		level = domoticz.LOG_ERROR, -- Select one of LOG_DEBUG, LOG_INFO, LOG_ERROR, LOG_FORCE to override system log level
		marker = DOMAIN},
	on = {
		-- devices = {203},   -- a switch for testing w/o waiting minutes
		timer = {TIME_INTERVAL},
		httpResponses = {'getDarkSkyForecast'}
		},
    data = {
		lastRain = {initial=nill },
		lastRainExp = {initial=nill }
		},
	
	execute = function(dz, triggerObject)
	    
	    -- /// Functions start \\\
    	local function string2Epoch(dateString) -- seconds from epoch based on stringdate (used by string2Date) -- Assuming a date pattern like: yyyy-mm-dd
    		local pattern = '(%d+)-(%d+)-(%d+)'
    		local runyear, runmonth, runday= dateString:match(pattern)
    		local convertedTimestamp = os.time({year = runyear, month = runmonth, day = runday})
    		return convertedTimestamp
    	end
    	
    	local function string2Date(str,fmt) -- convert string from json into datevalue
    		if fmt then
    			return os.date(fmt,string2Epoch(str))
    		end
    		return os.date(' %A %d %B, %Y',string2Epoch(str)):gsub(' 0',' ')
    	end
    	
    	local 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
    	
    	local function humidity_status(humidity_val) -- humidity in %
    		local status = dz.HUM_NORMAL
    		if humidity_val > 69 then status = dz.HUM_WET
    			elseif humidity_val < 30 then status = dz.HUM_DRY
    			elseif humidity_val < 45 then status = dz.HUM_NORMAL
    			else status = dz.HUM_COMFORTABLE
    		end
    		return status
    	end
    	
        local function THBForecast_calc(icon_val)
            local THBForecast_val = dz.BARO_NOINFO
            if icon_val == "" or icon_val == "wind" then THBForecast_val = dz.BARO_NOINFO
            	elseif icon_val == "clear-day" or icon_val == "clear-night" then THBForecast_val = dz.BARO_SUNNY
            	elseif icon_val == "partly-cloudy-day" or icon_val == "partly-cloudy-night" then THBForecast_val = dz.BARO_PARTLYCLOUDY
            	elseif icon_val == "sleet" or icon_val == "fog"  or  icon_val == "cloudy" then THBForecast_val = dz.BARO_CLOUDY
	          	elseif icon_val == "rain" or icon == "snow" then THBForecast_val=dz.BARO_RAIN
            end
            if debug == 1 then
                print('icon_val: ' .. icon_val)
                print('THBForecast_val: ' .. THBForecast_val)
            end
            return THBForecast_val
        end
        
        local function baroForecast_calc(icon_val) -- to improve
            local baroForecast_val = dz.BARO_NOINFO
            if icon_val == "wind" then baroForecast_val = dz.BARO_UNSTABLE
            	elseif icon_val == "clear-day" or icon_val == "clear-night" then baroForecast_val = dz.BARO_SUNNY
            	elseif icon_val == "partly-cloudy-day" or icon_val == "partly-cloudy-night" then baroForecast_val = dz.BARO_STABLE
            	elseif icon_val == "sleet" or icon_val == "fog"  or  icon_val == "cloudy" then baroForecast_val = dz.BARO_CLOUDY
	          	elseif icon_val == "rain" or icon == "snow" then baroForecast_val=dz.BARO_UNSTABLE
            end
            if debug == 1 then
                print('icon_val: ' .. icon_val)
                print('baroForecast_val: ' .. baroForecast_val)
            end
            return baroForecast_val
        end   
  
    	local function TempChill_calc(Temp_val, WindSpeed_kmh_val) -- https://fr.wikipedia.org/wiki/Température_ressentie#Froid_ressenti
    		local TempChill_val = Temp_val
    		if (Temp_val ~= nil and WindSpeed_kmh_val ~= nil and Temp_val <= 10) then
    		    if (WindSpeed_kmh_val > 4.8) then
    		        local Pow_WindSpeed = math.pow(WindSpeed_kmh_val, 0.16)
    				local Pow_WindSpeed = math.pow(WindSpeed_kmh_val, 0.16)
    				TempChill_val = 13.12 + 0.6215 * Temp_val + (0.3965 * Temp_val - 11.37) * Pow_WindSpeed
				elseif WindSpeed_kmh_val >= 0 then
    				TempChill_val = Temp_val + 0.2 * (0.1345 * Temp_val - 1.59) * WindSpeed_kmh_val
    			end
    		end
    		return round(TempChill_val,1)
    	end
    	
    	local function windDirection_calc(windBearing_val) -- Wind direction calculation
    		if (windBearing_val < 11.25) then wind_direction_val = 'N'
    			elseif (windBearing_val >= 11.25 and windBearing_val < 33.75) then wind_direction_val = 'NNE'
    			elseif (windBearing_val >= 33.75 and windBearing_val < 56.25) then wind_direction_val = 'NE'
    			elseif (windBearing_val >= 56.25 and windBearing_val < 78.75) then wind_direction_val = 'ENE'
    			elseif (windBearing_val >= 78.75 and windBearing_val < 101.25) then wind_direction_val = 'E'
    			elseif (windBearing_val >= 101.25 and windBearing_val < 123.75) then wind_direction_val = 'ESE'
    			elseif (windBearing_val >= 123.75 and windBearing_val < 146.25) then wind_direction_val = 'SE'
    			elseif (windBearing_val >= 146.25 and windBearing_val < 168.75) then wind_direction_val = 'SSE'
    			elseif (windBearing_val >= 168.75 and windBearing_val < 191.25) then wind_direction_val = 'S'
    			elseif (windBearing_val >= 191.25 and windBearing_val < 213.75) then wind_direction_val = 'SSW'
    			elseif (windBearing_val >= 213.75 and windBearing_val < 236.25) then wind_direction_val = 'SW'
    			elseif (windBearing_val >= 236.25 and windBearing_val < 258.75) then wind_direction_val = 'WSW'
    			elseif (windBearing_val >= 258.75 and windBearing_val < 281.25) then wind_direction_val = 'W'
    			elseif (windBearing_val >= 281.25 and windBearing_val < 303.75) then wind_direction_val = 'WNW'
    			elseif (windBearing_val >= 303.75 and windBearing_val < 326.25) then wind_direction_val = 'NW'
    			elseif (windBearing_val >= 326.25 and windBearing_val < 348.75) then wind_direction_val = 'NNW'
    			else wind_direction_val = 'N'
    		end
    		
    		return wind_direction_val
    	end
    	-- \\\ Functions end ///
    	
    	if (triggerObject.isDevice or triggerObject.isTimer) then   -- triggerObject.isDevic for testing only
    		local darkSkyUrl = 'https://api.darksky.net/forecast/'..api_key..'/'..coord..'?lang=fr&units=si&exclude=minutely,daily' -- alerts to get sources, nearest-station, units
    		dz.log('*** Request url', dz.LOG_FORCE)
			if debug==1 then
			    print('url: ' .. darkSkyUrl)
		    end
    		dz.openURL({url = darkSkyUrl, method = 'GET', callback = 'getDarkSkyForecast'})
    	elseif (triggerObject.isHTTPResponse) then
    	   	dz.log('*** Response...', dz.LOG_FORCE)
    	   	if (triggerObject.ok) then
    		    if debug==1 then
        			print('triggerObject ok')
        			print('trigger: ' .. triggerObject.trigger)
        			print('callback: ' .. triggerObject.callback)
        			print('statusCode: ' .. triggerObject.statusCode)
        		end
    			if (triggerObject.isJSON) then
    				local currently_time = os.date('%x %X', triggerObject.json.currently.time)
    				if debug==1 then
        				print ('JSON :-)')
        				print ('latitude: ' ..triggerObject.json.latitude)
        				print ('longitude: ' ..triggerObject.json.longitude)
        				print ('timezone: ' ..triggerObject.json.timezone)
        				print('time UNIX: '.. triggerObject.json.currently.time)
        				print('time: '.. currently_time)
    				end
    				--[[ to do once to know - need to add flag 
    				print('nearest-station: '.. triggerObject.json.flags["nearest-station"])
    		       	print('units: '.. triggerObject.json.flags.units)
    		       	local sourceId
    		       	for i in pairs(triggerObject.json.flags.sources) do
    		       	    print('sources '.. i .. ": "  .. triggerObject.json.flags.sources[i])
    		       	end
    		       	]]--
    		        local nillCount = 0 -- to count nill values from dark Sky
                	local nillCountH = 0 -- to count nill values from dark Sky (hourly data)
                	-- Variables to calcule rain forecast
                	local hourlyPrecipIntensity = {initial={}}
                	local hourlyPrecipExpectation = {initial={}}
                	local hourlyTime= {initial={}}
                	local h1PrecipExpectation = 0
                	local h12PrecipExpectation = 0
                	local h24PrecipExpectation = 0
                	local h1PrecipMax = 0
                	local h12PrecipMax = 0
                	local h24PrecipMax = 0

                	-- Retrieve values from dz in case of nill values from json
                	local dz_rainRate = dz.devices(dev_rain).rainRate
                	local dz_rain = dz.devices(dev_rain).rain
                	local dz_rainExp = dz.devices(dev_rainExp).rain
                	if dz.data.lastRain == nill then
                	    dz.data.lastRain = dz_rain
                	    if debug == 2 then
                	        print('dz.data.lastRain nill: ' .. dz.data.lastRain)
                  	    end
                     else
      	                if debug == 2 then
          	                print('dz.data.lastRain NOT nill: ' .. dz.data.lastRain)
          	            end
            	    end
        	    	if dz.data.lastRainExp == nill then
            	    dz.data.lastRainExp = dz_rainExp
            	    if debug == 2 then
            	        print('dz.data.lastRainExp nill: ' .. dz.data.lastRainExp)
              	    end
                 else
  	                if debug == 2 then
      	                print('dz.data.lastRainExp NOT nill: ' .. dz.data.lastRainExp)
      	            end
            	    end
                	local dz_humidity = dz.devices(dev_humidity).humidity
                	local dz_temperature = dz.devices(dev_temperature).temperature
                	local dz_dewPoint = dz.devices(dev_temp_hum_baro).dewPoint
                	local dz_pressure = dz.devices(dev_barometer).barometer
                	local dz_baroForecast = dz.devices(dev_barometer).forecast
                	local dz_THBForecast = dz.devices(dev_barometer).forecast
                	local dz_windBearing = dz.devices(dev_wind).direction
                	local dz_windSpeed_ms = dz.devices(dev_wind).speed
                	local dz_windGust_ms = dz.devices(dev_wind).gust
                	local dz_windChill = dz.devices(dev_wind).chill
                
                	if debug==1 then
                	    print(' ')
                	    print('dz values from devices')
                		print('dz_rainRate: ' .. dz_rainRate)
                		print('dz_rain: ' .. dz_rain)
                		print('dz_humidity: ' .. dz_humidity)
                		print('dz_temperature: ' .. dz_temperature)
                		print('dz_dewPoint: ' .. dz_dewPoint)
                		print('dz_pressure: ' .. dz_pressure)
                		print('dz_baroForecast: ' .. dz_baroForecast)
                		print('dz_THBForecast: ' .. dz_THBForecast)
                		print('dz_windBearing: ' .. dz_windBearing)
                		print('dz_windSpeed_ms: ' .. dz_windSpeed_ms)
                		print('dz_windGust_ms: ' .. dz_windGust_ms)
                		print('dz_windChill: ' .. dz_windChill)
                		print(' ')
                		print('Dark Sky values')
                		print('precipIntensity: ' ..  triggerObject.json.currently.precipIntensity)
                		print('precipProbability: ' ..  triggerObject.json.currently.precipProbability)
                        print('humidity: ' ..  triggerObject.json.currently.humidity)
                        print('temperature: ' ..  triggerObject.json.currently.temperature)
                        print('pressure: ' ..  triggerObject.json.currently.pressure)
                        print('icon: ' ..  triggerObject.json.currently.icon)
                        print('windSpeed: ' ..  triggerObject.json.currently.windSpeed)
                        print('windBearing: ' ..  triggerObject.json.currently.windBearing)
                        print('windGust: ' ..  triggerObject.json.currently.windGust)
                        print('windChill: ' .. triggerObject.json.currently.apparentTemperature)
                        print('dewPoint : ' ..  triggerObject.json.currently.dewPoint)
                        print('cloudCover: ' ..  triggerObject.json.currently.cloudCover)
                        print('uvIndex: ' ..  triggerObject.json.currently.uvIndex)
                        print('visibility: ' ..  triggerObject.json.currently.visibility)
                        print('ozone: ' ..  triggerObject.json.currently.ozone)
                	end
    	
    				-- get with values from json and if not nill, update the devices with Dark Sky values ; if nill keep dz values
    				local hum_status = '' --
    				
    				local Time = require('Time')
                    local  now = Time()
                    local nowSecondsSinceMidnight =  now.secondsSinceMidnight
       				if triggerObject.json.currently.precipIntensity ~= nill then
    				    local lastRainUpdateInSec = dz.devices(dev_rain).lastUpdate.secondsAgo
    				    local lastRainExpUpdateInSec = dz.devices(dev_rainExp).lastUpdate.secondsAgo
    				    -- rain sensor is the total rain of the day
    				    -- precipIntensity is for 1 hour, so 3600 seconds, for the last update I took the part for the elapsed time)
    				    if lastRainUpdateInSec <= nowSecondsSinceMidnight then -- the last update was yesterday
    				        dz.data.lastRain = dz.data.lastRain + triggerObject.json.currently.precipIntensity / 3600 * lastRainUpdateInSec
    				    else dz.data.lastRain = triggerObject.json.currently.precipIntensity / 3600 * lastRainUpdateInSec
    				    end
    				    dz_rain = round(dz.data.lastRain, 1)
    				    if triggerObject.json.currently.precipProbability ~= nill then
        				    if lastRainExpUpdateInSec <= nowSecondsSinceMidnight then -- the last update was yesterday
        				        dz.data.lastRainExp = dz.data.lastRainExp + triggerObject.json.currently.precipIntensity / 3600 * lastRainExpUpdateInSec * triggerObject.json.currently.precipProbability
        				    else dz.data.lastRainExp = triggerObject.json.currently.precipIntensity / 3600 * lastRainExpUpdateInSec * triggerObject.json.currently.precipProbability
        				    end
        				    dz_rainExp = round(dz.data.lastRainExp, 1)
			                else nillCount = nillCount + 1
				        end
    				    if debug == 2 then
            				print('secondsSinceMidnight: ' .. nowSecondsSinceMidnight)
            				print('rain last update: ' .. lastRainUpdateInSec)
            				print("precipIntensity: " .. triggerObject.json.currently.precipIntensity)
            				print('precipProbability: ' .. triggerObject.json.currently.precipProbability)
            				print("lastRain: " .. dz.data.lastRain)
            				print('dz_rain: ' .. dz_rain)
            				print("lastRainExp: " .. dz.data.lastRainExp)
            				print('dz_rainExp: ' .. dz_rainExp)
        				end
        				if triggerObject.json.currently.precipIntensity ~= nill then
    				        dz_rainRate = round(triggerObject.json.currently.precipIntensity * 100,0)
    				    else nillCount = nillCount + 1
    				    end
				        else nillCount = nillCount + 1
    				end -- else dz value is kept
				
    				dz.devices(dev_rain).updateRain(dz_rainRate,dz_rain)
    				dz.devices(dev_rainExp).updateRain(dz_rainRate,dz_rainExp)
    			
    				if triggerObject.json.currently.humidity ~= nill then
    					dz_humidity = triggerObject.json.currently.humidity*100
    					local hum_status = humidity_status(dz_humidity) dz.devices(dev_humidity).updateHumidity(dz_humidity, hum_status)
    					else nillCount = nillCount + 1
    				end
    			
    				if triggerObject.json.currently.temperature ~= nill then
    					dz_temperature = round(triggerObject.json.currently.temperature,1) dz.devices(dev_temperature).updateTemperature(dz_temperature)
    					else nillCount = nillCount + 1
    				end
    				
    				if triggerObject.json.currently.pressure ~= nill then
    					dz_pressure = round(triggerObject.json.currently.pressure,0)
    					else nillCount = nillCount + 1
    				end
    				
    				if triggerObject.json.currently.icon ~= nill then
    					dz_baroForecast = baroForecast_calc(triggerObject.json.currently.icon)
    					else nillCount = nillCount + 1
    				end
    				dz.devices(dev_barometer).updateBarometer(dz_pressure, dz_baroForecast)
    		
    				if triggerObject.json.currently.windBearing ~= nill then
    					dz_windBearing = triggerObject.json.currently.windBearing
    					else nillCount = nillCount + 1
    				end
    				
    				local wind_direction = windDirection_calc(dz_windBearing)
    					if debug==1 then
    					print ('dz_windBearing: ' .. dz_windBearing)
    					print('wind_direction: ' .. wind_direction)
    				end
    				
    				if triggerObject.json.currently.windGust ~= nill then
    					dz_windGust_ms = round(triggerObject.json.currently.windGust,1)
    					else nillCount = nillCount + 1
    				end
    				
    				if triggerObject.json.currently.apparentTemperature ~= nill then
    					tempChill = round(triggerObject.json.currently.apparentTemperature,1)
    					else nillCount = nillCount + 1
    				end
    				
    				if triggerObject.json.currently.icon ~= nill then
    					dz_THBForecast = THBForecast_calc(triggerObject.json.currently.icon)
    					else nillCount = nillCount + 1
    				end
    				dz.devices(dev_wind).updateWind(dz_windBearing, wind_direction, dz_windSpeed_ms, dz_windGust_ms, dz_temperature,tempChill)
    				dz.devices(dev_temp_hum_baro).updateTempHumBaro(dz_temperature,dz_humidity,hum_status,dz_pressure,dz_THBForecast)
    			
    				if triggerObject.json.currently.dewPoint ~= nill then
    					dz_dewPoint = round(triggerObject.json.currently.dewPoint,1)
    					dz.devices(dev_temp_hum_baro).dewPoint = triggerObject.json.currently.dewPoint -- doesn't work !? :-(
    				    else nillCount = nillCount + 1
    				end
    
    				if triggerObject.json.currently.cloudCover ~= nill then
    				    if dev_cloudCover ~= nill then 
    					    dz.devices(dev_cloudCover).updateCustomSensor(triggerObject.json.currently.cloudCover*100)
    					end
    					if dev_cloudCoverPerCent ~= nill then 
    					    dz.devices(dev_cloudCoverPerCent).updatePercentage(triggerObject.json.currently.cloudCover*100)
					    end
					else nillCount = nillCount + 1
    				end
    
    				if triggerObject.json.currently.uvIndex ~= nill then
    					dz.devices(dev_uvIndex).updateUV(triggerObject.json.currently.uvIndex)
    					else nillCount = nillCount + 1
    				end
    
    				if triggerObject.json.currently.visibility ~= nill then
    					dz.devices(dev_visibility).updateVisibility(triggerObject.json.currently .visibility)
    					else nillCount = nillCount + 1
    				end
    
    				if triggerObject.json.currently.ozone ~= nill then
    					dz.devices(dev_ozone).updateCustomSensor(round(triggerObject.json.currently.ozone))
    					else nillCount = nillCount + 1
    				end
    				
				   	if debug==1 then
                	    print(' ')
                	    print('dz values from devices')
                		print('dz_rainRate: ' .. dz_rainRate)
                		print('dz_rain: ' .. dz_rain)
                		print('dz_humidity: ' .. dz_humidity)
                		print('dz_temperature: ' .. dz_temperature)
                		print('dz_dewPoint: ' .. dz_dewPoint)
                		print('dz_pressure: ' .. dz_pressure)
                		print('dz_baroForecast: ' .. dz_baroForecast)
                		print('dz_THBForecast: ' .. dz_THBForecast)
                		print('dz_windBearing: ' .. dz_windBearing)
                		print('dz_windSpeed_ms: ' .. dz_windSpeed_ms)
                		print('dz_windGust_ms: ' .. dz_windGust_ms)
                		print('dz_windChill: ' .. dz_windChill)
                		print(' ')
            		end
    				
    
    				-- Rain forecast calculation --
    				for i = 1, 25 do -- walk the hourly result for 24 hours (maxi = 49)
    				    if triggerObject.json.hourly.data[i].precipIntensity ~= nill then
    				    	hourlyPrecipIntensity[i] = triggerObject.json.hourly.data[i].precipIntensity
        				    hourlyPrecipExpectation[i] = hourlyPrecipIntensity[i]
            					if i == 1 then -- for the next hour
            						h1PrecipExpectation = hourlyPrecipExpectation[i]
            						h1PrecipMax = triggerObject.json.hourly.data[i].precipIntensity
            					end
            					if i < 13 then -- for the next 12 hours
            						h12PrecipExpectation = h12PrecipExpectation + hourlyPrecipExpectation[i]
            						if h12PrecipMax < triggerObject.json.hourly.data[i].precipIntensity then
            							h12PrecipMax = triggerObject.json.hourly.data[i].precipIntensity
            						end
            					end
            					h24PrecipExpectation = h24PrecipExpectation + hourlyPrecipExpectation[i]
            					if h24PrecipMax < triggerObject.json.hourly.data[i].precipIntensity then
            						h24PrecipMax = triggerObject.json.hourly.data[i].precipIntensity
            					end
            					if triggerObject.json.hourly.data[i] ~= nill then
            					    hourlyTime[i] = os.date('%x %X', triggerObject.json.hourly.data[i].time)
            					    else  hourlyTime[i] = 0
                					nillCountH = nillCountH + 1
              					    hourlyPrecipExpectation[i] = 0
        					    end
    					else nillCountH = nillCountH + 1
    					    hourlyPrecipIntensity[i] = 0
    					    hourlyPrecipExpectation[i] = 0
    					end
    				    if debug==1 then
    					    print( i .. ' ' .. hourlyTime[i] .. ' precipIntensity: ' .. hourlyPrecipIntensity[i] .. ' expectation: ' .. hourlyPrecipExpectation[i])
    				    end
    				end
    				h1PrecipMax = round((h1PrecipMax*100),-1)
    				h12PrecipMax = round((h12PrecipMax*100),-1)
    				h24PrecipMax = round((h24PrecipMax*100),-1)
    			
    				h1PrecipExpectation = round(h1PrecipExpectation,1)
    				h12PrecipExpectation = round(h12PrecipExpectation,1)
    				h24PrecipExpectation = round(h24PrecipExpectation,1)
    			    if debug==1 then
    			        print('h1PrecipMax:  ' .. h1PrecipMax .. '  h1PrecipExpectation:  ' .. h1PrecipExpectation)
    			        print('h12PrecipMax: ' .. h12PrecipMax .. '  h12PrecipExpectation: ' .. h12PrecipExpectation)
    			        print('h24PrecipMax: ' .. h24PrecipMax .. '  h24PrecipExpectation: ' .. h24PrecipExpectation)
    				end
    			
    				dz.devices(dev_rain1h).updateCustomSensor(h1PrecipExpectation)
    				dz.devices(dev_rain12h).updateCustomSensor(h12PrecipExpectation)
    			    dz.devices(dev_rain24h).updateCustomSensor(h24PrecipExpectation)
                    if debug==1 then
    			        print('h1PrecipExpectation rounded:  ' .. h1PrecipExpectation)
    			        print('h12PrecipExpectation rounded: ' .. h12PrecipExpectation)
    			        print('h24PrecipExpectation rounded: ' .. h24PrecipExpectation)
    				end
            		if nillCount == 0 and nillCountH == 0 then
                        dz.log('Meteo Dark Sky end OK', dz.LOG_FORCE)
                        else dz.log('Meteo Dark Sky end KO : ' .. nillCount .. ' / ' .. nillCountH, dz.LOG_ERROR) -- number of values not present in the jason
                    end
                        else dz.log('NO JSON ???' , dz.LOG_ERROR)
        		end
        		    else dz.log('Response KO !!!' , dz.LOG_ERROR)
            end
                else dz.log('Error triggerObject !!!' , dz.LOG_ERROR)
        end
    end
}


Last edited by hestia on Sunday 10 March 2019 22:49, edited 2 times in total.
RapTile
Posts: 53
Joined: Saturday 10 March 2018 2:01
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: dzVents version of the Solar Data Script

Post by RapTile »

hestia wrote: Tuesday 13 November 2018 23:40 <..>
Hi,
I've writen a DzVents script to get values from DarkSky, with pressure and cloud cover => all put in dz device
It works fine except for the rain because rain sensors are a strange thing in Domoticz - I work on it when I time and when it's raining ;-)
I also have rain expectation for the next 1h, 12 and 24h (for a future watering system)
This could be a start to split the datasources from the algorithm

<..>
The logs tells me:

Code: Select all

2018-11-16 11:20:02.070 Status: dzVents: Error (2.4.8): :Meteo: Method updateCustomSensor is not available for device "CloudCover" (deviceType=General, deviceSubType=Percentage). If you believe this is not correct, please report.
2018-11-16 11:20:02.078 Status: dzVents: Error (2.4.8): :Meteo: Method updateCustomSensor is not available for device "Rain 1h" (deviceType=Rain, deviceSubType=TFA). If you believe this is not correct, please report.
2018-11-16 11:20:02.079 Status: dzVents: Error (2.4.8): :Meteo: Method updateCustomSensor is not available for device "Rain 12h" (deviceType=Rain, deviceSubType=TFA). If you believe this is not correct, please report.
2018-11-16 11:20:02.081 Status: dzVents: Error (2.4.8): :Meteo: Method updateCustomSensor is not available for device "Rain 24h" (deviceType=Rain, deviceSubType=TFA). If you believe this is not correct, please report.
The idx details are correct for my devices.
hestia
Posts: 357
Joined: Monday 25 December 2017 23:06
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.1
Location: Paris
Contact:

Re: dzVents version of the Solar Data Script

Post by hestia »

RapTile wrote: Friday 16 November 2018 11:23
hestia wrote: Tuesday 13 November 2018 23:40 <..>
Hi,
I've writen a DzVents script to get values from DarkSky, with pressure and cloud cover => all put in dz device
It works fine except for the rain because rain sensors are a strange thing in Domoticz - I work on it when I time and when it's raining ;-)
I also have rain expectation for the next 1h, 12 and 24h (for a future watering system)
This could be a start to split the datasources from the algorithm

<..>
The logs tells me:

Code: Select all

2018-11-16 11:20:02.070 Status: dzVents: Error (2.4.8): :Meteo: Method updateCustomSensor is not available for device "CloudCover" (deviceType=General, deviceSubType=Percentage). If you believe this is not correct, please report.
2018-11-16 11:20:02.078 Status: dzVents: Error (2.4.8): :Meteo: Method updateCustomSensor is not available for device "Rain 1h" (deviceType=Rain, deviceSubType=TFA). If you believe this is not correct, please report.
2018-11-16 11:20:02.079 Status: dzVents: Error (2.4.8): :Meteo: Method updateCustomSensor is not available for device "Rain 12h" (deviceType=Rain, deviceSubType=TFA). If you believe this is not correct, please report.
2018-11-16 11:20:02.081 Status: dzVents: Error (2.4.8): :Meteo: Method updateCustomSensor is not available for device "Rain 24h" (deviceType=Rain, deviceSubType=TFA). If you believe this is not correct, please report.
HI
sorry my comments in the script were not very accurate. I've changed them
So
local dev_rain1h = youridx -- dummy receive 1h expected rain in mm / Custom (mm)
local dev_rain12h = youridx -- dummy receive 12h expected rain in mm / Custom (mm)
local dev_rain24h = youridx -- dummy receive 24h expected rain in mm / Custom (mm)
local dev_cloudCover = youridx -- dummy receive cloudCover / SubType Custom Sensor (no unit, I put a / in the unit besause it is mandatory)

=> all this sensors are custom to summarize !

(for the last one I choose custom to be able to change the icon, I could not on a % type ; you could choose % as a unit and multiple by 100 if you want )

Hope this help!
RapTile
Posts: 53
Joined: Saturday 10 March 2018 2:01
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: dzVents version of the Solar Data Script

Post by RapTile »

hestia wrote: Friday 16 November 2018 11:54 <..>

HI
sorry my comments in the script were not very accurate. I've changed them
So
local dev_rain1h = youridx -- dummy receive 1h expected rain in mm / Custom (mm)
local dev_rain12h = youridx -- dummy receive 12h expected rain in mm / Custom (mm)
local dev_rain24h = youridx -- dummy receive 24h expected rain in mm / Custom (mm)
local dev_cloudCover = youridx -- dummy receive cloudCover / SubType Custom Sensor (no unit, I put a / in the unit besause it is mandatory)

=> all this sensors are custom to summarize !

(for the last one I choose custom to be able to change the icon, I could not on a % type ; you could choose % as a unit and multiple by 100 if you want )

Hope this help!
Sorry, i don't understand your comment.

The values in the script are:
local dev_rain1h = 105 -- dummy receive 1h expected rain in mm / Type Rain -> Custom (mm)
local dev_rain12h = 106 -- dummy receive 12h expected rain in mm / Type Rain -> Custom (mm)
local dev_rain24h = 107 -- dummy receive 24h expected rain in mm / Type Rain -> Custom (mm)

All 3 are Dummy devices and the sensor type are set to Rain sensor.
hestia
Posts: 357
Joined: Monday 25 December 2017 23:06
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.1
Location: Paris
Contact:

Re: dzVents version of the Solar Data Script

Post by hestia »

RapTile wrote: Friday 16 November 2018 12:07
hestia wrote: Friday 16 November 2018 11:54 <..>

HI
sorry my comments in the script were not very accurate. I've changed them
So
local dev_rain1h = youridx -- dummy receive 1h expected rain in mm / Custom (mm)
local dev_rain12h = youridx -- dummy receive 12h expected rain in mm / Custom (mm)
local dev_rain24h = youridx -- dummy receive 24h expected rain in mm / Custom (mm)
local dev_cloudCover = youridx -- dummy receive cloudCover / SubType Custom Sensor (no unit, I put a / in the unit besause it is mandatory)

=> all this sensors are custom to summarize !

(for the last one I choose custom to be able to change the icon, I could not on a % type ; you could choose % as a unit and multiple by 100 if you want )

Hope this help!
Sorry, i don't understand your comment.

The values in the script are:
local dev_rain1h = 105 -- dummy receive 1h expected rain in mm / Type Rain -> Custom (mm)
local dev_rain12h = 106 -- dummy receive 12h expected rain in mm / Type Rain -> Custom (mm)
local dev_rain24h = 107 -- dummy receive 24h expected rain in mm / Type Rain -> Custom (mm)

All 3 are Dummy devices and the sensor type are set to Rain sensor.
ocal dev_rain1h = 105 -- dummy receive 1h expected rain in mm / Custom (mm) =>> not rain type but custom type
local dev_rain12h = 106 -- dummy receive 12h expected rain in mm / Custom (mm) =>> not rain type but custom type
local dev_rain24h = 107 -- dummy receive 24h expected rain in mm / Custom (mm) =>> not rain type but custom type
RapTile
Posts: 53
Joined: Saturday 10 March 2018 2:01
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: dzVents version of the Solar Data Script

Post by RapTile »

oredin wrote: Saturday 27 October 2018 20:34 <..>
The script is avaiblable at https://github.com/russandol-sarl/dz-solarData.

Feel free to share ! If you have any improvements in mind, you can tell me and I'll see what I can do.
You did an awesome job, thanks!
But, there is something wrong with the script or i made a mistake myself implementing it.

Currently it is cloudy in the netherlands and the current indicated Lux value 13370.

The Lux wiki tells me that a clouded day is around 1000 Lux.
So 1337 Lux should be very cloudy ;-)

I think the "0" in the end should not exist or i made a mistake with the script and idx values but i've checked them three times so far so i don't know how i could do something wrong..
RapTile
Posts: 53
Joined: Saturday 10 March 2018 2:01
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: dzVents version of the Solar Data Script

Post by RapTile »

hestia wrote: Friday 16 November 2018 12:09 <..>
ocal dev_rain1h = 105 -- dummy receive 1h expected rain in mm / Custom (mm) =>> not rain type but custom type
local dev_rain12h = 106 -- dummy receive 12h expected rain in mm / Custom (mm) =>> not rain type but custom type
local dev_rain24h = 107 -- dummy receive 24h expected rain in mm / Custom (mm) =>> not rain type but custom type
Ok, thanks for the info!

What settings do u use for cloudcover?
Because i still receive the following error message:

Meteo: Method updateCustomSensor is not available for device "CloudCover" (deviceType=General, deviceSubType=Percentage). If you believe this is not correct, please report.
RapTile
Posts: 53
Joined: Saturday 10 March 2018 2:01
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: dzVents version of the Solar Data Script

Post by RapTile »

For some reason i can not get this to work properly.
What am i doing wrong?

Code: Select all

local countryCode = 'NL'                              -- Only for log purpose
local idxSolarAzimuth = 97                          -- (Integer) Virtual Azimuth Device ID
local idxSolarAltitude = 98                          -- (Integer) Your virtual Solar Altitude Device ID
local dsAPIkey = '5eba2XXXXXXXXXXXX1'      -- Dark Sky API Key
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 fetchIntervalDayMins = 15                  -- Day time scraping interval. Never set this below 4 if you have a free WU API account.
local fetchIntervalNightMins = 30                -- Night time scraping interval. 

-- Optional Domoticz devices
local idxLux = 100 -- (Integer) Domoticz virtual Lux device ID
local idxCloudCover = 99 -- (Integer) Domoticz Cloud Cover (PERCENTAGE TYPE) sensor device ID
local idxPressure = nil -- (Integer) Your Pressure Device ID. if you don't have one, the pressure value will be retrieve from Dark Sky API

-- (You don't have to configure these if you accept the values returned by the weather observation station)
local latitude = 52.3389926	-- Latitude. (Decimal number) Decimal Degrees. E.g. something like 51.748485
local longitude = 4.9591888	-- Longitude. (Decimal number) Decimal Degrees. E.g.something like 5.629728.
local altitude = -1	-- Altitude. (Integer) Meters above sea level.
The amount of Lux can't be correct...
Attachments
Screen Shot 2018-11-16 at 13.52.06.png
Screen Shot 2018-11-16 at 13.52.06.png (46.78 KiB) Viewed 4023 times
hestia
Posts: 357
Joined: Monday 25 December 2017 23:06
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.1
Location: Paris
Contact:

Re: dzVents version of the Solar Data Script

Post by hestia »

RapTile wrote: Friday 16 November 2018 13:33
hestia wrote: Friday 16 November 2018 12:09 <..>
ocal dev_rain1h = 105 -- dummy receive 1h expected rain in mm / Custom (mm) =>> not rain type but custom type
local dev_rain12h = 106 -- dummy receive 12h expected rain in mm / Custom (mm) =>> not rain type but custom type
local dev_rain24h = 107 -- dummy receive 24h expected rain in mm / Custom (mm) =>> not rain type but custom type
Ok, thanks for the info!

What settings do u use for cloudcover?
Because i still receive the following error message:

Meteo: Method updateCustomSensor is not available for device "CloudCover" (deviceType=General, deviceSubType=Percentage). If you believe this is not correct, please report.
device "CloudCover" => General Custom Sensor /!\ not a % device
after in the axis of the custom sensor you put what you want, there is no unit for the cloud sensor
Locked

Who is online

Users browsing this forum: No registered users and 0 guests