Fork of the espurna firmware for `mhsw` switches
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

66 lines
2.1 KiB

  1. /*
  2. THERMOSTAT MODULE
  3. Copyright (C) 2017 by Dmitry Blinov <dblinov76 at gmail dot com>
  4. */
  5. #pragma once
  6. #include "espurna.h"
  7. #include <ArduinoJson.h>
  8. #include <float.h>
  9. #if THERMOSTAT_DISPLAY_SUPPORT
  10. #include <SSD1306.h> // alias for `#include "SSD1306Wire.h"`
  11. #endif
  12. #define ASK_TEMP_RANGE_INTERVAL_INITIAL 15000 // ask initially once per every 15 seconds
  13. #define ASK_TEMP_RANGE_INTERVAL_REGULAR 60000 // ask every minute to be sure
  14. #define MILLIS_IN_SEC 1000
  15. #define MILLIS_IN_MIN 60000
  16. #define THERMOSTAT_STATE_UPDATE_INTERVAL 60000 // 1 min
  17. #define THERMOSTAT_RELAY 0 // use relay 0
  18. #define THERMOSTAT_TEMP_RANGE_MIN 10 // grad. Celsius
  19. #define THERMOSTAT_TEMP_RANGE_MIN_MIN 3 // grad. Celsius
  20. #define THERMOSTAT_TEMP_RANGE_MIN_MAX 30 // grad. Celsius
  21. #define THERMOSTAT_TEMP_RANGE_MAX 20 // grad. Celsius
  22. #define THERMOSTAT_TEMP_RANGE_MAX_MIN 8 // grad. Celsius
  23. #define THERMOSTAT_TEMP_RANGE_MAX_MAX 35 // grad. Celsius
  24. #define THERMOSTAT_ALONE_ON_TIME 5 // 5 min
  25. #define THERMOSTAT_ALONE_OFF_TIME 55 // 55 min
  26. #define THERMOSTAT_MAX_ON_TIME 30 // 30 min
  27. #define THERMOSTAT_MIN_OFF_TIME 10 // 10 min
  28. #define THERMOSTAT_ENABLED_BY_DEFAULT true
  29. #define THERMOSTAT_MODE_COOLER_BY_DEFAULT false
  30. struct temp_t {
  31. float temp;
  32. unsigned long last_update = 0;
  33. bool need_display_update = false;
  34. };
  35. struct temp_range_t {
  36. int min = THERMOSTAT_TEMP_RANGE_MIN;
  37. int max = THERMOSTAT_TEMP_RANGE_MAX;
  38. unsigned long last_update = 0;
  39. unsigned long ask_time = 0;
  40. unsigned long ask_interval = ASK_TEMP_RANGE_INTERVAL_INITIAL;
  41. bool need_display_update = true;
  42. };
  43. using thermostat_callback_f = std::function<void(bool state)>;
  44. void thermostatRegister(thermostat_callback_f callback);
  45. const temp_t& thermostatRemoteTemp();
  46. const temp_range_t& thermostatRange();
  47. void thermostatEnabled(bool enabled);
  48. bool thermostatEnabled();
  49. void thermostatModeCooler(bool cooler);
  50. bool thermostatModeCooler();
  51. void thermostatSetup();