mrk-its / homeassistant-blitzortung

Custom Component for fetching lightning data from blitzortung.org
MIT License
215 stars 41 forks source link

Blitzortung no longer works after updating Home Assistant #49

Closed K5OZ closed 2 years ago

K5OZ commented 2 years ago

Hello, My Blitzortung no longer works after updating Home Assistant to the latest revision 2022.4.5. I was on a revision from 2021.11.1. All I get now is 0 in the counter and Unknown in the distance and Azimuth with lightning all around my location (within 100KM). I reverted back to the 2021.11.1 backup; however, no luck in getting it working again.

Was there something I missed during the update? I see other like issues on this board, but no answers on what to fix. Can someone help me get it back working again? Thanks, Dave

1-am-r00t commented 2 years ago

@mrk-its

the developers from Blitzortung seem to have changed their WebSocket.

  1. before the latest change, it's been tcp/3000 to send/receive data - now it's using plain HTTPS (443).
  2. they changed the required initial JSON response, which the client must send to {"a":542}
  3. they started obfuscating/encoding the data, see this example: {"time":1649868278408932900,"latĆ33.447719ělonĆ-94.3ĕ602ěalğ:Ě"polĆĽmdsĆĥ34ěmcgĆ25Ŋ"stĞuņļěregiĬĠěsiŎ:[ĀŔaŏ155ěĂĄŇ4ʼn9őĪĞĠ7IJ746ūĪş:-80.521ƇĸĺĆ1183šŕtŗƌ2},ŧŕŏŲĽůą:Ĥ72ĒŒĝĻ36.Ż810ƥƀ-ƭ8.ďƎŲƊĻĈ88ƑŖŘ4Ɨƙũć75ƝăƟż31ż1ŶĻ45IJ3706ƐĜưĔģ8ő97ƸŇ66ƽƓŘƈǁœƚćƻƼāLjǢij9žĜŷ:3ǒǣ26ĐſĭƁ79IJżĘĩ"Ĺƹ7ǤǪƾŇǩŨŏ5ħŮǰƠ6İġȆƦŏƩčǝ9Țǚ2.Ķǝ4ķȇƋ:ǮŨǦƕȏǫƭčȔŰƠĦŴ2ȨțǷȂ0ħġǎǙǿƱēƅęǗǘȈƌ4njǥƔ:ƖƘȌƌ1ĦȴljĐƭŐǏŇǒij6ȒȋīɃƻ.ƈĤ1ɉȪ2ĔɎǧ0Ȱǃėɛǯȵ4đ5ĵǠǵĻǻƴĨĕǘɣĮƬƪŲɩŒɊćǘȭɏǀɒȐɐ0ǴƞŇİɹ5ȚǶĤģ7ijȾǾĮƭĢƬNJȋʊƈ0Ȇʍƿɱȑ2LJȵdžĖėɢǶijɦȗČǮʃȀƳǟǟƨǡǷNjɮȎʐȱǣʱƟ5ƍĉɹɜǷŹĘʼnŭɂĮĐIJȾǖǮʨėˆćɑǂȑɕɗĆƆȁ3ʠɼĠȣɌĨʂưƍƄȠĥǣ˃ƏŒʬˇˣćƮȨʕ:őƭĥ˖ȻġģƮĊ̆˲ƍƅ9Ǽĉ˃ɷȨ˻ɐʮɐǸɁ́ő53ČɁ̇Ƚċ˪ȡɃĦƅȹǖʉȪƲˠǨˈǃnjˍ˦̂ǑɹȊˑ̟.ƬĎŴʡȀŹɌċđ˃̮ȌȮˡ̘ǻɭɵˌŻǻ˪ˑɷģĤʓȺǚȂġɬĕ˃ďɻ̖̰˽ėǸ̵ʙȒʙʚǐƄŽɌ͍ʽƱ̎̐ďŽ͆ƨ˖̖ʏ˽ʩǘ́ĵNjĵƥʷȂȁő0˱̧ǹƢċɁʊ9̕ƒɏˢɓʋż̵ĵđ0ŵˬƠıdž5ČɻͰ˙Žƭē͞džˠΓʑɕĶΗɩ΋ʼʛĢďǝ̟̀-̨˕Ĥ̬ĻƬ̯ΫȱŴ̛ȕǗˍʙȺʛƩĨƭŬθȁIJΏȸ͞Ǒπ̘˰ͽυȧdžͯʛ1IJŐđʼưŻ.ΏĨǼ̓ƍϖ̱ƛǗΗʙčȓΜŲɦǻƮ̦˘ɞȾŴɪƹȳ͈ɏ͢ΔϷϙȵǣƜʰ͓ϟƆĶɍ˗ȀıƎʪΏͶʌΑǧρɲʁ̵Ż̟ƣ΂ƹͬĉƣθŽ̩ƨ˥ȩĻ͠Иŏϗ̐Ȇ́ȊΚʪ̆ʛ΄ˍƃƯ̧Ź6ʰDz͞пˠͺΔƎƆ̵ʥĘʞ͓Ʃ΅ƎϹȀϟǔφ˝ȪɖЁʭϭɐɬ˖́ȟǗİ̺ŹʞƨЕАƱƇϦŲȁνƕ͸ЮƠϗďˋĆ8͐ƻωĻƆƴ̃уѨƍĢȊϡ΍Ȫ˔Ϊ͋ǔɻ́ĕdžƶ͓ǒȧƢьҀȹƪċψ˸Ľ͹}]ědeĝyĆƩ3}

