Page 2 of 13

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

Posted: Monday 15 February 2016 22:43
by latis
Hi,
Yes, I have read the script, might it be that my location is something error in?
I did change that line you mentioned to reflect my linux setup.

relativePressure = jsonLocation.current_observation.pressure_mb <--- thats line 64.

//Latis

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

Posted: Tuesday 16 February 2016 8:55
by latis
I fixed it, it was my position which was erroneous. After changing that, everything works. Now lets hope domoticz can get an addition of dummy solar radiation. :)

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

Posted: Tuesday 16 February 2016 13:21
by stefanvn
Hi Guys,

How do you use the solar radiation in other scripts? I.e. How to read the value and switch lights on/off based on the amount of Lux?

I have tried numerous things, but I keep failing in using the lux value in another script.

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

Posted: Monday 22 February 2016 14:19
by Doler
stefanvn wrote:Hi Guys,

How do you use the solar radiation in other scripts? I.e. How to read the value and switch lights on/off based on the amount of Lux?

I have tried numerous things, but I keep failing in using the lux value in another script.
Using lua you can read the lux value from the virtual device you created:

Code: Select all

lux = tonumber(otherdevices_svalues['the name of your virtual device'])
With this value you can e.g. switch a lamp on when the lux value is below a certain threshold.

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

Posted: Saturday 19 March 2016 10:06
by jmleglise
Hi everyone,

Did you notice ? All our wishes have come true :-)
Since beta #4937 the Virtual sensor "custom type" allows us to choose the unit label (and the icon) we want.
So, use it for Sun Azimuth and Sun altitude. Y axis = "deg" and then edit it again in the dashboard to choose the icon you want.

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

Posted: Tuesday 29 March 2016 23:26
by marmachine
stefanvn wrote:Still not working....I'm getting a bit frustrated. Seems to me that I'm missing something obvious or something.

* print(otherdevices_svalues['Lux']): same error message (attempt to index global 'otherdevices_svalues' (a nil value)).
* Removed Lux device and re-created a new dummy Lux device: Device gets updated with Luxvalue, but print(otherdevices_svalues['Lux']) still gives the same error message.

Seems to me that it shouldn't be that hard to retrieve such a value, but apparently it is too difficult for me ;-)

I would love to get some more hints and tips, in order to get this working.
As i was running into the same error i went down to find the bug... and guess what, i think i've solved it!
I am under the impression that, even while Domoticz shows 0 lux right when you create the virtual device, that doesn't mean it really has a value.
Basically that is exactly what the error tell's you, it has no value (= 'nil')

Anyway, a workaround would be to set a value to it first, value 0 will be just fine.

see if this helps; place the following code above the line where the Lux value is first used

Code: Select all

       if (DEBUG == 1) then
          if (otherdevices_svalues['Lux']) then
             print("| Value of device Lux was: "..otherdevices_svalues['Lux'].." Lux")
          else
             -- apparently the device doesn't have a value, without this test it would return an error, so we set it's value to 0
             -- this will happen just the first time when you setup your (virtual) device
             otherdevices_svalues['Lux'] = 0
          end
        end
        
        --------------------------------
        -- ---> find the below line in the original script, place the above code here, so right above the below line in the original script
        -- ---> then first run the script in 'debug' mode to set the value
        --------------------------------

        -- No update if Lux is already 0. So lastUpdate of the sensor switch will keep the time of day when Lux has reached 0.

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

Posted: Wednesday 30 March 2016 10:17
by Xroads
In the installation instructions in the WIKI, it's stated that the lux device should be defined as "Virtual sensor LUX : sensor type LUX, name LUX."
This is not correct, it should be "Virtual sensor LUX : sensor type LUX, name Lux." Otherwise you will get the above mentioned error.

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

Posted: Thursday 31 March 2016 19:47
by jmleglise
Hi,

My bad. You 're right... Of course the sensor must be named the same way that your script ...
As the script use the name "Lux", I correct the wiki with "Lux".

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

Posted: Thursday 31 March 2016 19:58
by jmleglise
By the way, did you notice that I have updated the script in the wiki ?
I have modify this part at the end :

Code: Select all

if tonumber(otherdevices_svalues['Lux'])+round(weightedLux,0)>0   -- No update if Lux is already 0. So lastUpdate of the sensor Lux 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
So in your script_time you can use a condition like this :

Code: Select all

