ESPHome with AS3935 Franklin Lightning Sensor - try increasing the spike rejection value!

Tags: #<Tag:0x00007fc3fd09d260> #<Tag:0x00007fc3fd09d0d0>

I’ve got one of these AS3935 Franklin Lightning Sensors and I’ve been futzing with it. I read through this thread and it seems like maybe these sensors aren’t quite complete functionally.

I’m using i2c on mine with this code:

i2c:
  scl: D1
  sda: D2
  scan: True

as3935_i2c:
  irq_pin: D7
  indoor: True

binary_sensor:
  - platform: as3935
    name: "Storm Alert"

sensor:
  - platform: as3935
    lightning_energy:
      name: "Lightning Energy"
    distance:
      name: "Distance Storm"

I have some other things on the ESP8266 using the i2c bus and those are working. I’ve noticed that occasionally the sensor appears to “work” and by that I mean not spit out errors and warnings but the sensor results look like this:
image

However, quite a bit when I fire up the device, it continually spits out this Disturber was detected - try increasing the spike rejection value!. I’ve tried making the value 11 which is the maximum and it still dumps tons of these messages.

[08:27:18][I][as3935:041]: Disturber was detected - try increasing the spike rejection value!
[08:27:18][I][as3935:041]: Disturber was detected - try increasing the spike rejection value!
[08:27:18][I][as3935:041]: Disturber was detected - try increasing the spike rejection value!
[08:27:18][I][as3935:041]: Disturber was detected - try increasing the spike rejection value!
[08:27:18][I][as3935:041]: Disturber was detected - try increasing the spike rejection value!
[08:27:18][I][as3935:041]: Disturber was detected - try increasing the spike rejection value!
[08:27:19][I][as3935:041]: Disturber was detected - try increasing the spike rejection value!
[08:27:19][I][as3935:041]: Disturber was detected - try increasing the spike rejection value!
[08:27:19][I][as3935:041]: Disturber was detected - try increasing the spike rejection value!
[08:27:19][I][as3935:041]: Disturber was detected - try increasing the spike rejection value!
[08:27:19][I][as3935:041]: Disturber was detected - try increasing the spike rejection value!
[08:27:19][I][as3935:041]: Disturber was detected - try increasing the spike rejection value!
[08:27:19][I][as3935:041]: Disturber was detected - try increasing the spike rejection value!
[08:27:19][I][as3935:041]: Disturber was detected - try increasing the spike rejection value!
[08:27:19][I][as3935:041]: Disturber was detected - try increasing the spike rejection value!
[08:27:19][I][as3935:041]: Disturber was detected - try increasing the spike rejection value!
[08:27:19][I][as3935:041]: Disturber was detected - try increasing the spike rejection value!
[08:27:19][I][as3935:041]: Disturber was detected - try increasing the spike rejection value!
[08:27:19][I][as3935:041]: Disturber was detected - try increasing the spike rejection value!
[08:27:19][I][as3935:041]: Disturber was detected - try increasing the spike rejection value!
[08:27:19][I][as3935:041]: Disturber was detected - try increasing the spike rejection value!
[08:27:19][I][as3935:041]: Disturber was detected - try increasing the spike rejection value!
[08:27:19][I][as3935:041]: Disturber was detected - try increasing the spike rejection value!
[08:27:19][I][as3935:041]: Disturber was detected - try increasing the spike rejection value!
[08:27:19][I][as3935:041]: Disturber was detected - try increasing the spike rejection value!
[08:27:19][I][as3935:041]: Disturber was detected - try increasing the spike rejection value!
[08:27:19][I][as3935:041]: Disturber was detected - try increasing the spike rejection value!
[08:27:19][I][as3935:041]: Disturber was detected - try increasing the spike rejection value!
[08:27:19][I][as3935:041]: Disturber was detected - try increasing the spike rejection value!
[08:27:19][I][as3935:041]: Disturber was detected - try increasing the spike rejection value!
[08:27:19][I][as3935:041]: Disturber was detected - try increasing the spike rejection value!
[08:27:19][I][as3935:041]: Disturber was detected - try increasing the spike rejection value!
[08:27:19][I][as3935:041]: Disturber was detected - try increasing the spike rejection value!
[08:27:19][I][as3935:041]: Disturber was detected - try increasing the spike rejection value!

I’ve scoured the internet looking for answers and the only thing that might make sense is this note on SparkFun’s webpage:

The SparkFun Lightning Detector’s original design supported I²C but there were issues raised by a small percentage of customers who purchased this product with regards to its’ reliability. This issue was followed up with an investigation by our engineers and unfortunately, we decided we could not support it officially. However, if you want to use it, all of the goods are there. Just know SparkFun won’t be supporting problems that may arise with its’ use.