in the Javascript polling file, found on the Blitzortung map (map.blitzortung.org), you can find the decode function, which successfully unshifts/converts the characters and will give back the cleartext data: {"time":1649868278408932900,"lat":33.447719,"lon":-94.393602,"alt":0,"pol":0,"mds":4734,"mcg":254,"status":0,"region":3,"sig":[{"sta":2155,"time":4434954,"lat":37.374615,"lon":-80.52121,"alt":1183,"status":12},{"sta":2430,"time":4472404,"lat":36.748104,"lon":-108.271843,"alt":1688,"status":4},{"sta":1750,"time":4631461,"lat":45.337063,"lon":-89.485497,"alt":466,"status":12},{"sta":1888,"time":4639915,"lat":35.662678,"lon":-79.346909,"alt":176,"status":4},{"sta":2571,"time":4694339,"lat":26.688599,"lon":-82.028542,"alt":8,"status":12},{"sta":1068,"time":4779522,"lat":39.071331,"lon":-108.500633,"alt":1414,"status":2},{"sta":1177,"time":4781025,"lat":45.396576,"lon":-88.124413,"alt":289,"status":10},{"sta":2925,"time":4845607,"lat":26.219933,"lon":-81.743134,"alt":13,"status":4},{"sta":2015,"time":4945659,"lat":44.473907,"lon":-103.814636,"alt":1209,"status":4},{"sta":2520,"time":5032296,"lat":39.169868,"lon":-78.979736,"alt":331,"status":4},{"sta":1660,"time":5116456,"lat":37.90345,"lon":-78.307068,"alt":129,"status":12},{"sta":2517,"time":5279307,"lat":32.41193,"lon":-110.994766,"alt":834,"status":4},{"sta":1042,"time":5410475,"lat":33.404495,"lon":-111.596764,"alt":482,"status":2},{"sta":2351,"time":5453861,"lat":39.098309,"lon":-77.522064,"alt":108,"status":12},{"sta":1451,"time":5455676,"lat":38.818295,"lon":-77.419884,"alt":108,"status":12},{"sta":2689,"time":5742630,"lat":48.444012,"lon":-89.332893,"alt":277,"status":12},{"sta":2935,"time":5957599,"lat":40.614189,"lon":-111.962761,"alt":1365,"status":4},{"sta":1203,"time":6031604,"lat":39.795403,"lon":-75.672981,"alt":92,"status":2},{"sta":1346,"time":6084054,"lat":44.505867,"lon":-78.611008,"alt":250,"status":2},{"sta":1702,"time":6137298,"lat":43.278538,"lon":-77.345444,"alt":81,"status":12},{"sta":1951,"time":6351592,"lat":46.191055,"lon":-79.392952,"alt":245,"status":12},{"sta":1933,"time":6425089,"lat":41.325848,"lon":-74.921967,"alt":411,"status":12},{"sta":2463,"time":6596871,"lat":43.126049,"lon":-75.307953,"alt":168,"status":12},{"sta":2603,"time":6643020,"lat":41.520214,"lon":-74.180992,"alt":133,"status":12},{"sta":2933,"time":7438244,"lat":10.66424,"lon":-61.523617,"alt":7,"status":2},{"sta":1969,"time":7605095,"lat":49.751804,"lon":-77.620399,"alt":262,"status":4},{"sta":1852,"time":8149073,"lat":46.795189,"lon":-71.376358,"alt":77,"status":4},{"sta":2285,"time":8596394,"lat":37.733692,"lon":-121.943794,"alt":125,"status":4},{"sta":1270,"time":8742882,"lat":52.254162,"lon":-113.762581,"alt":903,"status":2},{"sta":2377,"time":9350184,"lat":45.427273,"lon":-122.798592,"alt":80,"status":4}],"delay":6.3}

