bbernstein / homebridge-snowsense

Senses when it's "snowy", meaning it snowed recently or will likely snow soon
Apache License 2.0
4 stars 1 forks source link

Feature request: ability to include temperature and/or total accumulation in trigger #20

Closed nvogt closed 1 year ago

nvogt commented 1 year ago

I really appreciate your work in this plug-in - it’s been very useful for triggering the heating wires on our roof, especially in the middle of the night.

I was wondering if it might be possible to incorporate temperature and/or expected total snowfall when deciding when to trigger the occupancy sensor. There have a been a few times where it’s started to snow and the temp has been in the mid to high 30s, and so nothing actually accumulates (and therefore not necessary to turn the heating wires on).

Maybe something as simple as seeing if the low temp in the next 4-6 hours is going to drop below freezing? Or if total snowfall in next 12 hrs is expected to be greater than 1 inch?

Thanks!

bbxp commented 1 year ago

In the previous versions I had an option of considering it snowy when there is precipitation and temperature below some value, but I took that out recently as openweathermap seemed to have a pretty clear indicator of snow compared to what I was using in the past.

It's technically easy to add this feature, but the hard part is how to explain it to users in the configuration page. Any suggestions of what this might look like on the config screen?

Perhaps a switch to turn it on called "Only When Cold" and then a field to enter a temperature that is cold enough (like 32 deg F)? There might be various cases to consider here, so it might take some time to test that there aren't too many false positives or negatives.

I'm open to ideas and happy to make a beta version you can try out for a while and see if the settings work.

In the case of roof heaters, it may make sense to only care if there's over an inch of snow expected, but for my walkway matts, any snow is enough to want to turn on the heat for a while.

Maybe we can make a simple "roof wire" mode that would have a group of settings that are configured differently than the simple settings it currently has.

I'd love to hear some suggestions on that.

nvogt commented 1 year ago

I really like the idea of an "Only When Cold" option. This would probably take care of 75% of the times when it's not ideal to have the heating wires turn on (based on my experience this winter).

For instance, if snow is expected in the next hour (I have my settings for 1 hour), but it's expected to be 35 degrees then, the occupancy sensor will not trigger. Once it's snowing, the occupancy sensor would be triggered if it's expected to continue to snow in the next hour and the temp at that time is expected to be below 32 (or whatever temp the user sets -- I think the heating wire manufacturers/installers recommend 34F).

A description of the setting could be "prevents triggering occupancy sensor if temperature is not below the set point, when snow accumulation is unlikely" or phrased alternatively "occupancy sensor will not trigger until temperature is expected to fall below the set point at which accumulation is likely."

Also, a thing that might be useful for people with heating wires would be triggering the occupancy sensor based on expected duration of snow. So the occupancy sensor wouldn't trigger if it's just expected to snow for 1 hour, but would trigger if snow is expected for the next 4 hours (or however long the user sets). In this case, total duration of snow is used as a proxy for accumulation (e.g. more hours of snow = more total accumulation of snow). This might be easier/simpler than having to calculate total expected accumulation (which seems like it's dependent on setting more thresholds like an amount cut off and a hour cut off).

I'd be happy to test out a beta version if either of these options aren't too difficult to incorporate. Thanks!

bbernstein commented 1 year ago

I just released a beta: 2.0.5-beta.4

In this version I reorganized the configs into different sub-areas. Now there is a "temperature" section where you can set "Only When Cold" and a temperature for that.

The code will only consider it "snowy" during a time period if it meets the regular criteria, but in addition the temperature at that tiime must be below (or equal) to that temperature threshold.

Next I'll think about and look into number of expected hours of future snow should trigger the sensor.

Here are some thoughts: Looking at next X hours, if Y of those hours are expected to have snow, then consider it snowy. We may need to discuss certain scenarios. Let's say we have an array of booleans, each indicating "snow expected", here are some possible scenarios:

Not snowing in the next four hours, but then it is snowing in the fifth: [false, false, false, false true]

Snowing in the next 1, 3, and 5 hours, but not in 2 or 3. In other words 3 of the next 5 hours (60%) are snowing, there could be some accumulation, or maybe it's on and off flurries. [true, false, true, false, true]

Snowing for the next three hours, but stopping after that [true, true, true, false, false]

Snowing in hours 3, 4, and 5, but not 1 or 2. Another case of 60% of the next 5 hours are snowing, and there will probably be some accumulation, but not right away. [false, false, true, true, true]

We can extend this to look at 10 hours instead of five, but this is just to get some examples. If we only turn on the trigger when it's snowing in the next hour, then we would probably ignore any case where the first value is false, but then for any case where the next hour is true, we can see how many of the following hours are expecting snow.

I'm not sure yet how this rule will play out yet but thinking it through still.

bbernstein commented 1 year ago

Maybe the simplest solution for the "only turn on if there may be accumulation" would be to say it is snowy if: every hour for the next X hours have snow predicted

If the value is 3, then these forecasts would be true: [true, true, true, false, false] [true, true, true, true, false]

these would be false: [false, true, true, true, true] [true, false, true, true, true] [true, true, false, true, true]

let's say it's been snowing for the past two hours, but now the forecast looks like: [true, false, false, false, false]

Even though it's been snowing, the snowy will not get turned on, but since the "past" timer is still ticket, it will still need to expire into the past, so that second condition (snowed recently) will still be invoked and so the sensor will not get switched off.

I'll give this case a try. It's another new config value which we can call: consecutiveHoursOfSnowIsSnowy So the code will always look forward at least that number of hours (if > 0) and one condition of Snowy is that every hour up to that number of hours need to have snow predicted.

Worth a try.

bbernstein commented 1 year ago

Added config and logic for consecutiveHoursOfSnowIsSnowy It's a little hard to explain, but basically, if it sees that it's going to be snowing within the normal given hours, then it will check for the next consecutiveHoursOfSnowIsSnowy hours and see if there are any non-snowy hours in there. If so, the nit will not trigger the sensor.

This is now available as: 2.0.5-beta.6

nvogt commented 1 year ago

This is great - just installed the beta version and will report back if there are any issues (unfortunately doesn’t look like it’s going to snow soon).

I agree the consecutive hours of snow seems like the most simple implementation and will help prevent triggering of the sensor when there are brief intermittent flurries. It might miss scenarios where it snows for a few hours, then stops, then snows for a few hours again, but that seems like an acceptable trade off.

Thanks again for all your work on this!

bbernstein commented 1 year ago

I'm closing this ticket and merging the code in it's beta form for now. I'm going to add more features as requested in another issue before making a release. Please open a new issue if we want to follow up about the features: consecutiveHoursOfSnowIsSnowy and onlyWhenCold