Lightning and Domoticz

Subforum for general discussions. Do not dump your questions/problems here, but try to find the subforum where it belongs!
elmortero
Posts: 227
Joined: Sunday 29 November 2015 21:46
Target OS: Raspberry Pi
Domoticz version: 3.9639
Location: Spain
Contact:

Re: Lightning and Domoticz

Post by elmortero » Wednesday 30 May 2018 12:00

Hi,

Is there a way to parse parameters to http://www.onweeractueel.nl/domoticz_bo.json ?
I wrote a script in dzvents for this but sometimes the json result is too large (which returns "lua script execution exceeded maximum number of lines")

What would be great, if possible, is to send a parameter with max/min LAT and LON so that the number of results gets lower.

For those interested in my dzvents version:

Code: Select all

 
 return {
	on = {
		timer = { 'every 15 minutes' },
		httpResponses = { 'blitz' } -- matches callback string below
	},
        data = {
            last = { initial = 0 }
        },
	
	execute = function(domoticz, triggerItem)
	   local lightning = domoticz.devices('Bliksemteller')
	   local preLight = tonumber(lightning.rawData[1])

		distance = function(lat1, lng1, lat2, lng2)
		radius = 6371
		dLat = (lat2 - lat1) * math.pi / 180
		dLng = (lng2 - lng1) * math.pi / 180
		lat1 = lat1 * math.pi / 180
		lat2 = lat2 * math.pi / 180
		val = math.sin(dLat / 2) * math.sin(dLat / 2) + math.sin(dLng / 2) * math.sin(dLng / 2) * math.cos(lat1) * math.cos(lat2)
		ang = 2 * math.atan2(math.sqrt(val), math.sqrt(1 - val))
		return radius * ang
		end
		
		local latHome = 00.000000  --replace with your own coordenates
		local lngHome = 00.000000  --replace with your own coordenates
		local distanceRange = 20    --change to the maximum distance you want for filtering (in KMs)
		local last = tonumber(domoticz.data.last)
		if (triggerItem.isTimer) then
			domoticz.openURL({
				url = 'https://www.onweeractueel.nl/domoticz_bo.json',
				method = 'GET',
				callback = 'blitz'
			})
		elseif (triggerItem.isHTTPResponse) then

	local response = triggerItem
		if (response.ok and response.isJSON) then
			local value = 0
			local ignored = 0
			tl = #response.json
			tc = 1
			repeat
			local times = tonumber(response.json[tc][1])
			local lat = tonumber(response.json[tc][2])
			local lng = tonumber(response.json[tc][3])
			local distanceBetween = distance(latHome, lngHome, lat, lng)
			 if (distanceBetween <= distanceRange) then
				if (times > last) then
				 value = value + 1
				else
				 value = 0
				end
			  domoticz.data.last = times
			 end
			tc = tc + 1
			until tc > tl
			print('Blitz Value = '..value)
			if value ~= preLight then
			lightning.updateCustomSensor(value)
	        end
			else
				print('**blitz failed to fetch info')
			end
		end
	end
}
 

FrankVZ
Posts: 35
Joined: Sunday 27 May 2018 12:01
Target OS: -
Domoticz version:
Contact:

Re: Lightning and Domoticz

Post by FrankVZ » Friday 01 June 2018 16:06

I think we're gonna die.
Look at the results of the lightning strikes with the data and script as mentioned before and get no errors as far as I know.

The amount of strikes (running script every 10 mins for a range of 15 km):
DateTime Series 1
31-05-2018 15:00 0,00
31-05-2018 16:00 4,00
31-05-2018 17:00 18446744073709500000,00
31-05-2018 18:00 0,00
31-05-2018 19:00 0,00
31-05-2018 20:00 0,00
31-05-2018 21:00 0,00
31-05-2018 22:00 0,00
31-05-2018 23:00 0,00
01-06-2018 00:00 0,00
01-06-2018 01:00 0,00
01-06-2018 02:00 0,00
01-06-2018 03:00 0,00
01-06-2018 04:00 0,00
01-06-2018 05:00 0,00
01-06-2018 06:00 0,00
01-06-2018 07:00 0,00
01-06-2018 08:00 0,00
01-06-2018 09:00 0,00
01-06-2018 10:00 0,00
01-06-2018 11:00 0,00
01-06-2018 12:00 0,00
01-06-2018 13:00 0,00
01-06-2018 14:00 1,00
01-06-2018 15:00 18446744073709500000,00


