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

Moderator: leecollings

latis
Posts: 5
Joined: Thursday 31 October 2013 16:42
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

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

Post 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
latis
Posts: 5
Joined: Thursday 31 October 2013 16:42
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

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

Post 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. :)
stefanvn
Posts: 5
Joined: Saturday 06 February 2016 10:02
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

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

Post 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.
Doler
Posts: 142
Joined: Friday 31 July 2015 21:02
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Sint-Oedenrode, Netherlands
Contact:

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

Post 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.
Mark: Domoticz Beta on Raspberry Pi 4 running Debian Bookworm - Z-Stick 7 - RFXCom - P1 - MySensors - SolarEdge - Dahua - Philips Hue - Docker - Zigbee2mqtt (plugin) - Zwave-js-ui - dzVents - Nodered
jmleglise
Posts: 192
Joined: Monday 12 January 2015 23:27
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.1
Location: FRANCE
Contact:

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

Post 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.
My script : https://github.com/jmleglise
RFXTRX433E: Blind Somfy RTS, Portal Somfy Evolvia, chacon IO, Oregon, PIR sensor PT2262
My Last project : Location de maison de vacances a Ouistreham vue mer
KMTronic USB relay
Chinese Z-WAVE: Neo CoolCam
marmachine
Posts: 128
Joined: Saturday 26 March 2016 10:19
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.4834
Location: Netherlands
Contact:

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

Post 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.
Xroads
Posts: 30
Joined: Thursday 25 February 2016 10:43
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

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

Post 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.
Raspberry pi 2
Razberry z-wave module with Fibaro dimmer, relay and pir and Dlink pir.
433mhz RFlink with 5 pcs. on/off switches
jmleglise
Posts: 192
Joined: Monday 12 January 2015 23:27
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.1
Location: FRANCE
Contact:

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

Post 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".
Last edited by jmleglise on Thursday 31 March 2016 19:59, edited 1 time in total.
My script : https://github.com/jmleglise
RFXTRX433E: Blind Somfy RTS, Portal Somfy Evolvia, chacon IO, Oregon, PIR sensor PT2262
My Last project : Location de maison de vacances a Ouistreham vue mer
KMTronic USB relay
Chinese Z-WAVE: Neo CoolCam
jmleglise
Posts: 192
Joined: Monday 12 January 2015 23:27
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.1
Location: FRANCE
Contact:

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

Post 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']
My script : https://github.com/jmleglise
RFXTRX433E: Blind Somfy RTS, Portal Somfy Evolvia, chacon IO, Oregon, PIR sensor PT2262
My Last project : Location de maison de vacances a Ouistreham vue mer
KMTronic USB relay
Chinese Z-WAVE: Neo CoolCam
assenzuid
Posts: 135
Joined: Friday 13 November 2015 9:11
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: The Netherlands, Emmen Area
Contact:

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

Post 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
marmachine
Posts: 128
Joined: Saturday 26 March 2016 10:19
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.4834
Location: Netherlands
Contact:

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

Post 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
paulD
Posts: 16
Joined: Wednesday 20 January 2016 14:46
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

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

Post 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,",")
marmachine
Posts: 128
Joined: Saturday 26 March 2016 10:19
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.4834
Location: Netherlands
Contact:

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

Post 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=
jmleglise
Posts: 192
Joined: Monday 12 January 2015 23:27
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.1
Location: FRANCE
Contact:

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

Post 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.
My script : https://github.com/jmleglise
RFXTRX433E: Blind Somfy RTS, Portal Somfy Evolvia, chacon IO, Oregon, PIR sensor PT2262
My Last project : Location de maison de vacances a Ouistreham vue mer
KMTronic USB relay
Chinese Z-WAVE: Neo CoolCam
MikeF
Posts: 350
Joined: Sunday 19 April 2015 0:36
Target OS: Raspberry Pi / ODroid
Domoticz version: V2022.2
Location: UK
Contact:

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

Post 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?
marmachine
Posts: 128
Joined: Saturday 26 March 2016 10:19
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.4834
Location: Netherlands
Contact:

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

Post 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
MikeF
Posts: 350
Joined: Sunday 19 April 2015 0:36
Target OS: Raspberry Pi / ODroid
Domoticz version: V2022.2
Location: UK
Contact:

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

Post 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
MikeF
Posts: 350
Joined: Sunday 19 April 2015 0:36
Target OS: Raspberry Pi / ODroid
Domoticz version: V2022.2
Location: UK
Contact:

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

Post 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)?
marmachine
Posts: 128
Joined: Saturday 26 March 2016 10:19
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.4834
Location: Netherlands
Contact:

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

Post 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.
jmleglise
Posts: 192
Joined: Monday 12 January 2015 23:27
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.1
Location: FRANCE
Contact:

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

Post 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 ?
My script : https://github.com/jmleglise
RFXTRX433E: Blind Somfy RTS, Portal Somfy Evolvia, chacon IO, Oregon, PIR sensor PT2262
My Last project : Location de maison de vacances a Ouistreham vue mer
KMTronic USB relay
Chinese Z-WAVE: Neo CoolCam
Locked

Who is online

Users browsing this forum: No registered users and 1 guest