Anyway, I guess I might have to try it in SPI mode and see if that helps me get somewhere more interesting. I’m just wondering if anyone has had better results with it or, specifically, knows how to fix this disturber was detected message.

I tried it in SPI mode and the problem persists using this YAML:

spi:
  clk_pin: D5
  miso_pin: D6
  mosi_pin: D7

as3935_spi:
  cs_pin: D1
  irq_pin: D2
  indoor: True

binary_sensor:
  - platform: as3935
    name: "Storm Alert"

sensor:
  - platform: as3935
    lightning_energy:
      name: "Lightning Energy"
    distance:
      name: "Distance Storm"

The errors don’t come out quite as rapidly in SPI mode (3-4 per second), I assume that’s because of the sampling rate in SPI:

[10:29:52][I][as3935:041]: Disturber was detected - try increasing the spike rejection value!
[10:29:52][I][as3935:041]: Disturber was detected - try increasing the spike rejection value!
[10:29:52][I][as3935:041]: Disturber was detected - try increasing the spike rejection value!
[10:29:53][I][as3935:041]: Disturber was detected - try increasing the spike rejection value!
[10:29:53][I][as3935:041]: Disturber was detected - try increasing the spike rejection value!
[10:29:53][I][as3935:041]: Disturber was detected - try increasing the spike rejection value!
[10:29:54][I][as3935:041]: Disturber was detected - try increasing the spike rejection value!
[10:29:54][I][as3935:041]: Disturber was detected - try increasing the spike rejection value!
[10:29:54][I][as3935:041]: Disturber was detected - try increasing the spike rejection value!
[10:29:55][I][as3935:041]: Disturber was detected - try increasing the spike rejection value!
[10:29:55][I][as3935:041]: Disturber was detected - try increasing the spike rejection value!

Also of note, while randomly reading through AliExpress ads for the AS3935 I came across this one that has this written in the FAQ section:

Q: I believe there is a calibration issue on this sensor. It does not seem to work and when connected (with proper 3.3V) The AS3935 sensor outputs thousands of Disturber was detected messages as seen below; [14:48:15][I][as3935:041]: Disturber was detected [14:48:15][I][as3935:041]: Disturber was detected [14:48:15][I][as3935:041]: Disturber was detected 14:48:22][W][i2c:073]: Received NACK on transmit of data for address 0x03 [14:48:22][W][as3935_i2c:029]: Read failed!
A: If you use Arduino IDE, please upload code to scan the IIC address. When you test it, please do not touch the module.

It’s funny because the log entries look exactly like ESPHome. Seems like someone else was experiencing the same issue and the vendor had no solution for them. :frowning:

I even tried with spike_rejection: 11.

More debugging. I looked around and it appears as though this device can accept 5V supply. So I took a couple of level shifters and mocked up a 5V version of this to use with my Wemos D1 Mini. I got it all wired up and flashed it with ESPHome and now it’s showing me these messages:

[11:54:25][I][as3935:039]: Noise was detected - try increasing the noise level value!
[11:54:26][I][as3935:039]: Noise was detected - try increasing the noise level value!
[11:54:27][I][as3935:039]: Noise was detected - try increasing the noise level value!
[11:54:28][I][as3935:039]: Noise was detected - try increasing the noise level value!
[11:54:29][I][as3935:039]: Noise was detected - try increasing the noise level value!
[11:54:31][I][as3935:039]: Noise was detected - try increasing the noise level value!
[11:54:33][I][as3935:039]: Noise was detected - try increasing the noise level value!
[11:54:34][I][as3935:039]: Noise was detected - try increasing the noise level value!
[11:54:35][I][as3935:039]: Noise was detected - try increasing the noise level value!
[11:54:35][I][as3935:039]: Noise was detected - try increasing the noise level value!
[11:54:36][I][as3935:039]: Noise was detected - try increasing the noise level value!
[11:54:37][I][as3935:039]: Noise was detected - try increasing the noise level value!
[11:54:39][I][as3935:039]: Noise was detected - try increasing the noise level value!
[11:54:40][I][as3935:039]: Noise was detected - try increasing the noise level value!
[11:54:42][I][as3935:039]: Noise was detected - try increasing the noise level value!

I tried upping the noise_level value, apparently the maximum is 7. Even at 7 it still generates a ton of these messages. But hey, at least the spike rejection messages are gone! :smiley:

No love yet.

BTW: For the record, I level shifted every signal in SPI mode so I used 2 level shifters (each handling 4 signals) for 5 signals: (CL/CLK, DA/MOSI, MI/MISO, CS, IRQ)

image

I just found that I could cause the Noise was detected message to go away if I plugged a 220uF electrolyic capacitor across the V and G terminals of the AS3935! If I used anything smaller than that (100uF next size) it would still spit out one or two a second. It was in SPI mode at 5V using the level shifters.

So, I’ve swapped it back to I2C mode to see if I can get it to work at 5V using level shifters. To my surprise, without the 220uF cap it came right up, no errors/warnings. I think I might just try to build my circuit with a bunch of level shifters so everything operates at 5V.

Well, I found this github issue where someone said that if you just flip the indoor to false it causes the Disturber was detected messages to go away. I just put my circuit back to 3.3V for everything and it seems to be working great with that set to false. I’m planning on installing this outside so I’ll just do all my testing with it like this as well.

LOL, lots of debug for nothing it seems. Hopefully this thing actually works to detect lightning.

Interesting project, would love to hear how well it works. We get frequent thunderstorms.

Have you tested it yet?

@depen

Yeah, these sensors are a piles of crap. I purchased both styles of it the purple AliExpress.com one and the red SparkFun.com one (directly from SparkFun). Neither of them works to report lightning. I’m using I²C on both of them and there are notes on the SparkFun website that say that the device has issues in I²C mode so maybe this is what they’re talking about. It surprises me that they’ll still take $30 for these…

The screen shot I shared above with Storm Alert: Off, Distance Storm: Unknown, and Lightning Energy: Unknown has never shown anything else and we’ve had a few thunderstorms roll through.

Anyway, my opinion on this is: stay away – waste of money.

1 Like

Thanks for sharing! Your effort saved me a lot off time and money! The Home Assistant community is truly awesome!

I’ve got the same problem. Bought 2 of them, tried SPI/I2C, either I’m getting these Disturber was detected floods or nothing.

Connected to Arduino in SPI mode with SparkFun library, it sees the AS board fine, sets/gets the settings (noise level etc) but there are no interrupts from it at all. I tried some man-made disturbers: piezo, drill which sparks like hell when stopped etc. Nothing.

I recently ran across this interesting little sensor and it really made me curious. Not sure if you guys have seen this extremely thorough analysis of the AS3935 sensor here. It looks like it’s a pain to set up, because it needs to be at least 10m from any RF noise source like computers and is very picky about noise on the power supply. But from the guys results, it actually looks like it’s rather precise once set up correctly ! Now he does play around with all kind of internal settings, some of them poorly documented. Not sure how much of that is exposed by esphome.

I’m tempted to try this thing out lol.

That sounds like a communication issue more than anything else. Have you done any more tests since or did the thing end up in your trash ?

I have one that is out on my deck, just about as far from computers and whatnot as it could be (40’ cat five from the Wemos D1 mini that drives it). I’ve still never seen it give me anything. The other ones I bought hoping they’d be different sit on my workbench.

If you can get it to work, please let me know. I’d love to know what I’m doing wrong. :smiley:

1 Like

I know I’m going to regret this and I’ll waste way too much time than reasonable on that thing, but I just ordered a cheapo clone on Ali (the Sparkfun was too expensive for something that is probably not going to work). This sensor is too fascinating to pass :grinning: We have a lot of thunderstorms here in the summer so I’ll have plenty of opportunities to test ! So hopefully some results in a few months…

I got one of these devices not knowing the issues I would encountered (The cheap ones I suppose)

It’s the GY-AS3935. I’m assuming some register masks may not be correct for this specific device? Not sure but yea… storm right now and it’s only coming up with “Unknown” for the readings. I would have thought that as it has the same chip, it would have functioned the same :x

Can this work with an ESP32 too? :thinking:

I’ve got 5 of them lying around so if I could avoid to buy again…

OK, I can confirm that these things just don’t work. I have one connected to the lowest noise MCU I could find, an Arduino powered by a battery. The thing is on a post in the middle of a field, more than 800m from any interfering electronics. We just had a heavy thunderstorm go right over our heads. Constant lightning strikes all around, one even struck one of my neighbors trees.

My AS3935 (clone) detected - absolutely nothing except some noise :roll_eyes:

Maybe it’s the clones that are just broken, I don’t know.

For reference, that is the thing that went over us. If the AS can’t even detect something like this, I don’t know what will make it trigger…

(From https://map.blitzortung.org)

1 Like

Thanks for confirming. It’s sad that they’re around $30 and still available for curious people to buy into when they just don’t do what they’re designed to do.

Thanks man you just saved my money and my time !!!

Au passage un p’tit “coucou” de Normandie :wink: