Hacker News new | ask | show | jobs
by rwjwjuwjudf 3734 days ago
Also you can decouple the handling of ac and heat, and check the current state to prevent a redundant transition into the current state.

  if (temp > max + error)
    if (off (ac))
      turn_on (ac);

  if (temp < max - error)
    if (on (ac))
      turn_off (ac);

  if (temp < min - error)
    if (off (heat))
      turn_on (heat);

  if (temp > min + error)
    if (on (heat))
      turn_off (heat);
2 comments

If in between samples you go from above max to below min you'll have both heat and ac on.

The take-away is that like programming lift controllers[0] it's not quite as simple as it might first seem - many many edge cases.

[0] http://play.elevatorsaga.com/ (for example)

I think that's wrong, because all 4 if-statements are evaluated for each sample.

But yes agreed, in general there are lots of edge cases. I actually wrote a finite state machine specification for an elevator in a logic class once. Without having really thought about it much, it looks like the biggest problems with thermostats are dealing with scalars, sampling frequencies, and sampling error.

I'd prefer a nice fuzzy logic rule set with some variable speed on the heat/fans.