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

Tags: #<Tag:0x00007f73b48205f8> #<Tag:0x00007f73b48203f0>

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.