The same script (I gave it another name), and running at a lower refresh rate (2x/hr for 30 km)
31-05-2018 15:00 0,00
31-05-2018 16:00 37,00
31-05-2018 17:00 18446744073709500000,00
31-05-2018 18:00 0,00
31-05-2018 19:00 0,00
31-05-2018 20:00 0,00
31-05-2018 21:00 0,00
31-05-2018 22:00 0,00
31-05-2018 23:00 0,00
01-06-2018 00:00 0,00
01-06-2018 01:00 0,00
01-06-2018 02:00 0,00
01-06-2018 03:00 0,00
01-06-2018 04:00 0,00
01-06-2018 05:00 0,00
01-06-2018 06:00 0,00
01-06-2018 07:00 0,00
01-06-2018 08:00 0,00
01-06-2018 09:00 0,00
01-06-2018 10:00 0,00
01-06-2018 11:00 0,00
01-06-2018 12:00 0,00
01-06-2018 13:00 0,00
01-06-2018 14:00 0,00
01-06-2018 15:00 0,00


Well, are we going to survive? :)

It looks like the misreading occurs, with the first reading after a successful/correct reading.

Someone knows what causes these strange amounts?

User avatar
EdwinK
Posts: 1239
Joined: Sunday 22 January 2017 22:46
Target OS: Raspberry Pi
Domoticz version: BETA
Location: Rhoon
Contact:

Re: Lightning and Domoticz

Post by EdwinK » Saturday 02 June 2018 20:54

EdwinK wrote:
Tuesday 29 May 2018 20:20
Getting the script from Phoenixblue's git page made it work again.

Hmm.. Not really. Still doesn't update the counter :(

Tried with creating another counter, but still no updating :(
Running latest BETA on a Pi-3 | Toon Thermostat | RFxcom | Dashticz V2 |

FrankVZ
Posts: 35
Joined: Sunday 27 May 2018 12:01
Target OS: -
Domoticz version:
Contact:

Re: Lightning and Domoticz

Post by FrankVZ » Thursday 07 June 2018 22:38

Well, a small update: in my case it is updating, but on regular basis the huge error (18 * 10^18 number)

The script starts in my case by the synology task manager (running the python script from there). It has a big advantage: if Domoticz is down (crashed last two days at midnight for some reason) I instantly get notified by the synology that is still brave doing what it has to do.
So that is nice,

but the huge number error is still strange.
But today I also find out, while testing another counter, the same error occurs.
I tested the json command in order to set a new value into the counter with
http://<myip>:<myport>/json.htm?type=command&param=udevice&idx=<mycounter>&svalue=200

It just should put the number 200 into the counter, but got 18*18^10 instead.

So it wouldn't surprise me if the behaviour /bug is coming from the counter function within Domoticz it selves, instead of the script created by Phoenixblue or the sources it uses (the API).
It is quite buggy anyway, because the graph only shows the last 10 hours, but the header says 24hrs :)
Counter errors.jpg
Counter errors.jpg (63.02 KiB) Viewed 465 times
Question is of course: how to solve this issue?
Al lot of people should experience counter errors in that case?
Or is it the interpreter between json <-> DZ where is goes wrong?

assenzuid
Posts: 165
Joined: Friday 13 November 2015 10:11
Target OS: Raspberry Pi
Domoticz version: Beta
Location: The Netherlands, Emmen Area
Contact:

Re: Lightning and Domoticz

Post by assenzuid » Thursday 09 August 2018 16:49

Today I noticed the script is not working.
I use the script at page 3 of this topic.

Code: Select all

Traceback (most recent call last):
  File "lightning.py", line 76, in <module>
    for pos in data:
TypeError: 'NoneType' object is not iterable

User avatar
phoenixblue
Posts: 78
Joined: Friday 25 November 2016 12:20
Target OS: Raspberry Pi
Domoticz version: 3.7392
Contact:

Re: Lightning and Domoticz

Post by phoenixblue » Thursday 09 August 2018 16:58

Hi,
This is correct, there are some import problems from the main server in Germany.
Unfortunately this part must be solved from external.

When the import is back working I will let it know.


Verstuurd vanaf mijn EML-L29 met Tapatalk

scripts on github: Link

SweetPants
Posts: 2167
Joined: Friday 12 July 2013 21:24
Target OS: Linux
Domoticz version: V4.9866
Location: The Netherlands
Contact:

Re: Lightning and Domoticz

Post by SweetPants » Friday 10 August 2018 9:19

I have data again since aug 9 16:00, and some lightning strikes where discovered.
Ubuntu 16.04.3 LTS, Intel NUC, MySensors 2.3.0-alpha, Pro Mini 3.3/8M RFM69(HW), ESP8266 (SDK2.2.0), Sonoff, RFLink, RFXcom, MQTT, NodeRed, Domoticz Beta (from source)

Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests