Lovelace Lightning Detector Card for AS3935

I thought this would be a great little weekend project do work on and it is. I took a bit a time to realize I had ordered the SPI version so I had to solder on a couple of more leads and try again.

I had to install MQTT version 1.5.7 I believe – whatever them most current is and I tested it by sending some messages back and forth.

My issue is that I can’t get the detector to connect to the local host broker. I no next to nothing about MQTT other than what I played with today.

In the script I am using the following for MQTT config

# The hostname or IP address of the MQTT broker to connect to (Default: localhost)

# Also read from the MQTT_HOSTNAME environment variable
hostname = localhost

# The TCP port the MQTT broker is listening on (Default: 1883)**

# Also read from the MQTT_PORT environment variable**
port = 1883

Is there something I don’t see?

Thanks

After messing with this a bit, I am lost. See below:

pi@raspberrypi:~ $ sudo systemctl status mosquitto.service
● mosquitto.service - Mosquitto MQTT v3.1/v3.1.1 Broker
   Loaded: loaded (/lib/systemd/system/mosquitto.service; enabled; vendor preset
   Active: active (running) since Tue 2021-02-02 09:17:39 CST; 6min ago
     Docs: man:mosquitto.conf(5)
           man:mosquitto(8)
 Main PID: 2399 (mosquitto)
    Tasks: 1 (limit: 2063)
   CGroup: /system.slice/mosquitto.service
           └─2399 /usr/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf

Feb 02 09:17:39 raspberrypi systemd[1]: Starting Mosquitto MQTT v3.1/v3.1.1 Brok
Feb 02 09:17:39 raspberrypi systemd[1]: Started Mosquitto MQTT v3.1/v3.1.1 Broke

pi@raspberrypi:~ $ cd /opt/ISP-lightning-mqtt-daemon
pi@raspberrypi:/opt/ISP-lightning-mqtt-daemon $ sudo nano config.ini
pi@raspberrypi:/opt/ISP-lightning-mqtt-daemon $ sudo systemctl start pigpiod.service
pi@raspberrypi:/opt/ISP-lightning-mqtt-daemon $ cd 
pi@raspberrypi:~ $ python3 /opt/ISP-lightning-mqtt-daemon/ISP-lightning-mqtt-daemon.py
[2021-02-02 09:27:22] - * **init mqtt_client_connected=[False]**
[2021-02-02 09:27:22] * Sensor on SPI bus

ini file

# The hostname or IP address of the MQTT broker to connect to (Default: localho$
# Also read from the MQTT_HOSTNAME environment variable
hostname = localhost

# The TCP port the MQTT broker is listening on (Default: 1883)
# Also read from the MQTT_PORT environment variable
port = 1883
# Enable TLS/SSL on the connection
tls = false

# Path to CA Certificate file to verify host
#tls_ca_cert =

# Path to TLS client auth key file
#tls_keyfile = privkey.pem

# Path to TLS client auth certificate file
#tls_certfile = fullchain.pem

Any thoughts

Very nice. Would love to get this working with the Tasmota interface for the AS3935.

I have set this up, but so far all of the MQTT sensors only display Unknown. I am assuming the sensor that I use with the lightning detector card is the “sensor.current_ringset” and “sensor.past_ringset”?

This is what I’m seeing:

Then, when I add either of those sensors to the lightning detector card I’m just seeing:
CleanShot 2021-05-03 at 15.12.38

Is this what I should be seeing?

@emergent the “Unknown” usually indicate that MQTT broker under MQTT has not yet received any information from your RPi/Lightning detector.

You can watch MQTT traffic by monitoring what the broker is receiving using tools such as MQTT Explorer or MQTTBox. After you confirm the sensor is reporting then you should see these values start updating correctly.

Yes, the current_ringset is the latest Lightning Detection traffic.

Hope this helps.

It’s receiving something because it’s creating the entities. Do you mean information specifically about lightning events?

This is what MQTT Explorer is showing underhomeassistant/sensor:

For topic homeassistant/sensor/lightningdetector/crings/config it’s showing this:
{"name": "Current Ringset", "uniq_id": "AS3935-b827ebd2aa00_crings", "dev_cla": "timestamp", "stat_t": "~/crings", "val_tpl": "{{ value_json.crings.timestamp }}", "~": "home/nodes/sensor/lightningdetector", "pl_avail": "Online", "pl_not_avail": "Offline", "avty_t": "~/status", "json_attr_t": "~/crings", "json_attr_tpl": "{{ value_json.crings | tojson }}", "dev": {"identifiers": ["AS3935-b827ebd2aa00"]}}

I’m looking and topic home/nodes/sensor/lightningdetector is only showing the status topic which is status=Online. I’m not seeing a topic home/nodes/sensor/settings being created like the docs refer to.

This is what my config.ini looks like:

# Configuration file for lightning-detector-MQTT2HA-Daemon

# Source: https://github.com/ironsheep/lightning-detector-MQTT2HA-Daemon

#

# Uncomment and adapt all settings as needed.

# Some settings can be configured by environment variables.

# If an env variable is set, it takes precedence over settings in this file

[General]

[Daemon]

# Enable or Disable an endless execution loop (Default: true)

#enabled = true

[MQTT]
# The hostname or IP address of the MQTT broker to connect to (Default: localho$

# Also read from the MQTT_HOSTNAME environment variable

hostname = 192.168.1.248

# The TCP port the MQTT broker is listening on (Default: 1883)

# Also read from the MQTT_PORT environment variable

#port = 1883

# Maximum period in seconds between ping messages to the broker. (Default: 60)

#keepalive = 60

# NOTE: The MQTT topic used for this device is constructed as:
#  {base_topic}/{sensor_name}
#
# The MQTT base topic to publish the Lightning detector sensor data topics unde$
base_topic = home/nodes

# The MQTT name for this Lightning detector sensor
sensor_name = lightningdetector

# The MQTT broker authentification credentials (Default: no authentication)
# Will also read from MQTT_USERNAME and MQTT_PASSWORD environment variables
#username = user
#password = pwd123

# Enable TLS/SSL on the connection
#tls = false

# Path to CA Certificate file to verify host
#tls_ca_cert =

# Path to TLS client auth key file
#tls_keyfile =

# Path to TLS client auth certificate file
#tls_certfile =

# Broker connection-failure recovery
#  Rety connection attempts [default 5]
#retry_count = 5

#  Retry after waiting N seconds [default 30]
#retry_wait_in_seconds = 30

[Behavior]

# This script accumulates detections into buckets (rings if you will) for this period of time [2-10] in minutes [Default: 5]
#period_in_minutes = 5

# This script accumulates values into [3-7] rings [Default: 5]
#number_of_rings = 5

# This script can report distances in miles or kilometers (mi, km) [Default: km]
distance_as = mi

# This script determines that a storm has ended after this period of time [10-60] in minutes [Default: 30]
#end_storm_after_minutes = 30

[Sensor]

# decribe how your sensor is hooked up to your RPi
#  use values 'I2C' or 'SPI' - default is 'I2C'
#sensor_attached = I2C

# GPIO pin used for interrupts
#intr_pin = 17

# The SPI bus and device numbers come from the device file being used.
#   e.g., /dev/spidev0.0  would be bus=0, device=0
# The defaults are 0 and 0 (SPI0 which appears at the GPIO 40pin header)
#spi_bus = 0
#spi_device = 0

# Rev. 1 Raspberry Pis should leave bus set at 0, while rev. 2 Pis should set
# bus equal to 1. The address should be changed to match the address of the
# sensor.
#i2c_bus = 1
#i2c_address = 0x03

# Value to use for your board
#   Internal Tuning Capacitors (from 0 to 120pF in steps of 8pf) - A value of [0-15]
# run the script with a --tune paramater to determine value for your board
#  NOTE: this runs for 3 minutes so be patient!  Then record your best value here.
tuning_capacitor = 0xf

# Indoors (True) = more sensitive (can miss very strong lightnings)
# Outdoors (False) = less sensitive (can miss far away lightnings)
detector_afr_gain_indoor = True

detector_noise_floor = 1

# Prevent single isolated strikes from being logged => interrupts begin after
# this number of strikes (def: 5, value 1,5,9,16), then are fired normally.
detector_min_strikes = 1

I rebooted and now the settings node showed up:
{"settings": {"timestamp": "2021-05-03T21:37:11+01:00", "hardware": {"min_strikes": 1, "afe_inside": true, "disp_lco": false, "noise_floor": 1}, "script": {"period_minutes": 5, "end_minutes": 30, "number_rings": 5, "distance_units": "mi"}}}

However the card still only shows up like this:

Am I missing something? It should look like something like this, right?
87717634-f2f92b80-c76d-11ea-915a-66cfdeaa4c73

I still cannot get the connection to the host.

# The hostname or IP address of the MQTT broker to connect to (Default: localho$
# Also read from the MQTT_HOSTNAME environment variable
hostname = 192.168.1.173
#hostname = localhost
#hostname = 192.168.1.170

# The TCP port the MQTT broker is listening on (Default: 1883)
# Also read from the MQTT_PORT environment variable
#port = 1883

@Edhall1044 OK, I’ll need a little bit more understanding of your setup.

The normal environment is one RPi with Lightning detector attached and running the properly configured python script which announces messages to an external MQTT broker. Then a second RPi (or another machine) is running both Home Assistant and the MQTT Broker.

What does your setup look like?

OK, that’s a good start. But behind that, you should see detection reports. Until the detection reports are sent to MQTT the card won’t show anything…

You should be able to run the detector script by hand (stop the daemon form while doing so) and enable debug output (I think this may be the -d option. You can check by running the script with -h and it will tell you all available options.)

This will help you see if your detector is reporting anything useful.

Also, there is a storm playback mechanism built into the script. If you generate a storm (or use one of the pre-existing storms) then playback the storm and the data reports correctly via MQTT then you should see the Lovelace card report this fake/generated storm. This would also be a means to check out your MQTT and Lovelace card configuration … See lightning-detector-MQTT2HA-Daemon/THEOPS.md at 431f9d50c020e1755f2a322f57ccddef36c24003 · ironsheep/lightning-detector-MQTT2HA-Daemon · GitHub

Does this help?

I’ve got a pi4 running home assistant with the mqtt addon running. I use the mqtt to grab data from my weather station and ahassplate.

The pi running home assistant is at 192.168.1.173. Currently the pi running the lightning detector is connected to the network directly.

UPDATE: I"ve added the missing exaple card configuration to the README in the card repo.
See: GitHub - ironsheep/lovelace-lightning-detector-card: A Lightning Detection Display Card for Home Assistant Lovelace

Regards,
Stephen

OK, that helps. Check the config.ini on the Detector RPi. Hostname in that file should refer to your Home Assistant RPi 4 hostname where the MQTT broker is running. This should be the hostname of the MQTT broker machine.

You currently have:

# The hostname or IP address of the MQTT broker to connect to (Default: localho$
# Also read from the MQTT_HOSTNAME environment variable
hostname = 192.168.1.173

Tried again and got this

2021-05-03 20:33:50] - * init mqtt_client_connected=[False]
[2021-05-03 20:33:50] * Sensor on SPI bus
[2021-05-03 20:33:50] MQTT connection error - broker @192.168.1.173 not responding. Retrying in 30 seconds... (retry count = 5)
[2021-05-03 20:34:20] MQTT connection error - broker @192.168.1.173 not responding. Retrying in 30 seconds... (retry count = 4)

What are the IP addresses of your two RPi’s ?

is 192.168.1.173 your RPi 4 running the MQTT broker or the one with your Detector?

also see if you can (1) ping the HA RPi from the Detector RPi see if there is basic communication…

MQTT connection error - broker @192.168.1.173
Means that your detector RPi can’t start communication with your MQTT broker on the HA RPi.

the pi with the detector is 192.168.1.69. home assistant is .73 and I can ping .73 from .69

I meant. 173. I found the problem, I had unremarked a couple of lines that I thought were variables.

son came by and helped me with the rest.

And thanks for your help. Much appreciated…

Good to hear. Glad to help!