for me this fixed my Node-Red setup. I just stumbled upon those issues by Googling and wanted to spread the word.

GL&HF!

K5OZ commented 2 years ago

alphachris, Thanks for pointing this out to author mrk-its; however, I am a novice on all of this. Can you expand upon exactly what you did in Node-Red Blitzortung Integration to fix the situation? Thanks, Dave

mboroff commented 2 years ago

alphachris

I looked at mrk-its code and he is using MQTT to get the data. It seems to me that you are using HTTPS. For ark-its to change over is not going to be as simple you indicate. I also looked at the source on map.blitzuntorg.org and I did not see the code you reference. I don't know if Blitzuntorg has secured their MQTT requiring an id and password but reviewing their documentation they only want folks who have sensors reporting to them to have access to the data. And they don't make it easy to get sensor and join.

So I take it you are getting your information outside of Home Assistant. It would be very nice if you shared your code.

1-am-r00t commented 2 years ago

I looked at mrk-its code and he is using MQTT to get the data.

I doubt that, except my understanding of this HA plugin is wrong. I legit cannot imagine Blitzortung will provide lightning data via Mosquitto. in the repository, find the following file: ws_client/ws_client/client.py you can see that traditional WebSocket is being used to poll the data. MQTT is just being used to publish the data to a desired MQTT topic AFTER the data has been received by the listening WebSocket client.

My first point mentions that the WebSocket destination changed; see line 58 in client.py: uri = "wss://ws{}.blitzortung.org:3000/".format(random.randrange(5) + 1)

should be now: uri = "wss://ws{}.blitzortung.org/".format(random.randrange(5) + 1)

I also looked at the source on map.blitzuntorg.org and I did not see the code you reference

try to find in the file https://map.blitzortung.org/JavaScript/index.js a function called "decode"

the function looks like this: function decode(b) { var a, e = {}, d = b.split(""), c = d[0], f = c, g = [c], h = 256; o = h; for (b = 1; b < d.length; b++) a = d[b].charCodeAt(0), a = h > a ? d[b] : e[a] ? e[a] : f + c, g.push(a), c = a.charAt(0), e[o] = f + c, o++, f = a; return g.join("") }

this should be implemented into the existing script, otherwise the data will only be received scrambled (see my first reply).

since I'm not a HomeAssistant user myself (mainly using Node-Red to implement home automation by myself) I cannot help fixing the problem. I just stumbled upon this Github issue while troubleshooting and wanted to share my findings to you guys so someone with sufficient knowledge in HA scripting can open a pull-request.

mboroff commented 2 years ago

Alphachris

I think you may be able to help. Both Dave and I are ham radio operators. Dave first found out that he could obtain lightning strike distance via Blitzuntorg and node-red. I personally use it because I thought it was the only way to do it. In my node-red flow under HA I use MQTY+T to send a message to other node-red servers that a lightning strike is within 10 km.

So if you have a node-red flow that is bringing back to strike coordinate and possible boiling down the distance, I would be so grateful. I find the overhead of using HA is much more that straight Node-red. And I think, but can't speak for Dave, that he would also like to see your flow.

