Hacker News new | ask | show | jobs
by spdustin 653 days ago
It largely centers on this template sensor:

    {% set distance = states('sensor.lightning_detector_lightning_distance')|int(999) %}
    {% set bearing = states('sensor.lightning_detector_lightning_azimuth')|int %}
    {% set wind_bearing = states('sensor.pirateweather_wind_bearing')|int %}
    
    {% set bearing_normalized = bearing % 360 + 360 %}
    {% set bearing_left = (wind_bearing-80) % 360 + 360 %}
    {% set bearing_right = (wind_bearing+80) % 360 + 360 %}
    {% set distance_max = 20 %}
    {% set bearing_min = ([bearing_left,bearing_right]|sort)[0] %}
    {% set bearing_max = ([bearing_left,bearing_right]|sort)[-1] %}
    {% set approaching = bearing_min < bearing < bearing_max %}
    {% set close = distance < distance_max %}
    {{ close and approaching }}
It normalizes the bearings to avoid dealing with the 0-degree crossover, and is reevaluated automatically whenever the three tracked entities change their state.

The automation itself is set to "restart" mode, and fires whenever the template sensor is true. It then waits for the sensor to be false for 15 minutes, and for the nearest lightning distance to be > 20 miles for 15 minutes.

Why a 20 mile radius? It's a good enough proxy for the time it takes them to prep for (get clothes ready, etc) and then actually shower (and brush teeth, 30 minutes total), and most storms in my area tend to move through at ~40mph.