homebridge-snowsense

A simple snow checker acting as an Occupancy Sensor, using DarkSky for forecast and current conditions

Usage no npm install needed!

<script type="module">
  import homebridgeSnowsense from 'https://cdn.skypack.dev/homebridge-snowsense';
</script>

README

homebridge-snowsense

An Occupancy Sensor that indicates snowy conditions using local weather forecast

This is a plugin for homebridge that is a simple Occupancy Sensor that automatically detects occupancy ON when it's going to snow soon and OFF a while after it stops snowing. Think of snow being the occupant and you have ample warning of when the (un)welcome guest arrives.

This is based on my earlier project, homebridge-snowswitch that was similar but acted as a switch rather than a sensor.

Thanks to rmkjr for suggeting moving from a Switch to an Occupancy Sensor.

Installation

  1. Install homebridge using: npm install -g homebridge
  2. Install this plugin using: npm install -g homebridge-snowsense
  3. Sign up and get a free API Key from OpenWeather API
  4. Update your configuration file. Read below.

Configuration

Add the following information to your config file.

provider [default='darksky'] (values 'darksky' or 'openweathermap') DarkSky still works if you have an old API key, but I recommand moving to OpenWeather instead.

key [no default] is the Secret Key as assigned from DarkSky or OpenWeather

latitude and longitude fields [no default] identify the location for the snow checking. You can find the coordinates by looking at Google Maps and finding the numbers after the @ symbol. Eg: @40.7484405,-73.9878584 means Latitude is 40.748 and Longitude is -73.988.

units [default='imperial'] (values 'standard', 'metric' or 'imperial') is the units defined in OpenWeather Docs. This defines the unit for Fahrenheit vs Celcius and Inches vs Millimeters (if needed).

forecastFrequency field [default=15] is how frequently (in minutes) to download the weather forecast. Don't do it too frequently or you will use up your API limit for the day.

beforeSnowStarts field [default=3] is number of hours before snow starts that the occupancy should go on.

afterSnowStops field [default=3] is number of hours after snow stops that the occupancy should go off.

precipTempIsSnow field [no default] is the temperature at which we should assume it's snowing if there is precipitation. In some areas, the precipitation type may not work so we can just check see if there is precipitation and temperature below this number (in units set above). If this is not set, we will not use temperature.

sensors field [default=''] is a comma-delimited list of sensors to load. If this is left empty, they will all be added. The four available sensors are:

  • past: Load the WasSnowing sensor, indicating if it has snowed in the past within the time of afterSnowStops.
  • present: Load the IsSnowing sensor, indicating that it is currently snowing.
  • future: Load the WillSnow sensor, indicating that it is forecasted to snow in the future within the time of beforeSnowStarts.
  • any: Load the IsSnowy sensor, which is all of the above and is extra optimistic by showing snow even if it was only forecasted but didn't actually snow in recent hours. It continues to be "snowy" even if there is no longer a forecast of snow.
"platforms": [
  {
    "platform": "SnowSense",
    "name": "Snow Sense",
    "key": "XXXXXXX_GET_YOUR_OWN_KEY_XXXXXXX",
    "latitude": "42.326",
    "longitude": "-71.220",
    "units": "us",
    "forecastFrequency": 15,
    "beforeSnowStarts": 3,
    "afterSnowStops": 3,
    "sensors": "any, present, future"
  }
]

Why this exists

I created this for a specific use case, which is to turn on and off snow melting mats outside my house.

I have been happy with HeatTrak Snow Melting Mats and when I purchased wireless outlets for them, I liked them even more. So, on one snowy weekend I decided to take the automation to the next level and build this plug-in.

Now, if the local forecast expects snow in the next few hours, the Snow Melting Mats will turn on, and when the snow stops falling, they Mats will turn off a few hours later.

I bought a set of Etekcity outlets and installed homebridge and homebridge-vesync to control them from the my Apple-centric home using HomeKit.

To make them work with HomeKit, I needed to get homebridge working. I had an old Raspberry Pi sitting around so I installed it there and put the device in a closet with the rest of my network gear.

This should work pretty well with any switches you can get working with HomeKit, and if you can also get a homebridge setup working and a DarkSky API key, then the HomeKit App end of this is pretty trivial.

I had originally made additions to homebridge-weather-station-extended, a more sophisticated weather forecasting add-on where I had added fields indicating that it had snowed recently or was expected to snow soon, but that required more complex setup from the iPhone App. I wanted to make something simpler at the front-end and have this single-purpose.

Thanks to @mbriney on github for pointing out that the wunderground api is going away and suggesting DarkSky for the replacement api.

Thanks to @apollo316 on github for pointing out that the DarkSky api is going away and @nicoryan and others for recommending OpenWeather.

How to set up the automation

  • Launch the iPhone or iPad Home app
  • Create scenes; one to turn on the Snow Mats and another to turn them off
  • Create a new Automation
  • Select An accessory is Controlled as the trigger for the automation
  • Select the Controller IsSnowy
  • Select When to be Turns On
  • Select the Snow Mats On scene
  • Repeat for turning Off when the controller Turns Off

Contributors

This plugin borrowed code from and was inspired by homebridge-weather-station-extended which is a fork of homebridge-weather-station which is a fork of homebridge-wunderground.