Home Assistant Unofficial Reference 2024.12.1
homeassistant.components.template.sensor Namespace Reference

Classes

class  SensorTemplate
 
class  TriggerSensorEntity
 

Functions

None _async_create_template_tracking_entities (AddEntitiesCallback async_add_entities, HomeAssistant hass, list[dict] definitions, str|None unique_id_prefix)
 
SensorTemplate async_create_preview_sensor (HomeAssistant hass, str name, dict[str, Any] config)
 
None async_setup_entry (HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)
 
None async_setup_platform (HomeAssistant hass, ConfigType config, AddEntitiesCallback async_add_entities, DiscoveryInfoType|None discovery_info=None)
 
def extra_validation_checks (val)
 
list[dict] rewrite_legacy_to_modern_conf (HomeAssistant hass, dict[str, dict] cfg)
 
def validate_last_reset (val)
 

Variables

 _LOGGER = logging.getLogger(__name__)
 
dictionary LEGACY_FIELDS
 
 LEGACY_SENSOR_SCHEMA
 
 PLATFORM_SCHEMA
 
 SENSOR_CONFIG_SCHEMA
 
 SENSOR_SCHEMA
 

Detailed Description

Allows the creation of a sensor that breaks out state_attributes.

Function Documentation

◆ _async_create_template_tracking_entities()

None homeassistant.components.template.sensor._async_create_template_tracking_entities ( AddEntitiesCallback  async_add_entities,
HomeAssistant  hass,
list[dict]  definitions,
str | None  unique_id_prefix 
)
private
Create the template sensors.

Definition at line 180 of file sensor.py.

◆ async_create_preview_sensor()

SensorTemplate homeassistant.components.template.sensor.async_create_preview_sensor ( HomeAssistant  hass,
str  name,
dict[str, Any]   config 
)
Create a preview sensor.

Definition at line 250 of file sensor.py.

◆ async_setup_entry()

None homeassistant.components.template.sensor.async_setup_entry ( HomeAssistant  hass,
ConfigEntry  config_entry,
AddEntitiesCallback  async_add_entities 
)
Initialize config entry.

Definition at line 237 of file sensor.py.

◆ async_setup_platform()

None homeassistant.components.template.sensor.async_setup_platform ( HomeAssistant  hass,
ConfigType  config,
AddEntitiesCallback  async_add_entities,
DiscoveryInfoType | None   discovery_info = None 
)
Set up the template sensors.

Definition at line 206 of file sensor.py.

◆ extra_validation_checks()

def homeassistant.components.template.sensor.extra_validation_checks (   val)
Run extra validation checks.

Definition at line 130 of file sensor.py.

◆ rewrite_legacy_to_modern_conf()

list[dict] homeassistant.components.template.sensor.rewrite_legacy_to_modern_conf ( HomeAssistant  hass,
dict[str, dict]   cfg 
)
Rewrite legacy sensor definitions to modern ones.

Definition at line 145 of file sensor.py.

◆ validate_last_reset()

def homeassistant.components.template.sensor.validate_last_reset (   val)
Run extra validation checks.

Definition at line 73 of file sensor.py.

Variable Documentation

◆ _LOGGER

homeassistant.components.template.sensor._LOGGER = logging.getLogger(__name__)
private

Definition at line 176 of file sensor.py.

◆ LEGACY_FIELDS

dictionary homeassistant.components.template.sensor.LEGACY_FIELDS
Initial value:
1 = {
2  CONF_FRIENDLY_NAME_TEMPLATE: CONF_NAME,
3  CONF_FRIENDLY_NAME: CONF_NAME,
4  CONF_VALUE_TEMPLATE: CONF_STATE,
5 }

Definition at line 66 of file sensor.py.

◆ LEGACY_SENSOR_SCHEMA

homeassistant.components.template.sensor.LEGACY_SENSOR_SCHEMA
Initial value:
1 = vol.All(
2  cv.deprecated(ATTR_ENTITY_ID),
3  vol.Schema(
4  {
5  vol.Required(CONF_VALUE_TEMPLATE): cv.template,
6  vol.Optional(CONF_ICON_TEMPLATE): cv.template,
7  vol.Optional(CONF_ENTITY_PICTURE_TEMPLATE): cv.template,
8  vol.Optional(CONF_FRIENDLY_NAME_TEMPLATE): cv.template,
9  vol.Optional(CONF_AVAILABILITY_TEMPLATE): cv.template,
10  vol.Optional(CONF_ATTRIBUTE_TEMPLATES, default={}): vol.Schema(
11  {cv.string: cv.template}
12  ),
13  vol.Optional(CONF_FRIENDLY_NAME): cv.string,
14  vol.Optional(CONF_UNIT_OF_MEASUREMENT): cv.string,
15  vol.Optional(CONF_DEVICE_CLASS): DEVICE_CLASSES_SCHEMA,
16  vol.Optional(ATTR_ENTITY_ID): cv.entity_ids,
17  vol.Optional(CONF_UNIQUE_ID): cv.string,
18  }
19  ),
20 )

Definition at line 108 of file sensor.py.

◆ PLATFORM_SCHEMA

homeassistant.components.template.sensor.PLATFORM_SCHEMA
Initial value:
1 = vol.All(
2  SENSOR_PLATFORM_SCHEMA.extend(
3  {
4  vol.Optional(CONF_TRIGGER): cv.match_all, # to raise custom warning
5  vol.Required(CONF_SENSORS): cv.schema_with_slug_keys(LEGACY_SENSOR_SCHEMA),
6  }
7  ),
8  extra_validation_checks,
9 )

Definition at line 166 of file sensor.py.

◆ SENSOR_CONFIG_SCHEMA

homeassistant.components.template.sensor.SENSOR_CONFIG_SCHEMA
Initial value:
1 = vol.All(
2  vol.Schema(
3  {
4  vol.Required(CONF_STATE): cv.template,
5  vol.Optional(CONF_DEVICE_ID): selector.DeviceSelector(),
6  }
7  ).extend(TEMPLATE_SENSOR_BASE_SCHEMA.schema),
8 )

Definition at line 99 of file sensor.py.

◆ SENSOR_SCHEMA

homeassistant.components.template.sensor.SENSOR_SCHEMA
Initial value:
1 = vol.All(
2  vol.Schema(
3  {
4  vol.Required(CONF_STATE): cv.template,
5  vol.Optional(ATTR_LAST_RESET): cv.template,
6  }
7  )
8  .extend(TEMPLATE_SENSOR_BASE_SCHEMA.schema)
9  .extend(TEMPLATE_ENTITY_COMMON_SCHEMA.schema),
10  validate_last_reset,
11 )

Definition at line 86 of file sensor.py.