hello,
please shoo me away if this is too annoying, im looking at how this handles lightning detectiom, but im not smart enough with code so i asked claude. Im looking at using the vibe coded severe weather app in the other section. Right now im using an ecowitt lightning detector, but it only reports a summary of the day's lightning events at around midnight every night.
this is my first time playing with this kind of AI stuff so i wanted to run it past the community and see what the consensus is :
The Core Problem
The app is subscribed to lightningDistance on your lightning sensor (line 706), but looking at the Ecowitt RF Sensor driver, the attribute it actually fires events on is lightningCount — not lightningDistance.
From the Hubitat events screenshot, you can see your sensor is emitting lightningTime and lightningCount events. The lightning handler is simply never firing because it's listening for the wrong attribute name.
There are actually two bugs here:
Bug 1 — Wrong attribute subscribed:
groovy
// Line 706 - what the app does:
subscribeMulti(sensorLightning, ["lightningDistance", "distance"], "lightningHandler")
// What your Ecowitt driver actually emits:
"lightningCount" ← this is what triggers
"lightningTime" ← paired timestamp
Bug 2 — lightningCount is a cumulative daily count, not a per-strike event. The app's lightningHandler treats each event value as a distance reading for storm vectoring, which won't work correctly with a count attribute.
The Fix
In the app code, find this line (~line 706):
groovy
subscribeMulti(sensorLightning, ["lightningDistance", "distance"], "lightningHandler")
Replace it with:
groovy
subscribeMulti(sensorLightning, ["lightningCount", "lightningDistance", "distance"], "lightningHandler")
Then find the lightningHandler (~line 939):
groovy
def lightningHandler(evt) { updateHistory("lightningHistory", evt.value, 1800000); runIn(1, "evaluateMatrix") }
Replace it with:
groovy
def lightningHandler(evt) {
// Handle both lightningCount (Ecowitt cumulative) and lightningDistance style events
if (evt.name == "lightningCount") {
def count = 0
try { count = evt.value.toString().toInteger() } catch(e) { return }
// Only record if count increased (new strikes detected)
def lastCount = state.lastLightningCount ?: 0
if (count > lastCount && count > 0) {
def newStrikes = count - lastCount
newStrikes.times {
// Record each new strike with a placeholder distance of 99 (unknown)
def hist = state.lightningHistory ?: []
hist.add([time: now(), value: 99])
def cutoff = now() - 1800000
hist = hist.findAll { it.time >= cutoff }
if (hist.size() > 288) hist = hist.drop(hist.size() - 288)
state.lightningHistory = hist
}
}
// Handle daily reset (count goes back to 0)
if (count == 0) { state.lastLightningCount = 0; return }
state.lastLightningCount = count
} else {
// Original distance-based path for other sensor types
updateHistory("lightningHistory", evt.value, 1800000)
}
markActive()
runIn(1, "evaluateMatrix")
}
What This Does
- Subscribes to
lightningCount so Hubitat actually delivers events to the handler when your Ecowitt station detects lightning.
- Detects new strikes by comparing the new count to the previous count (handles the cumulative nature of
lightningCount).
- Handles the daily reset when count goes back to 0 at midnight.
- Remains compatible with distance-based sensors if you ever change hardware.
How to Apply It
- In Hubitat, go to Apps Code → find Advanced Severe Weather Detector
- Make the two edits above
- Click Save
- Go back to the app and click
Force Matrix Evaluation to confirm it picks up your sensor
You should then see the Light[] counter in the diagnostics telemetry bar start populating when lightning is detected, and the thunderstorm matrix will react in real time rather than only on the timed poll cycle.