mirror of
				https://github.com/esphome/esphome.git
				synced 2025-11-04 09:01:49 +00:00 
			
		
		
		
	Compare commits
	
		
			10 Commits
		
	
	
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 
						 | 
					a3b2d384f5 | ||
| 
						 | 
					50238f8d72 | ||
| 
						 | 
					704470d606 | ||
| 
						 | 
					f7e6195466 | ||
| 
						 | 
					a0bb7c3ed0 | ||
| 
						 | 
					c4edd3047f | ||
| 
						 | 
					c50da1593a | ||
| 
						 | 
					1d06426281 | ||
| 
						 | 
					9c5b693dd5 | ||
| 
						 | 
					5fecc70db1 | 
@@ -3,7 +3,8 @@ import esphome.config_validation as cv
 | 
				
			|||||||
from esphome import automation
 | 
					from esphome import automation
 | 
				
			||||||
from esphome.automation import Condition
 | 
					from esphome.automation import Condition
 | 
				
			||||||
from esphome.const import CONF_DATA, CONF_DATA_TEMPLATE, CONF_ID, CONF_PASSWORD, CONF_PORT, \
 | 
					from esphome.const import CONF_DATA, CONF_DATA_TEMPLATE, CONF_ID, CONF_PASSWORD, CONF_PORT, \
 | 
				
			||||||
    CONF_REBOOT_TIMEOUT, CONF_SERVICE, CONF_VARIABLES, CONF_SERVICES, CONF_TRIGGER_ID, CONF_EVENT
 | 
					    CONF_REBOOT_TIMEOUT, CONF_SERVICE, CONF_VARIABLES, CONF_SERVICES, CONF_TRIGGER_ID, CONF_EVENT, \
 | 
				
			||||||
 | 
					    CONF_TAG
 | 
				
			||||||
from esphome.core import coroutine_with_priority
 | 
					from esphome.core import coroutine_with_priority
 | 
				
			||||||
 | 
					
 | 
				
			||||||
DEPENDENCIES = ['network']
 | 
					DEPENDENCIES = ['network']
 | 
				
			||||||
@@ -137,6 +138,23 @@ def homeassistant_event_to_code(config, action_id, template_arg, args):
 | 
				
			|||||||
    yield var
 | 
					    yield var
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					HOMEASSISTANT_TAG_SCANNED_ACTION_SCHEMA = cv.maybe_simple_value({
 | 
				
			||||||
 | 
					    cv.GenerateID(): cv.use_id(APIServer),
 | 
				
			||||||
 | 
					    cv.Required(CONF_TAG): cv.templatable(cv.string_strict),
 | 
				
			||||||
 | 
					}, key=CONF_TAG)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					@automation.register_action('homeassistant.tag_scanned', HomeAssistantServiceCallAction,
 | 
				
			||||||
 | 
					                            HOMEASSISTANT_TAG_SCANNED_ACTION_SCHEMA)
 | 
				
			||||||
 | 
					def homeassistant_tag_scanned_to_code(config, action_id, template_arg, args):
 | 
				
			||||||
 | 
					    serv = yield cg.get_variable(config[CONF_ID])
 | 
				
			||||||
 | 
					    var = cg.new_Pvariable(action_id, template_arg, serv, True)
 | 
				
			||||||
 | 
					    cg.add(var.set_service('esphome.tag_scanned'))
 | 
				
			||||||
 | 
					    templ = yield cg.templatable(config[CONF_TAG], args, cg.std_string)
 | 
				
			||||||
 | 
					    cg.add(var.add_data('tag_id', templ))
 | 
				
			||||||
 | 
					    yield var
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@automation.register_condition('api.connected', APIConnectedCondition, {})
 | 
					@automation.register_condition('api.connected', APIConnectedCondition, {})
 | 
				
			||||||