1-am-r00t commented 2 years ago

[{"id":"07aa18e05459f621","type":"tab","label":"Flow 1","disabled":false,"info":"","env":[]},{"id":"e8923d3119f9de10","type":"websocket in","z":"07aa18e05459f621","name":"","server":"","client":"bea4993f.85f4d8","x":790,"y":380,"wires":[["bb38d5607155fdac"]]},{"id":"2570533c0ddd961a","type":"websocket out","z":"07aa18e05459f621","name":"","server":"","client":"bea4993f.85f4d8","x":800,"y":320,"wires":[]},{"id":"6c3aabd78a8dbe6b","type":"inject","z":"07aa18e05459f621","name":"","props":[{"p":"payload"}],"repeat":"30","crontab":"","once":true,"onceDelay":"1","topic":"","payload":"{\"a\":542}","payloadType":"str","x":830,"y":240,"wires":[["2570533c0ddd961a"]]},{"id":"64ce0bfa9e1942bb","type":"function","z":"07aa18e05459f621","name":"","func":"function arePointsNear(checkPoint, centerPoint) {\n var ky = 40000 / 360;\n var kx = Math.cos(Math.PI * centerPoint.lat / 180.0) * ky;\n var dx = Math.abs(centerPoint.lng - checkPoint.lng) * kx;\n var dy = Math.abs(centerPoint.lat - checkPoint.lat) * ky;\n return Math.sqrt(dx * dx + dy * dy);\n}\n\nvar strike = { lat: msg.payload.lat, lng: msg.payload.lon };\n\n// set latitute + longitude accordingly\nvar home = { lat: 22.222222, lng: 11.111111 };\n\nvar n = arePointsNear(strike, home);\n\n// '10' = km radius, replace with whatever km radius you'd like\nif(n <= 10) {\n // return distance to strike if strike is in defined radius\n return {payload: n};\n}","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":770,"y":560,"wires":[[]]},{"id":"e0a0fa6ae9f41024","type":"json","z":"07aa18e05459f621","name":"convert JSON","property":"payload","action":"","pretty":false,"x":870,"y":500,"wires":[["64ce0bfa9e1942bb"]]},{"id":"bb38d5607155fdac","type":"function","z":"07aa18e05459f621","name":"","func":"function decode(b) {\n var a, e = {},\n d = b.split(\"\"),\n c = d[0],\n f = c,\n g = [c],\n h = 256;\n o = h;\n for (b = 1; b < d.length; b++) a = d[b].charCodeAt(0), a = h > a ? d[b] : e[a] ? e[a] : f + c, g.push(a), c = a.charAt(0), e[o] = f + c, o++, f = a;\n return g.join(\"\")\n}\n\nreturn {\n payload: decode(msg.payload)\n}","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":790,"y":440,"wires":[["e0a0fa6ae9f41024"]]},{"id":"bea4993f.85f4d8","type":"websocket-client","path":"wss://ws7.blitzortung.org/","tls":"621bc3fe.d747dc","wholemsg":"false","hb":"0","subprotocol":""},{"id":"621bc3fe.d747dc","type":"tls-config","name":"","cert":"","key":"","ca":"","certname":"","keyname":"","caname":"","servername":"","verifyservercert":false}]

this is my flow. good luck & have fun!

mboroff commented 2 years ago

alphachris

Dynamite. Thank you too much. Any chance you are also a ham?

1-am-r00t commented 2 years ago

Any chance you are also a ham?

curious to find out more about it, but low on time unfortunately. So for now, no.

K5OZ commented 2 years ago

@alphachris, Wow, this is great!!!! Now I can use just a Pi-zero for my application to disconnect my antennas when lightning is near! HA required a Pi4 to run the HA app. Many Thanks, Dave

1-am-r00t commented 2 years ago

well, glad it worked/helped both of you!!

In case you're curious about my use-case: I'm using near lightning strikes (<=10km radius) amongst wind and rain data from my weather station (polling via USB interface from receiver, publishing data to MQTT) to determine when to retract the electronic awning on my balcony when I'm not at home. Custom flows created in Node-RED because I wanted to avoid the overhead of installing HA. Works great.

