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.

67 lines
2.3 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. #define ASK_TEMP_RANGE_INTERVAL_INITIAL 15000 // ask initially once per every 15 seconds
  8. #define ASK_TEMP_RANGE_INTERVAL_REGULAR 60000 // ask every minute to be sure
  9. #define MILLIS_IN_SEC 1000
  10. #define MILLIS_IN_MIN 60000
  11. #define THERMOSTAT_STATE_UPDATE_INTERVAL 60000 // 1 min
  12. #define THERMOSTAT_RELAY 0 // use relay 0
  13. #define THERMOSTAT_TEMP_RANGE_MIN 10 // grad. Celsius
  14. #define THERMOSTAT_TEMP_RANGE_MIN_MIN 3 // grad. Celsius
  15. #define THERMOSTAT_TEMP_RANGE_MIN_MAX 30 // grad. Celsius
  16. #define THERMOSTAT_TEMP_RANGE_MAX 20 // grad. Celsius
  17. #define THERMOSTAT_TEMP_RANGE_MAX_MIN 8 // grad. Celsius
  18. #define THERMOSTAT_TEMP_RANGE_MAX_MAX 35 // grad. Celsius
  19. #define THERMOSTAT_ALONE_ON_TIME 5 // 5 min
  20. #define THERMOSTAT_ALONE_OFF_TIME 55 // 55 min
  21. #define THERMOSTAT_MAX_ON_TIME 30 // 30 min
  22. #define THERMOSTAT_MIN_OFF_TIME 10 // 10 min
  23. #define THERMOSTAT_ENABLED_BY_DEFAULT true
  24. #define THERMOSTAT_MODE_COOLER_BY_DEFAULT false
  25. #define MQTT_TOPIC_HOLD_TEMP "hold_temp"
  26. #define MQTT_TOPIC_HOLD_TEMP_MIN "min"
  27. #define MQTT_TOPIC_HOLD_TEMP_MAX "max"
  28. #define MQTT_TOPIC_REMOTE_TEMP "remote_temp"
  29. #define MQTT_TOPIC_ASK_TEMP_RANGE "ask_temp_range"
  30. #define MQTT_TOPIC_NOTIFY_TEMP_RANGE_MIN "notify_temp_range_min"
  31. #define MQTT_TOPIC_NOTIFY_TEMP_RANGE_MAX "notify_temp_range_max"
  32. struct temp_t {
  33. float temp;
  34. unsigned long last_update = 0;
  35. bool need_display_update = false;
  36. };
  37. struct temp_range_t {
  38. int min = THERMOSTAT_TEMP_RANGE_MIN;
  39. int max = THERMOSTAT_TEMP_RANGE_MAX;
  40. unsigned long last_update = 0;
  41. unsigned long ask_time = 0;
  42. unsigned long ask_interval = ASK_TEMP_RANGE_INTERVAL_INITIAL;
  43. bool need_display_update = true;
  44. };
  45. using thermostat_callback_f = std::function<void(bool state)>;
  46. void thermostatRegister(thermostat_callback_f callback);
  47. const temp_t& thermostatRemoteTemp();
  48. const temp_range_t& thermostatRange();
  49. void thermostatEnabled(bool enabled);
  50. bool thermostatEnabled();
  51. void thermostatModeCooler(bool cooler);
  52. bool thermostatModeCooler();
  53. void thermostatSetup();