if tonumber(otherdevices_svalues['Lux'])==0 and timedifference(otherdevices_lastupdate['Lux'])<=60 
This is usefull to activate something when the Lux reach 0. As easy as you used before : if minutes == (timeofday['SunriseInMinutes']

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

Posted: Thursday 07 April 2016 21:59
by assenzuid
I'm missing something.....

I get below errors

2016-04-07 21:50:00.384 Error: EventSystem: in /home/pi/domoticz/scripts/lua/script_time_SolarSensor.lua: /home/pi/domoticz/scripts/lua/script_time_SolarSensor.lua:56: attempt to call a nil value
2016-04-07 21:50:00.557 Error: EventSystem: in real-time solar data: [string "--[[ Virtual Lux sensor and other real-t..."]:56: attempt to call a nil value
2016-04-07 21:50:01.750 Error: EventSystem: in real-time solar data: [string "--[[ Virtual Lux sensor and other real-t..."]:56: attempt to call a nil valu

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

Posted: Friday 22 April 2016 12:23
by marmachine
Hi,

It was actually working like a charm!
I'm also using the WU API call to update virtual weather devices, still having issues on setting Wind, Rain and UV through UpdateDevice command though. Anyway, now i also have an error in my log and i can't really find direction here as well?

2016-04-22 12:07:03.584 LUA: | curl "http://www.ogimet.com/cgi-bin/getsynop? ... 1604220900"
2016-04-22 12:07:03.704 Error: EventSystem: in Virtual Lux sensor: [string "--[[ Virtual Lux sensor and other real-t..."]:498: bad argument #1 to 'gsub' (string expected, got nil)

498 relates to the line in below code --> Trame = string.gsub(rslt[2], "=", "")

Code: Select all

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

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

Posted: Friday 22 April 2016 16:20
by paulD
Hi guys,

If you want some help, I advise to you to give more debug information ! ( like print variable ...)

@assenzuid : what is your line 56 ?

@marmachine : The rslt is null, and it came from synop. So what is the value of synop ? print the synop variable with that :

Code: Select all

if string.find(synop,"Status: 500") == nil
       then
          print("rslt:"..synop)
          rslt = split(synop,",")

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

Posted: Friday 22 April 2016 17:01
by marmachine
Thanks!

I did check the curl cmd; copied and paste it into a browser window, but didn't return me anything actually (and now it does)
So i think that there was an issue with ogimet.com this morning, right now it's working like a charm as it did before.

To answer your question, synop now prints the following to my log (and this is similar to what i get to see when copy/paste the curl cmd into a browser)
rslt:06260,2016,04,22,13,00,AAXX 22131 06260 07678 80504 10116 20035 30200 40204 57017 60005 702// 88/// 333 541// 55/// 21952 553// 23600 60005 82/35 88/61 90710 91006 91107=
06260,2016,04,22,14,00,AAXX 22141 06260 07674 80304 10115 20035 30194 40197 58017 60005 702// 88/// 333 541// 55/// 21823 553// 23200 60005 82/35 88/58 90710 91008 91108=

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

Posted: Saturday 23 April 2016 10:19
by jmleglise
Hi, I have noticed that between 0h and 2h, (french time) ogimet return nothing. It's the aim of the check of 'status 500'. But Maybe there are other return status to check ? If your problem occurs again, could you publish here the data send by ogimet ?

I will add a new check of rslt == Nil to avoid your problem.

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

Posted: Friday 29 April 2016 9:32
by MikeF
I may be missing something obvious, but I can't find sensor type = custom when I try to create virtual sensors Sun Altitude and Sun Azimuth. I'm using beta v3.5065.

Any clues?

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

Posted: Friday 29 April 2016 10:12
by marmachine
@MikeF
I remember that i came across the same issue, i am using type "visibility", with the side effect that it add's Km (or miles) to the value, which should actualy be Degrees, never the less it works! By the way; i'm on v3.4834 (and Domoticz is telling me there is no update available)

You probably have read this earlier post;
Since beta #4937 the Virtual sensor "custom type" allows us to choose the unit label (and the icon) we want.
So, use it for Sun Azimuth and Sun altitude. Y axis = "deg" and then edit it again in the dashboard to choose the icon you want.
Cheers

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

Posted: Friday 29 April 2016 13:36
by MikeF
OK, I'll try that - but it would be nice to display in degrees...

If you go to Setup > Settings, make sure that Software Updates Release Channel is set to Beta. Then in Terminal (or whatever), go to your domoticz folder (e.g., cd ~/domoticz on a Mac / Linux machine), and type this:

Code: Select all

./updatebeta

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

Posted: Saturday 30 April 2016 0:16
by MikeF
OK, so I've now got this working, by applying @marmachine's fix to get around the problem where virtual device 'Lux' doesn't have a value when first created, and also by saving the JSON.lua library in the lua folder - this needs to be mentioned in the wiki.

As I can't create custom type virtual sensors, I've used visibility instead - does 'degrees' equate to kilometres or miles (obviously there's a conversion factor - approx. 1.6)?

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

Posted: Sunday 01 May 2016 11:31
by marmachine
Hi MikeF,
I've set mine to km's and Azimuth shows values between 0-359 (representing the sun's clockwise position in degrees)

I haven't tested, but i assume there is no conversion done in Domoticz when you change km's to miles... it is just added as measurement label, but doesn't bother the value itself because that depends on the actual input.

by the way: thanks for the "Software Updates Release Channel", i think i'll stay with official releases though... i have only one (production) system.

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

Posted: Sunday 01 May 2016 12:33
by jmleglise
It's too bad you haven't the new custom sensor which was created specially for this case. I have updated the wiki with screenshot. It's work fine with V 3.4951

If you are sure of you, you should consider open a bug report ?