Never actually thought about this also being useful for HAM radio amateurs, but yeah, definitely makes sense. I'm assuming you're using some kind of relay/actuator to actually "disconnect" them, right?

K5OZ commented 2 years ago

@alphachris Yes, I built a unit that opens the antenna ports on my Ham Radio Equipment anytime there is lightning within 10mi or 16km and reconnects when no lightning has been around for at least 20 minutes. Below is the link that I need to update; https://www.thingiverse.com/thing:4634806

Thanks, Dave

1-am-r00t commented 2 years ago

@alphachris Yes, I built a unit that opens the antenna ports on my Ham Radio Equipment anytime there is lightning within 10mi or 16km and reconnects when no lightning has been around for at least 20 minutes. Below is the link that I need to update; https://www.thingiverse.com/thing:4634806

Thanks, Dave

Thanks for sharing! Same idea, different use case though.

Cheers!

avd706 commented 2 years ago

@alphachris sorry, really a HA noob here, but if I change line 58 will the Home Assistant custom component start working.

@K5OZ it stopped working in my home assistant dashboard, but it seems the history shows count and distance on the graph

Big storm forcasted for tonight, maybe it will work, I'll try changing line 58.

B-Kramer commented 2 years ago

@alphachris sorry, really a HA noob here, but if I change line 58 will the Home Assistant custom component start working.

@K5OZ it stopped working in my home assistant dashboard, but it seems the history shows count and distance on the graph

Big storm forcasted for tonight, maybe it will work, I'll try changing line 58.

Any luck?

mboroff commented 2 years ago

I can't seem to find the ws_client on my Pi. How do you find it? I found some files in custom_components.

mrk-its commented 2 years ago

@alphachris

the developers from Blitzortung seem to have changed their WebSocket.

  1. before the latest change, it's been tcp/3000 to send/receive data - now it's using plain HTTPS (443).
  2. they changed the required initial JSON response, which the client must send to {"a":542}
  3. they started obfuscating/encoding the data, see this example: GL&HF!

Thanks for this really detailed explanation what happened, I'll try to make this plugin working again.

B-Kramer commented 2 years ago

Thanks for this really detailed explanation what happened, I'll try to make this plugin working again.

Thanks so much for taking the time to look at it, it's really appreciated.

harry747400 commented 2 years ago

@mrk-its

Thanks for this really detailed explanation what happened, I'll try to make this plugin working again.

Any progress yet?

B-Kramer commented 2 years ago

@mrk-its

Thanks for this really detailed explanation what happened, I'll try to make this plugin working again.

Any progress yet?

It's been working since the end of April.

harry747400 commented 2 years ago

It's been working since the end of April. not for me it hasn't. it still says "unavailable". did i end up with an old version?

mboroff commented 2 years ago

Most likely yes. Delete blitzing from the panel then add it back in. That should bring in the new version.

Marty

Sent from my iPhone

On May 31, 2022, at 12:10 PM, harry747400 @.***> wrote:

 It's been working since the end of April. not for me it hasn't. it still says "unavailable". did i end up with an old version?

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.

harry747400 commented 2 years ago

Delete blitzing from the panel then add it back in. That should bring in the new version.

i tried that, but it didn't help. they still say "unavailable" :-(

PS. my version.py says it's version 1.1.0

chatainsim commented 2 years ago

I can't seem to find the ws_client on my Pi. How do you find it? I found some files in custom_components.

Hello, I'm also not able to find the ws_client directory to check the client.py file. I've installed v1.1.0 but still not working. Can you help me ? Thanks

mboroff commented 2 years ago

I am not familiar with the file. Maybe you should get another SD card and start from scratch.

Marty

On Jun 3, 2022, at 6:22 AM, Simon @.***> wrote:

I can't seem to find the ws_client on my Pi. How do you find it? I found some files in custom_components.

Hello, I'm also not able to find the ws_client directory to check the client.py file. I've installed v1.1.0 but still not working. Can you help me ? Thanks

