AS3935 Franklin Lightning sensor with ESPHome

I am using the AS3935 Franklin Lightning with ESPhome and the journey to get this working was bumpy so I thought I would share some feedback and we may be able to share numbers.

Initial setup

The wiring and programming with ESPHome is very straight forward.
I am using SPI:

esphome:
  name: esph-lightning-01
  friendly_name: esph-lightning-01

esp8266:
  board: d1_mini


# Enable logging
logger:

spi:
  - id: spi_bus0
    clk_pin: GPIO14
    miso_pin: GPIO12
    mosi_pin: GPIO13
    interface: hardware
  
# See https://esphome.io/components/sensor/as3935.html#over-spi
as3935_spi:
  # Mandatory
  cs_pin: GPIO15
  irq_pin: GPIO02

  # Optional
  indoor: false 
  noise_level: 2 # Default 2
  spike_rejection: 1 # default is 2
  lightning_threshold: 1 # default is 1. Value are 1 | 5 | 9 | 16 for a 15 min window
  mask_disturber: false # default false
  
  div_ratio: 32 # default 0
  capacitance: 1 # default 0
  
  # watchdog_threshold: 2
  # calibration: false # default to true

  # One shot:
  # tune_antenna: true # default false

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

binary_sensor:
  - platform: as3935
    name: Lightning Strike
          
# Enable Home Assistant API
api:
  encryption:
      key: !secret encryption_key

ota:
  - platform: esphome
    password: !secret ota_pass

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  domain: !secret domain


captive_portal:

Here comes the noise + spam

After that, you should happily get… some noise.

Here is a storm with lightnings passing by:

No wonder that many people quality this device as useless.
Not only it spams your system but also does not allow making a decision whether there are lightning or not.

I initiallly tried a few random settings including mask_disturber: false but there are key points before you can get this sensor to behave and stop spamming your OH with noise and “lightnings” that occured 1km away from you…

Solution

Wiring

Initially, I packed a Wemos and the sensor close to each other to fit in a small 3d printed enclosure. That’s just a bad idea…

You must keep the sensor away from the micro controller and its Wifi antenna.
I do not have a minimum length. I went for a length of 90cm using a ribbon cable and it behaves much better. I guess shorter would work as well.

I did a test using my initial setup and 18mm between sensor and Wemos and definitely not enough.

Positioning

It seems that the sensor needs to lay flat (ie horizontal) and not point up.

Tuning

This is probably the most important point.
Each device is different. So using the values that work for me on ONE sensor is rather useless. You will need to tuned YOUR antenna.

Mine was not working great of the shelf:

For this you will need to flash your Wemos with:

tune_antenna: true 
calibration: false

and plug a device that can measure the frequency on the IRQ pin.
Once you have a freq, multiply by 16. The goal is to get as close as possible to 500kHz using div_ratio and capacitance.

  • capacitance is a value from 0 to 15.
  • div_ratio is 0 | 32 | 64 …

Once you found the optimum value (it does not have to be perfect), you can change back to:

tune_antenna: false 
calibration: true

flash your device and reboot.

After that, you should no longer get noise and spam into your logs with false detection and you should start seeing real events. Those can be recognized with their distance being >1km:

Note that the chart above is with mask_disturber: false.

Final word

This sensor is not very simple to setup as you need to prepare then wait for some lightnings to tune your values. EPSHome makes it however quite easy to do.

I noticed during the tuning process that it is good to unplug and replug the Wemos and ensure a correct reading of the frequency.

And “luckily” we got bad weather and storms today.
After tuning, this is the kind of signal that can be expected:

  • Before the storm, nothiong anymore, very nice.
  • During the storm, we can see in yellow, the front closing in, then passing by and going away
  • The number of “events” is also much higher when the storm is near

Now some rules can be applied.

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.