mirror of
				https://github.com/esphome/esphome.git
				synced 2025-10-31 15:12:06 +00:00 
			
		
		
		
	Mhz19 warmup (#6214)
This commit is contained in:
		
				
					committed by
					
						 GitHub
						GitHub
					
				
			
			
				
	
			
			
			
						parent
						
							e4df422798
						
					
				
				
					commit
					430ee43b93
				
			| @@ -29,6 +29,14 @@ void MHZ19Component::setup() { | |||||||
| } | } | ||||||
|  |  | ||||||
| void MHZ19Component::update() { | void MHZ19Component::update() { | ||||||
|  |   uint32_t now_ms = millis(); | ||||||
|  |   uint32_t warmup_ms = this->warmup_seconds_ * 1000; | ||||||
|  |   if (now_ms < warmup_ms) { | ||||||
|  |     ESP_LOGW(TAG, "MHZ19 warming up, %ds left", (warmup_ms - now_ms) / 1000); | ||||||
|  |     this->status_set_warning(); | ||||||
|  |     return; | ||||||
|  |   } | ||||||
|  |  | ||||||
|   uint8_t response[MHZ19_RESPONSE_LENGTH]; |   uint8_t response[MHZ19_RESPONSE_LENGTH]; | ||||||
|   if (!this->mhz19_write_command_(MHZ19_COMMAND_GET_PPM, response)) { |   if (!this->mhz19_write_command_(MHZ19_COMMAND_GET_PPM, response)) { | ||||||
|     ESP_LOGW(TAG, "Reading data from MHZ19 failed!"); |     ESP_LOGW(TAG, "Reading data from MHZ19 failed!"); | ||||||
| @@ -101,6 +109,8 @@ void MHZ19Component::dump_config() { | |||||||
|   } else if (this->abc_boot_logic_ == MHZ19_ABC_DISABLED) { |   } else if (this->abc_boot_logic_ == MHZ19_ABC_DISABLED) { | ||||||
|     ESP_LOGCONFIG(TAG, "  Automatic baseline calibration disabled on boot"); |     ESP_LOGCONFIG(TAG, "  Automatic baseline calibration disabled on boot"); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|  |   ESP_LOGCONFIG(TAG, "  Warmup seconds: %ds", this->warmup_seconds_); | ||||||
| } | } | ||||||
|  |  | ||||||
| }  // namespace mhz19 | }  // namespace mhz19 | ||||||
|   | |||||||
| @@ -25,6 +25,7 @@ class MHZ19Component : public PollingComponent, public uart::UARTDevice { | |||||||
|   void set_temperature_sensor(sensor::Sensor *temperature_sensor) { temperature_sensor_ = temperature_sensor; } |   void set_temperature_sensor(sensor::Sensor *temperature_sensor) { temperature_sensor_ = temperature_sensor; } | ||||||
|   void set_co2_sensor(sensor::Sensor *co2_sensor) { co2_sensor_ = co2_sensor; } |   void set_co2_sensor(sensor::Sensor *co2_sensor) { co2_sensor_ = co2_sensor; } | ||||||
|   void set_abc_enabled(bool abc_enabled) { abc_boot_logic_ = abc_enabled ? MHZ19_ABC_ENABLED : MHZ19_ABC_DISABLED; } |   void set_abc_enabled(bool abc_enabled) { abc_boot_logic_ = abc_enabled ? MHZ19_ABC_ENABLED : MHZ19_ABC_DISABLED; } | ||||||
|  |   void set_warmup_seconds(uint32_t seconds) { warmup_seconds_ = seconds; } | ||||||
|  |  | ||||||
|  protected: |  protected: | ||||||
|   bool mhz19_write_command_(const uint8_t *command, uint8_t *response); |   bool mhz19_write_command_(const uint8_t *command, uint8_t *response); | ||||||
| @@ -32,6 +33,7 @@ class MHZ19Component : public PollingComponent, public uart::UARTDevice { | |||||||
|   sensor::Sensor *temperature_sensor_{nullptr}; |   sensor::Sensor *temperature_sensor_{nullptr}; | ||||||
|   sensor::Sensor *co2_sensor_{nullptr}; |   sensor::Sensor *co2_sensor_{nullptr}; | ||||||
|   MHZ19ABCLogic abc_boot_logic_{MHZ19_ABC_NONE}; |   MHZ19ABCLogic abc_boot_logic_{MHZ19_ABC_NONE}; | ||||||
|  |   uint32_t warmup_seconds_; | ||||||
| }; | }; | ||||||
|  |  | ||||||
| template<typename... Ts> class MHZ19CalibrateZeroAction : public Action<Ts...> { | template<typename... Ts> class MHZ19CalibrateZeroAction : public Action<Ts...> { | ||||||
|   | |||||||
| @@ -18,6 +18,7 @@ from esphome.const import ( | |||||||
| DEPENDENCIES = ["uart"] | DEPENDENCIES = ["uart"] | ||||||
|  |  | ||||||
| CONF_AUTOMATIC_BASELINE_CALIBRATION = "automatic_baseline_calibration" | CONF_AUTOMATIC_BASELINE_CALIBRATION = "automatic_baseline_calibration" | ||||||
|  | CONF_WARMUP_TIME = "warmup_time" | ||||||
|  |  | ||||||
| mhz19_ns = cg.esphome_ns.namespace("mhz19") | mhz19_ns = cg.esphome_ns.namespace("mhz19") | ||||||
| MHZ19Component = mhz19_ns.class_("MHZ19Component", cg.PollingComponent, uart.UARTDevice) | MHZ19Component = mhz19_ns.class_("MHZ19Component", cg.PollingComponent, uart.UARTDevice) | ||||||
| @@ -45,6 +46,9 @@ CONFIG_SCHEMA = ( | |||||||
|                 state_class=STATE_CLASS_MEASUREMENT, |                 state_class=STATE_CLASS_MEASUREMENT, | ||||||
|             ), |             ), | ||||||
|             cv.Optional(CONF_AUTOMATIC_BASELINE_CALIBRATION): cv.boolean, |             cv.Optional(CONF_AUTOMATIC_BASELINE_CALIBRATION): cv.boolean, | ||||||
|  |             cv.Optional( | ||||||
|  |                 CONF_WARMUP_TIME, default="75s" | ||||||
|  |             ): cv.positive_time_period_seconds, | ||||||
|         } |         } | ||||||
|     ) |     ) | ||||||
|     .extend(cv.polling_component_schema("60s")) |     .extend(cv.polling_component_schema("60s")) | ||||||
| @@ -68,6 +72,8 @@ async def to_code(config): | |||||||
|     if CONF_AUTOMATIC_BASELINE_CALIBRATION in config: |     if CONF_AUTOMATIC_BASELINE_CALIBRATION in config: | ||||||
|         cg.add(var.set_abc_enabled(config[CONF_AUTOMATIC_BASELINE_CALIBRATION])) |         cg.add(var.set_abc_enabled(config[CONF_AUTOMATIC_BASELINE_CALIBRATION])) | ||||||
|  |  | ||||||
|  |     cg.add(var.set_warmup_seconds(config[CONF_WARMUP_TIME])) | ||||||
|  |  | ||||||
|  |  | ||||||
| CALIBRATION_ACTION_SCHEMA = maybe_simple_id( | CALIBRATION_ACTION_SCHEMA = maybe_simple_id( | ||||||
|     { |     { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user