— Reply to this email directly, view it on GitHub https://github.com/mrk-its/homeassistant-blitzortung/issues/49#issuecomment-1145865138, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB2EZ2VMY244TJCNXMNOHZLVNHTIFANCNFSM5TLRX7SQ. You are receiving this because you commented.

chatainsim commented 2 years ago

I'm talking about this file: https://github.com/mrk-its/homeassistant-blitzortung/blob/master/ws_client/ws_client/client.py Do you know where it is in HA ?

mboroff commented 2 years ago

I am afraid I do not know where it is located. I did explore the files at one time looking to make a modification to where he gets the data. I suspect it is installed on the Pi when you add the integration.

You know I installed Blitzuntorg using HACS. I assume you are doing the same. That’s why I suggest deleting the app and adding it back in. I also assume your HA files are the current or one prior version.

On Jun 3, 2022, at 8:10 AM, Simon @.***> wrote:

I'm talking about this file: https://github.com/mrk-its/homeassistant-blitzortung/blob/master/ws_client/ws_client/client.py https://github.com/mrk-its/homeassistant-blitzortung/blob/master/ws_client/ws_client/client.py Do you know where it is in HA ?

— Reply to this email directly, view it on GitHub https://github.com/mrk-its/homeassistant-blitzortung/issues/49#issuecomment-1145948230, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB2EZ2WPGEBFGHRNNN2WFTLVNH73JANCNFSM5TLRX7SQ. You are receiving this because you commented.

mboroff commented 2 years ago

Try this. Go to settings and select Devices and Services. Check the service on HACS to see if Bliztotung is there. Delete Blitztortung from the integration panel. Then check the services on HACS again and see if it is gone. Reboot your device. Then go to settings and select Devices and select add and integration and add the Blitzuntorg back in and set up the entities for it.

Marty

On May 31, 2022, at 12:34 PM, harry747400 @.***> wrote:

Most likely yes. Delete blitzing from the panel then add it back in. That should bring in the new version.

i tried that, but it didn't help. they still say "unavailable" :-(

— Reply to this email directly, view it on GitHub https://github.com/mrk-its/homeassistant-blitzortung/issues/49#issuecomment-1142420781, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB2EZ2UCGCFBYWPK7NQW7O3VMZETJANCNFSM5TLRX7SQ. You are receiving this because you commented.

K5OZ commented 1 year ago

Mariusz Kryński (Mrk-its);

Please look at issue #70.

Thanks,

Dave

K5oz

From: Mariusz Krynski @.> Sent: Thursday, April 21, 2022 11:33 AM To: mrk-its/homeassistant-blitzortung @.> Cc: David Hartley @.>; Mention @.> Subject: Re: [mrk-its/homeassistant-blitzortung] Blitzortung no longer works after updating Home Assistant (Issue #49)

@alphachris https://github.com/alphachris

the developers from Blitzortung seem to have changed their WebSocket.

  1. before the latest change, it's been tcp/3000 to send/receive data - now it's using plain HTTPS (443).
  2. they changed the required initial JSON response, which the client must send to {"a":542}
  3. they started obfuscating/encoding the data, see this example: GL&HF!

Thanks for this really detailed explanation what happened, I'll try to make this plugin working again.

- Reply to this email directly, https://github.com/mrk-its/homeassistant-blitzortung/issues/49#issuecomment -1105447385 view it on GitHub, or https://github.com/notifications/unsubscribe-auth/AFCOUQMFNTWOJLTRGYUT43TVG F7ILANCNFSM5TLRX7SQ unsubscribe. You are receiving this because you were mentioned. https://github.com/notifications/beacon/AFCOUQJDF23H5NNDPYEZQCLVGF7ILA5CNFS M5TLRX7S2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOIHR4TWI .gif Message ID: < @.> @.>

avd706 commented 1 year ago

This is working, or at least it was

mboroff commented 1 year ago

Issue 49 yes. This is a new issue. Place the socket url in your browser and it say you need to upgrade. There was a firmware update in November. So they have changed the connection requirements.MartySent from my iPhoneOn Jan 13, 2023, at 5:34 PM, avd706 @.***> wrote: This is working, or at least it was

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you commented.Message ID: @.***>