def api_connected_to_code(config, condition_id, template_arg, args):
 | 
					def api_connected_to_code(config, condition_id, template_arg, args):
 | 
				
			||||||
    yield cg.new_Pvariable(condition_id, template_arg)
 | 
					    yield cg.new_Pvariable(condition_id, template_arg)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -11,6 +11,7 @@ static const char *TAG = "remote_receiver.esp32";
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
void RemoteReceiverComponent::setup() {
 | 
					void RemoteReceiverComponent::setup() {
 | 
				
			||||||
  ESP_LOGCONFIG(TAG, "Setting up Remote Receiver...");
 | 
					  ESP_LOGCONFIG(TAG, "Setting up Remote Receiver...");
 | 
				
			||||||
 | 
					  this->pin_->setup();
 | 
				
			||||||
  rmt_config_t rmt{};
 | 
					  rmt_config_t rmt{};
 | 
				
			||||||
  this->config_rmt(rmt);
 | 
					  this->config_rmt(rmt);
 | 
				
			||||||
  rmt.gpio_num = gpio_num_t(this->pin_->get_pin());
 | 
					  rmt.gpio_num = gpio_num_t(this->pin_->get_pin());
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -50,7 +50,7 @@ bool parse_ruuvi_data_byte(const esp32_ble_tracker::adv_data_t &adv_data, RuuviP
 | 
				
			|||||||
      const float acceleration_y = (int16_t(data[8] << 8) + int16_t(data[9])) / 1000.0f;
 | 
					      const float acceleration_y = (int16_t(data[8] << 8) + int16_t(data[9])) / 1000.0f;
 | 
				
			||||||
      const float acceleration_z = (int16_t(data[10] << 8) + int16_t(data[11])) / 1000.0f;
 | 
					      const float acceleration_z = (int16_t(data[10] << 8) + int16_t(data[11])) / 1000.0f;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      const uint8_t power_info = (data[12] << 8) | data[13];
 | 
					      const uint16_t power_info = (uint16_t(data[12] << 8) | data[13]);
 | 
				
			||||||
      const float battery_voltage = ((power_info >> 5) + 1600.0f) / 1000.0f;
 | 
					      const float battery_voltage = ((power_info >> 5) + 1600.0f) / 1000.0f;
 | 
				
			||||||
      const float tx_power = ((power_info & 0x1F) * 2.0f) - 40.0f;
 | 
					      const float tx_power = ((power_info & 0x1F) * 2.0f) - 40.0f;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -33,10 +33,6 @@ void SNTPComponent::setup() {
 | 
				
			|||||||
    sntp_setservername(2, strdup(this->server_3_.c_str()));
 | 
					    sntp_setservername(2, strdup(this->server_3_.c_str()));
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifdef ARDUINO_ARCH_ESP8266
 | 
					 | 
				
			||||||
  // let localtime/gmtime handle timezones, not sntp
 | 
					 | 
				
			||||||
  sntp_set_timezone(0);
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
  sntp_init();
 | 
					  sntp_init();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
void SNTPComponent::dump_config() {
 | 
					void SNTPComponent::dump_config() {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -7,9 +7,9 @@ from .. import tuya_ns, CONF_TUYA_ID, Tuya
 | 
				
			|||||||
DEPENDENCIES = ['tuya']
 | 
					DEPENDENCIES = ['tuya']
 | 
				
			||||||
CODEOWNERS = ['@jesserockz']
 | 
					CODEOWNERS = ['@jesserockz']
 | 
				
			||||||
 | 
					
 | 
				
			||||||
CONF_TARGET_TEMPERATURE_DATAPOINT = "target_temperature_datapoint"
 | 
					CONF_TARGET_TEMPERATURE_DATAPOINT = 'target_temperature_datapoint'
 | 
				
			||||||
CONF_CURRENT_TEMPERATURE_DATAPOINT = "current_temperature_datapoint"
 | 
					CONF_CURRENT_TEMPERATURE_DATAPOINT = 'current_temperature_datapoint'
 | 
				
			||||||
# CONF_ECO_MODE_DATAPOINT = "eco_mode_datapoint"
 | 
					CONF_TEMPERATURE_MULTIPLIER = 'temperature_multiplier'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
TuyaClimate = tuya_ns.class_('TuyaClimate', climate.Climate, cg.Component)
 | 
					TuyaClimate = tuya_ns.class_('TuyaClimate', climate.Climate, cg.Component)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -19,7 +19,7 @@ CONFIG_SCHEMA = cv.All(climate.CLIMATE_SCHEMA.extend({
 | 
				
			|||||||
    cv.Optional(CONF_SWITCH_DATAPOINT): cv.uint8_t,
 | 
					    cv.Optional(CONF_SWITCH_DATAPOINT): cv.uint8_t,
 | 
				
			||||||
    cv.Optional(CONF_TARGET_TEMPERATURE_DATAPOINT): cv.uint8_t,
 | 
					    cv.Optional(CONF_TARGET_TEMPERATURE_DATAPOINT): cv.uint8_t,
 | 
				
			||||||
    cv.Optional(CONF_CURRENT_TEMPERATURE_DATAPOINT): cv.uint8_t,
 | 
					    cv.Optional(CONF_CURRENT_TEMPERATURE_DATAPOINT): cv.uint8_t,
 | 
				
			||||||
    # cv.Optional(CONF_ECO_MODE_DATAPOINT): cv.uint8_t,
 | 
					    cv.Optional(CONF_TEMPERATURE_MULTIPLIER, default=1): cv.positive_float,
 | 
				
			||||||
}).extend(cv.COMPONENT_SCHEMA), cv.has_at_least_one_key(
 | 
					}).extend(cv.COMPONENT_SCHEMA), cv.has_at_least_one_key(
 | 
				
			||||||
    CONF_TARGET_TEMPERATURE_DATAPOINT, CONF_SWITCH_DATAPOINT))
 | 
					    CONF_TARGET_TEMPERATURE_DATAPOINT, CONF_SWITCH_DATAPOINT))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -38,5 +38,4 @@ def to_code(config):
 | 
				
			|||||||
        cg.add(var.set_target_temperature_id(config[CONF_TARGET_TEMPERATURE_DATAPOINT]))
 | 
					        cg.add(var.set_target_temperature_id(config[CONF_TARGET_TEMPERATURE_DATAPOINT]))
 | 
				
			||||||
    if CONF_CURRENT_TEMPERATURE_DATAPOINT in config:
 | 
					    if CONF_CURRENT_TEMPERATURE_DATAPOINT in config:
 | 
				
			||||||
        cg.add(var.set_current_temperature_id(config[CONF_CURRENT_TEMPERATURE_DATAPOINT]))
 | 
					        cg.add(var.set_current_temperature_id(config[CONF_CURRENT_TEMPERATURE_DATAPOINT]))
 | 
				
			||||||
    # if CONF_ECO_MODE_DATAPOINT in config:
 | 
					    cg.add(var.set_temperature_multiplier(config[CONF_TEMPERATURE_MULTIPLIER]))
 | 
				
			||||||
    #     cg.add(var.set_eco_mode_id(config[CONF_ECO_MODE_DATAPOINT]))
 | 
					 | 
				
			||||||
 
 | 
				
			|||||||
@@ -21,28 +21,20 @@ void TuyaClimate::setup() {
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
  if (this->target_temperature_id_.has_value()) {
 | 
					  if (this->target_temperature_id_.has_value()) {
 | 
				
			||||||
    this->parent_->register_listener(*this->target_temperature_id_, [this](TuyaDatapoint datapoint) {
 | 
					    this->parent_->register_listener(*this->target_temperature_id_, [this](TuyaDatapoint datapoint) {
 | 
				
			||||||
      this->target_temperature = datapoint.value_int;
 | 
					      this->target_temperature = datapoint.value_int * this->temperature_multiplier_;
 | 
				
			||||||
      this->compute_state_();
 | 
					      this->compute_state_();
 | 
				
			||||||
      this->publish_state();
 | 
					      this->publish_state();
 | 
				
			||||||
      ESP_LOGD(TAG, "MCU reported target temperature is: %d", datapoint.value_int);
 | 
					      ESP_LOGD(TAG, "MCU reported target temperature is: %.1f", this->target_temperature);
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  if (this->current_temperature_id_.has_value()) {
 | 
					  if (this->current_temperature_id_.has_value()) {
 | 
				
			||||||
    this->parent_->register_listener(*this->current_temperature_id_, [this](TuyaDatapoint datapoint) {
 | 
					    this->parent_->register_listener(*this->current_temperature_id_, [this](TuyaDatapoint datapoint) {
 | 
				
			||||||
      this->current_temperature = datapoint.value_int;
 | 
					      this->current_temperature = datapoint.value_int * this->temperature_multiplier_;
 | 
				
			||||||
      this->compute_state_();
 | 
					      this->compute_state_();
 | 
				
			||||||
      this->publish_state();
 | 
					      this->publish_state();
 | 
				
			||||||
      ESP_LOGD(TAG, "MCU reported current temperature is: %d", datapoint.value_int);
 | 
					      ESP_LOGD(TAG, "MCU reported current temperature is: %.1f", this->current_temperature);
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  // if (this->eco_mode_id_.has_value()) {
 | 
					 | 
				
			||||||
  //   this->parent_->register_listener(*this->eco_mode_id_, [this](TuyaDatapoint datapoint) {
 | 
					 | 
				
			||||||
  //     this->eco_mode = datapoint.value_bool;
 | 
					 | 
				
			||||||
  //     this->compute_state_();
 | 
					 | 
				
			||||||
  //     this->publish_state();
 | 
					 | 
				
			||||||
  //     ESP_LOGD(TAG, "MCU reported eco mode of: %s", ONOFF(datapoint.value_bool));
 | 
					 | 
				
			||||||
  //   });
 | 
					 | 
				
			||||||
  // }
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void TuyaClimate::control(const climate::ClimateCall &call) {
 | 
					void TuyaClimate::control(const climate::ClimateCall &call) {
 | 
				
			||||||
@@ -56,30 +48,17 @@ void TuyaClimate::control(const climate::ClimateCall &call) {
 | 
				
			|||||||
    this->parent_->set_datapoint_value(datapoint);
 | 
					    this->parent_->set_datapoint_value(datapoint);
 | 
				
			||||||
    ESP_LOGD(TAG, "Setting switch: %s", ONOFF(datapoint.value_bool));
 | 
					    ESP_LOGD(TAG, "Setting switch: %s", ONOFF(datapoint.value_bool));
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  if (call.get_target_temperature_low().has_value())
 | 
					
 | 
				
			||||||
    this->target_temperature_low = *call.get_target_temperature_low();
 | 
					 | 
				
			||||||
  if (call.get_target_temperature_high().has_value())
 | 
					 | 
				
			||||||
    this->target_temperature_high = *call.get_target_temperature_high();
 | 
					 | 
				
			||||||
  if (call.get_target_temperature().has_value()) {
 | 
					  if (call.get_target_temperature().has_value()) {
 | 
				
			||||||
    this->target_temperature = *call.get_target_temperature();
 | 
					    this->target_temperature = *call.get_target_temperature();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    TuyaDatapoint datapoint{};
 | 
					    TuyaDatapoint datapoint{};
 | 
				
			||||||
    datapoint.id = *this->target_temperature_id_;
 | 
					    datapoint.id = *this->target_temperature_id_;
 | 
				
			||||||
    datapoint.type = TuyaDatapointType::INTEGER;
 | 
					    datapoint.type = TuyaDatapointType::INTEGER;
 | 
				
			||||||
    datapoint.value_int = (int) this->target_temperature;
 | 
					    datapoint.value_int = (int) (this->target_temperature / this->temperature_multiplier_);
 | 
				
			||||||
    this->parent_->set_datapoint_value(datapoint);
 | 
					    this->parent_->set_datapoint_value(datapoint);
 | 
				
			||||||
    ESP_LOGD(TAG, "Setting target temperature: %d", datapoint.value_int);
 | 
					    ESP_LOGD(TAG, "Setting target temperature: %.1f", this->target_temperature);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  // if (call.get_eco_mode().has_value()) {
 | 
					 | 
				
			||||||
  //   this->eco_mode = *call.get_eco_mode();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  //   TuyaDatapoint datapoint{};
 | 
					 | 
				
			||||||
  //   datapoint.id = *this->eco_mode_id_;
 | 
					 | 
				
			||||||
  //   datapoint.type = TuyaDatapointType::BOOLEAN;
 | 
					 | 
				
			||||||
  //   datapoint.value_bool = this->eco_mode;
 | 
					 | 
				
			||||||
  //   this->parent_->set_datapoint_value(datapoint);
 | 
					 | 
				
			||||||
  //   ESP_LOGD(TAG, "Setting eco mode: %s", ONOFF(datapoint.value_bool));
 | 
					 | 
				
			||||||
  // }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
  this->compute_state_();
 | 
					  this->compute_state_();
 | 
				
			||||||
  this->publish_state();
 | 
					  this->publish_state();
 | 
				
			||||||
@@ -89,7 +68,6 @@ climate::ClimateTraits TuyaClimate::traits() {
 | 
				
			|||||||
  auto traits = climate::ClimateTraits();
 | 
					  auto traits = climate::ClimateTraits();
 | 
				
			||||||
  traits.set_supports_current_temperature(this->current_temperature_id_.has_value());
 | 
					  traits.set_supports_current_temperature(this->current_temperature_id_.has_value());
 | 
				
			||||||
  traits.set_supports_heat_mode(true);
 | 
					  traits.set_supports_heat_mode(true);
 | 
				
			||||||
  // traits.set_supports_eco_mode(this->eco_mode_id_.has_value());
 | 
					 | 
				
			||||||
  traits.set_supports_action(true);
 | 
					  traits.set_supports_action(true);
 | 
				
			||||||
  return traits;
 | 
					  return traits;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -102,8 +80,6 @@ void TuyaClimate::dump_config() {
 | 
				
			|||||||
    ESP_LOGCONFIG(TAG, "  Target Temperature has datapoint ID %u", *this->target_temperature_id_);
 | 
					    ESP_LOGCONFIG(TAG, "  Target Temperature has datapoint ID %u", *this->target_temperature_id_);
 | 
				
			||||||
  if (this->current_temperature_id_.has_value())
 | 
					  if (this->current_temperature_id_.has_value())
 | 
				
			||||||
    ESP_LOGCONFIG(TAG, "  Current Temperature has datapoint ID %u", *this->current_temperature_id_);
 | 
					    ESP_LOGCONFIG(TAG, "  Current Temperature has datapoint ID %u", *this->current_temperature_id_);
 | 
				
			||||||
  // if (this->eco_mode_id_.has_value())
 | 
					 | 
				
			||||||
  //   ESP_LOGCONFIG(TAG, "  Eco Mode has datapoint ID %u", *this->mode_id_);
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void TuyaClimate::compute_state_() {
 | 
					void TuyaClimate::compute_state_() {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -18,7 +18,9 @@ class TuyaClimate : public climate::Climate, public Component {
 | 
				
			|||||||
  void set_current_temperature_id(uint8_t current_temperature_id) {
 | 
					  void set_current_temperature_id(uint8_t current_temperature_id) {
 | 
				
			||||||
    this->current_temperature_id_ = current_temperature_id;
 | 
					    this->current_temperature_id_ = current_temperature_id;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  // void set_eco_mode_id(uint8_t eco_mode_id) { this->eco_mode_id_ = eco_mode_id; }
 | 
					  void set_temperature_multiplier(float temperature_multiplier) {
 | 
				
			||||||
 | 
					    this->temperature_multiplier_ = temperature_multiplier;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  void set_tuya_parent(Tuya *parent) { this->parent_ = parent; }
 | 
					  void set_tuya_parent(Tuya *parent) { this->parent_ = parent; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -38,7 +40,7 @@ class TuyaClimate : public climate::Climate, public Component {
 | 
				
			|||||||
  optional<uint8_t> switch_id_{};
 | 
					  optional<uint8_t> switch_id_{};
 | 
				
			||||||
  optional<uint8_t> target_temperature_id_{};
 | 
					  optional<uint8_t> target_temperature_id_{};
 | 
				
			||||||
  optional<uint8_t> current_temperature_id_{};
 | 
					  optional<uint8_t> current_temperature_id_{};
 | 
				
			||||||
  // optional<uint8_t> eco_mode_id_{};
 | 
					  float temperature_multiplier_{1.0f};
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}  // namespace tuya
 | 
					}  // namespace tuya
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,8 +1,8 @@
 | 
				
			|||||||
import esphome.codegen as cg
 | 
					import esphome.codegen as cg
 | 
				
			||||||
import esphome.config_validation as cv
 | 
					import esphome.config_validation as cv
 | 
				
			||||||
from esphome.components import sensor, esp32_ble_tracker
 | 
					from esphome.components import sensor, esp32_ble_tracker
 | 
				
			||||||
from esphome.const import CONF_MAC_ADDRESS, CONF_TEMPERATURE, \
 | 
					from esphome.const import CONF_BATTERY_LEVEL, CONF_MAC_ADDRESS, CONF_TEMPERATURE, \
 | 
				
			||||||
    UNIT_CELSIUS, ICON_THERMOMETER, UNIT_PERCENT, ICON_WATER_PERCENT, CONF_ID, \
 | 
					    UNIT_CELSIUS, ICON_THERMOMETER, UNIT_PERCENT, ICON_WATER_PERCENT, ICON_BATTERY, CONF_ID, \
 | 
				
			||||||
    CONF_MOISTURE, CONF_ILLUMINANCE, ICON_BRIGHTNESS_5, UNIT_LUX, CONF_CONDUCTIVITY, \
 | 
					    CONF_MOISTURE, CONF_ILLUMINANCE, ICON_BRIGHTNESS_5, UNIT_LUX, CONF_CONDUCTIVITY, \
 | 
				
			||||||
    UNIT_MICROSIEMENS_PER_CENTIMETER, ICON_FLOWER
 | 
					    UNIT_MICROSIEMENS_PER_CENTIMETER, ICON_FLOWER
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -19,6 +19,7 @@ CONFIG_SCHEMA = cv.Schema({
 | 
				
			|||||||
    cv.Optional(CONF_TEMPERATURE): sensor.sensor_schema(UNIT_CELSIUS, ICON_THERMOMETER, 1),
 | 
					    cv.Optional(CONF_TEMPERATURE): sensor.sensor_schema(UNIT_CELSIUS, ICON_THERMOMETER, 1),
 | 
				
			||||||
    cv.Optional(CONF_MOISTURE): sensor.sensor_schema(UNIT_PERCENT, ICON_WATER_PERCENT, 0),
 | 
					    cv.Optional(CONF_MOISTURE): sensor.sensor_schema(UNIT_PERCENT, ICON_WATER_PERCENT, 0),
 | 
				
			||||||
    cv.Optional(CONF_ILLUMINANCE): sensor.sensor_schema(UNIT_LUX, ICON_BRIGHTNESS_5, 0),
 | 
					    cv.Optional(CONF_ILLUMINANCE): sensor.sensor_schema(UNIT_LUX, ICON_BRIGHTNESS_5, 0),
 | 
				
			||||||
 | 
					    cv.Optional(CONF_BATTERY_LEVEL): sensor.sensor_schema(UNIT_PERCENT, ICON_BATTERY, 0),
 | 
				
			||||||
    cv.Optional(CONF_CONDUCTIVITY):
 | 
					    cv.Optional(CONF_CONDUCTIVITY):
 | 
				
			||||||
        sensor.sensor_schema(UNIT_MICROSIEMENS_PER_CENTIMETER, ICON_FLOWER, 0),
 | 
					        sensor.sensor_schema(UNIT_MICROSIEMENS_PER_CENTIMETER, ICON_FLOWER, 0),
 | 
				
			||||||
}).extend(esp32_ble_tracker.ESP_BLE_DEVICE_SCHEMA).extend(cv.COMPONENT_SCHEMA)
 | 
					}).extend(esp32_ble_tracker.ESP_BLE_DEVICE_SCHEMA).extend(cv.COMPONENT_SCHEMA)
 | 
				
			||||||
@@ -43,3 +44,6 @@ def to_code(config):
 | 
				
			|||||||
    if CONF_CONDUCTIVITY in config:
 | 
					    if CONF_CONDUCTIVITY in config:
 | 
				
			||||||
        sens = yield sensor.new_sensor(config[CONF_CONDUCTIVITY])
 | 
					        sens = yield sensor.new_sensor(config[CONF_CONDUCTIVITY])
 | 
				
			||||||
        cg.add(var.set_conductivity(sens))
 | 
					        cg.add(var.set_conductivity(sens))
 | 
				
			||||||
 | 
					    if CONF_BATTERY_LEVEL in config:
 | 
				
			||||||
 | 
					        sens = yield sensor.new_sensor(config[CONF_BATTERY_LEVEL])
 | 
				
			||||||
 | 
					        cg.add(var.set_battery_level(sens))
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -14,6 +14,7 @@ void XiaomiHHCCJCY01::dump_config() {
 | 
				
			|||||||
  LOG_SENSOR("  ", "Moisture", this->moisture_);
 | 
					  LOG_SENSOR("  ", "Moisture", this->moisture_);
 | 
				
			||||||
  LOG_SENSOR("  ", "Conductivity", this->conductivity_);
 | 
					  LOG_SENSOR("  ", "Conductivity", this->conductivity_);
 | 
				
			||||||
  LOG_SENSOR("  ", "Illuminance", this->illuminance_);
 | 
					  LOG_SENSOR("  ", "Illuminance", this->illuminance_);
 | 
				
			||||||
 | 
					  LOG_SENSOR("  ", "Battery Level", this->battery_level_);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
bool XiaomiHHCCJCY01::parse_device(const esp32_ble_tracker::ESPBTDevice &device) {
 | 
					bool XiaomiHHCCJCY01::parse_device(const esp32_ble_tracker::ESPBTDevice &device) {
 | 
				
			||||||
@@ -50,6 +51,8 @@ bool XiaomiHHCCJCY01::parse_device(const esp32_ble_tracker::ESPBTDevice &device)
 | 
				
			|||||||
      this->conductivity_->publish_state(*res->conductivity);
 | 
					      this->conductivity_->publish_state(*res->conductivity);
 | 
				
			||||||
    if (res->illuminance.has_value() && this->illuminance_ != nullptr)
 | 
					    if (res->illuminance.has_value() && this->illuminance_ != nullptr)
 | 
				
			||||||
      this->illuminance_->publish_state(*res->illuminance);
 | 
					      this->illuminance_->publish_state(*res->illuminance);
 | 
				
			||||||
 | 
					    if (res->battery_level.has_value() && this->battery_level_ != nullptr)
 | 
				
			||||||
 | 
					      this->battery_level_->publish_state(*res->battery_level);
 | 
				
			||||||
    success = true;
 | 
					    success = true;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -22,6 +22,7 @@ class XiaomiHHCCJCY01 : public Component, public esp32_ble_tracker::ESPBTDeviceL
 | 
				
			|||||||
  void set_moisture(sensor::Sensor *moisture) { moisture_ = moisture; }
 | 
					  void set_moisture(sensor::Sensor *moisture) { moisture_ = moisture; }
 | 
				
			||||||
  void set_conductivity(sensor::Sensor *conductivity) { conductivity_ = conductivity; }
 | 
					  void set_conductivity(sensor::Sensor *conductivity) { conductivity_ = conductivity; }
 | 
				
			||||||
  void set_illuminance(sensor::Sensor *illuminance) { illuminance_ = illuminance; }
 | 
					  void set_illuminance(sensor::Sensor *illuminance) { illuminance_ = illuminance; }
 | 
				
			||||||
 | 
					  void set_battery_level(sensor::Sensor *battery_level) { battery_level_ = battery_level; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 protected:
 | 
					 protected:
 | 
				
			||||||
  uint64_t address_;
 | 
					  uint64_t address_;
 | 
				
			||||||
@@ -29,6 +30,7 @@ class XiaomiHHCCJCY01 : public Component, public esp32_ble_tracker::ESPBTDeviceL
 | 
				
			|||||||
  sensor::Sensor *moisture_{nullptr};
 | 
					  sensor::Sensor *moisture_{nullptr};
 | 
				
			||||||
  sensor::Sensor *conductivity_{nullptr};
 | 
					  sensor::Sensor *conductivity_{nullptr};
 | 
				
			||||||
  sensor::Sensor *illuminance_{nullptr};
 | 
					  sensor::Sensor *illuminance_{nullptr};
 | 
				
			||||||
 | 
					  sensor::Sensor *battery_level_{nullptr};
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}  // namespace xiaomi_hhccjcy01
 | 
					}  // namespace xiaomi_hhccjcy01
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -2,7 +2,7 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
MAJOR_VERSION = 1
 | 
					MAJOR_VERSION = 1
 | 
				
			||||||
MINOR_VERSION = 15
 | 
					MINOR_VERSION = 15
 | 
				
			||||||
PATCH_VERSION = '0'
 | 
					PATCH_VERSION = '2'
 | 
				
			||||||
__short_version__ = f'{MAJOR_VERSION}.{MINOR_VERSION}'
 | 
					__short_version__ = f'{MAJOR_VERSION}.{MINOR_VERSION}'
 | 
				
			||||||
__version__ = f'{__short_version__}.{PATCH_VERSION}'
 | 
					__version__ = f'{__short_version__}.{PATCH_VERSION}'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -101,6 +101,8 @@ sensor:
 | 
				
			|||||||
      name: "Xiaomi HHCCJCY01 Illuminance"
 | 
					      name: "Xiaomi HHCCJCY01 Illuminance"
 | 
				
			||||||
    conductivity:
 | 
					    conductivity:
 | 
				
			||||||
      name: "Xiaomi HHCCJCY01 Soil Conductivity"
 | 
					      name: "Xiaomi HHCCJCY01 Soil Conductivity"
 | 
				
			||||||
 | 
					    battery_level:
 | 
				
			||||||
 | 
					      name: "Xiaomi HHCCJCY01 Battery Level"
 | 
				
			||||||
  - platform: xiaomi_lywsdcgq
 | 
					  - platform: xiaomi_lywsdcgq
 | 
				
			||||||
    mac_address: 7A:80:8E:19:36:BA
 | 
					    mac_address: 7A:80:8E:19:36:BA
 | 
				
			||||||
    temperature:
 | 
					    temperature:
 | 
				
			||||||
@@ -280,6 +282,9 @@ text_sensor:
 | 
				
			|||||||
          service: light.turn_on
 | 
					          service: light.turn_on
 | 
				
			||||||
          data:
 | 
					          data:
 | 
				
			||||||
            entity_id: light.my_light
 | 
					            entity_id: light.my_light
 | 
				
			||||||
 | 
					      - homeassistant.tag_scanned:
 | 
				
			||||||
 | 
					          tag: 1234-abcd
 | 
				
			||||||
 | 
					      - homeassistant.tag_scanned: 1234-abcd
 | 
				
			||||||
  - platform: template
 | 
					  - platform: template
 | 
				
			||||||
    name: "Template Text Sensor"
 | 
					    name: "Template Text Sensor"
 | 
				
			||||||
    lambda: |-
 | 
					    lambda: |-
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -87,6 +87,7 @@ climate:
 | 
				
			|||||||
    id: tuya_climate
 | 
					    id: tuya_climate
 | 
				
			||||||
    switch_datapoint: 1
 | 
					    switch_datapoint: 1
 | 
				
			||||||
    target_temperature_datapoint: 3
 | 
					    target_temperature_datapoint: 3
 | 
				
			||||||
 | 
					    temperature_multiplier: 0.5
 | 
				
			||||||
 | 
					
 | 
				
			||||||
switch:
 | 
					switch:
 | 
				
			||||||
  - platform: tuya
 | 
					  - platform: tuya
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user