Перейти к содержанию

Сенсоры

SensorTempEntity

Датчик температуры.

Sber Temperature Sensor entity -- maps HA temperature sensors to Sber sensor_temp.

SENSOR_TEMP_CATEGORY module-attribute

SENSOR_TEMP_CATEGORY = 'sensor_temp'

Sber device category for temperature sensor entities.

SensorTempEntity

SensorTempEntity(entity_data)

Bases: SimpleReadOnlySensor

Sber temperature sensor entity.

Reports temperature readings from HA sensor entities to the Sber cloud. Temperature is transmitted as an integer value multiplied by 10 (e.g. 22.5 C becomes 225).

Initialize temperature sensor entity.

Parameters:

Name Type Description Default
entity_data dict

HA entity registry dict containing entity metadata.

required
Source code in custom_components/sber_mqtt_bridge/devices/sensor_temp.py
def __init__(self, entity_data: dict) -> None:
    """Initialize temperature sensor entity.

    Args:
        entity_data: HA entity registry dict containing entity metadata.
    """
    super().__init__(SENSOR_TEMP_CATEGORY, entity_data)
    self.temperature = 0.0
    self._air_pressure: int | None = None
    self._linked_humidity: int | None = None
    self._temp_unit: str = "c"

fill_by_ha_state

fill_by_ha_state(ha_state)

Parse HA state and update temperature and air pressure values.

When the HA sensor reports Fahrenheit (unit_of_measurement == "°F"), the incoming value is converted to Celsius before storage. Sber's temperature feature is always transmitted as °C × 10 on the wire (see https://developers.sber.ru/docs/ru/smarthome/c2c/temperature — "The 'integer_value' should be set to the temperature multiplied by 10 (e.g., 220 for 22 degrees Celsius)"); temp_unit_view is a display-only hint. Without conversion, 72°F would ship as 720 and be decoded as 72°C.

Parameters:

Name Type Description Default
ha_state dict

HA state dict with 'state' containing the temperature reading. Attributes may include 'pressure' for air pressure.

required
Source code in custom_components/sber_mqtt_bridge/devices/sensor_temp.py
def fill_by_ha_state(self, ha_state: dict) -> None:
    """Parse HA state and update temperature and air pressure values.

    When the HA sensor reports Fahrenheit (``unit_of_measurement == "°F"``),
    the incoming value is converted to Celsius before storage. Sber's
    ``temperature`` feature is always transmitted as ``°C × 10`` on the
    wire (see
    https://developers.sber.ru/docs/ru/smarthome/c2c/temperature —
    "The 'integer_value' should be set to the temperature multiplied
    by 10 (e.g., 220 for 22 degrees Celsius)"); ``temp_unit_view`` is
    a display-only hint. Without conversion, ``72°F`` would ship as
    ``720`` and be decoded as ``72°C``.

    Args:
        ha_state: HA state dict with 'state' containing the temperature reading.
            Attributes may include 'pressure' for air pressure.
    """
    super().fill_by_ha_state(ha_state)
    try:
        temp = float(ha_state.get("state", 0))
        self.temperature = temp if math.isfinite(temp) else 0.0
    except (ValueError, TypeError):
        self.temperature = 0.0
    attrs = ha_state.get("attributes", {})
    # Unit detection + °F→°C share one implementation with
    # SensorAirEntity (devices/utils/temperature.py) so the two
    # categories that emit ``temperature`` cannot drift apart.
    self._temp_unit = detect_temp_unit(attrs)
    self.temperature = to_celsius(self.temperature, self._temp_unit)
    pressure = attrs.get("pressure")
    if pressure is not None:
        try:
            self._air_pressure = int(pressure)
        except (TypeError, ValueError):
            self._air_pressure = None
    else:
        self._air_pressure = None

update_linked_data

update_linked_data(role, ha_state)

Inject data from a linked entity (humidity, battery, signal).

Parameters:

Name Type Description Default
role str

Link role name.

required
ha_state dict

HA state dict.

required
Source code in custom_components/sber_mqtt_bridge/devices/sensor_temp.py
def update_linked_data(self, role: str, ha_state: dict) -> None:
    """Inject data from a linked entity (humidity, battery, signal).

    Args:
        role: Link role name.
        ha_state: HA state dict.
    """
    super().update_linked_data(role, ha_state)
    if role == "humidity":
        state_val = ha_state.get("state")
        if state_val not in (None, "unknown", "unavailable"):
            with contextlib.suppress(TypeError, ValueError):
                self._linked_humidity = round(float(state_val))

HumiditySensorEntity

Датчик влажности.

Sber Humidity Sensor entity -- maps HA humidity sensors to Sber sensor_temp category.

HUMIDITY_SENSOR_CATEGORY module-attribute

HUMIDITY_SENSOR_CATEGORY = 'sensor_temp'

Sber device category for humidity sensor entities (shares sensor_temp category).

HumiditySensorEntity

HumiditySensorEntity(entity_data)

Bases: SimpleReadOnlySensor

Sber humidity sensor entity.

Reports humidity readings from HA sensor entities to the Sber cloud. Humidity is transmitted as a plain integer percentage (0-100).

Initialize humidity sensor entity.

Parameters:

Name Type Description Default
entity_data dict

HA entity registry dict containing entity metadata.

required
Source code in custom_components/sber_mqtt_bridge/devices/humidity_sensor.py
def __init__(self, entity_data: dict) -> None:
    """Initialize humidity sensor entity.

    Args:
        entity_data: HA entity registry dict containing entity metadata.
    """
    super().__init__(HUMIDITY_SENSOR_CATEGORY, entity_data)
    self.humidity = 0.0
    self._linked_temperature: float | None = None

fill_by_ha_state

fill_by_ha_state(ha_state)

Parse HA state and update humidity value.

Parameters:

Name Type Description Default
ha_state dict

HA state dict with 'state' containing the humidity reading.

required
Source code in custom_components/sber_mqtt_bridge/devices/humidity_sensor.py
def fill_by_ha_state(self, ha_state: dict) -> None:
    """Parse HA state and update humidity value.

    Args:
        ha_state: HA state dict with 'state' containing the humidity reading.
    """
    super().fill_by_ha_state(ha_state)
    try:
        self.humidity = float(ha_state.get("state", 0))
    except (ValueError, TypeError):
        self.humidity = 0.0

update_linked_data

update_linked_data(role, ha_state)

Inject data from a linked entity (temperature, battery, signal).

Parameters:

Name Type Description Default
role str

Link role name.

required
ha_state dict

HA state dict.

required
Source code in custom_components/sber_mqtt_bridge/devices/humidity_sensor.py
def update_linked_data(self, role: str, ha_state: dict) -> None:
    """Inject data from a linked entity (temperature, battery, signal).

    Args:
        role: Link role name.
        ha_state: HA state dict.
    """
    super().update_linked_data(role, ha_state)
    if role == "temperature":
        state_val = ha_state.get("state")
        if state_val not in (None, "unknown", "unavailable"):
            with contextlib.suppress(TypeError, ValueError):
                self._linked_temperature = float(state_val)

MotionSensorEntity

Датчик движения (PIR).

Sber Motion Sensor entity -- maps HA motion binary sensors to Sber sensor_pir.

MOTION_SENSOR_CATEGORY module-attribute

MOTION_SENSOR_CATEGORY = 'sensor_pir'

Sber device category for PIR / motion sensor entities.

MotionSensorEntity

MotionSensorEntity(entity_data)

Bases: TamperAlarmMuteMixin, SimpleReadOnlySensor

Sber motion sensor entity.

Reports motion detection state from HA binary_sensor entities (device_class=motion) to the Sber cloud via the pir feature.

Per Sber specification, pir uses ENUM type with value "pir" when motion is detected. This is an event-based sensor.

Initialize motion sensor entity.

Parameters:

Name Type Description Default
entity_data dict

HA entity registry dict containing entity metadata.

required
Source code in custom_components/sber_mqtt_bridge/devices/motion_sensor.py
def __init__(self, entity_data: dict) -> None:
    """Initialize motion sensor entity.

    Args:
        entity_data: HA entity registry dict containing entity metadata.
    """
    super().__init__(MOTION_SENSOR_CATEGORY, entity_data)
    self.motion_detected = False

fill_by_ha_state

fill_by_ha_state(ha_state)

Parse HA state and update motion detection flag and tamper alarm.

Parameters:

Name Type Description Default
ha_state dict

HA state dict; 'on' means motion detected.

required
Source code in custom_components/sber_mqtt_bridge/devices/motion_sensor.py
def fill_by_ha_state(self, ha_state: dict) -> None:
    """Parse HA state and update motion detection flag and tamper alarm.

    Args:
        ha_state: HA state dict; 'on' means motion detected.
    """
    super().fill_by_ha_state(ha_state)
    self.motion_detected = ha_state.get("state") == "on"
    self._parse_tamper_alarm_mute(ha_state.get("attributes", {}))

DoorSensorEntity

Датчик открытия двери/окна.

Sber Door Sensor entity -- maps HA door/window/garage binary sensors to Sber sensor_door.

DOOR_SENSOR_CATEGORY module-attribute

DOOR_SENSOR_CATEGORY = 'sensor_door'

Sber device category for door/window contact sensor entities.

DoorSensorEntity

DoorSensorEntity(entity_data)

Bases: TamperAlarmMuteMixin, SimpleReadOnlySensor

Sber door sensor entity.

Reports open/close state from HA binary_sensor entities (device_class=door, window, garage_door) to the Sber cloud via the doorcontact_state feature.

Per Sber specification, doorcontact_state uses BOOL type: - true = open (contacts disconnected) - false = closed (contacts connected)

Initialize door sensor entity.

Parameters:

Name Type Description Default
entity_data dict

HA entity registry dict containing entity metadata.

required
Source code in custom_components/sber_mqtt_bridge/devices/door_sensor.py
def __init__(self, entity_data: dict) -> None:
    """Initialize door sensor entity.

    Args:
        entity_data: HA entity registry dict containing entity metadata.
    """
    super().__init__(DOOR_SENSOR_CATEGORY, entity_data)
    self.is_open = False

fill_by_ha_state

fill_by_ha_state(ha_state)

Parse HA state and update open/close status and tamper alarm.

Parameters:

Name Type Description Default
ha_state dict

HA state dict; 'on' means door is open.

required
Source code in custom_components/sber_mqtt_bridge/devices/door_sensor.py
def fill_by_ha_state(self, ha_state: dict) -> None:
    """Parse HA state and update open/close status and tamper alarm.

    Args:
        ha_state: HA state dict; 'on' means door is open.
    """
    super().fill_by_ha_state(ha_state)
    self.is_open = ha_state.get("state") == "on"
    self._parse_tamper_alarm_mute(ha_state.get("attributes", {}))

WaterLeakSensorEntity

Датчик протечки воды.

Sber Water Leak Sensor entity -- maps HA moisture binary sensors to Sber sensor_water_leak.

WATER_LEAK_SENSOR_CATEGORY module-attribute

WATER_LEAK_SENSOR_CATEGORY = 'sensor_water_leak'

Sber device category for water leak sensor entities.

WaterLeakSensorEntity

WaterLeakSensorEntity(entity_data)

Bases: TamperAlarmMuteMixin, SimpleReadOnlySensor

Sber water leak sensor entity.

Reports leak detection state from HA binary_sensor entities (device_class=moisture) to the Sber cloud via the water_leak_state feature.

Optionally supports tamper_alarm and alarm_mute from HA attributes.

Initialize water leak sensor entity.

Parameters:

Name Type Description Default
entity_data dict

HA entity registry dict containing entity metadata.

required
Source code in custom_components/sber_mqtt_bridge/devices/water_leak_sensor.py
def __init__(self, entity_data: dict) -> None:
    """Initialize water leak sensor entity.

    Args:
        entity_data: HA entity registry dict containing entity metadata.
    """
    super().__init__(WATER_LEAK_SENSOR_CATEGORY, entity_data)
    self.leak_detected = False

fill_by_ha_state

fill_by_ha_state(ha_state)

Parse HA state and update leak detection flag.

Parameters:

Name Type Description Default
ha_state dict

HA state dict; 'on' means leak detected.

required
Source code in custom_components/sber_mqtt_bridge/devices/water_leak_sensor.py
def fill_by_ha_state(self, ha_state: dict) -> None:
    """Parse HA state and update leak detection flag.

    Args:
        ha_state: HA state dict; 'on' means leak detected.
    """
    super().fill_by_ha_state(ha_state)
    self.leak_detected = ha_state.get("state") == "on"
    self._parse_tamper_alarm_mute(ha_state.get("attributes", {}))

GasSensorEntity

Датчик газа.

Sber Gas Sensor entity -- maps HA gas binary sensors to Sber sensor_gas.

GAS_SENSOR_CATEGORY module-attribute

GAS_SENSOR_CATEGORY = 'sensor_gas'

Sber device category for gas leak sensor entities.

GasSensorEntity

GasSensorEntity(entity_data)

Bases: TamperAlarmMuteMixin, SimpleReadOnlySensor

Sber gas sensor entity.

Reports gas leak detection state from HA binary_sensor entities (device_class=gas) to the Sber cloud via the gas_leak_state feature.

Per Sber specification, gas_leak_state uses BOOL type: - true = gas leak detected - false = no gas leak

Optionally supports alarm_mute (BOOL) if the HA entity provides it in attributes.

Initialize gas sensor entity.

Parameters:

Name Type Description Default
entity_data dict

HA entity registry dict containing entity metadata.

required
Source code in custom_components/sber_mqtt_bridge/devices/gas_sensor.py
def __init__(self, entity_data: dict) -> None:
    """Initialize gas sensor entity.

    Args:
        entity_data: HA entity registry dict containing entity metadata.
    """
    super().__init__(GAS_SENSOR_CATEGORY, entity_data)
    self.gas_detected: bool = False

fill_by_ha_state

fill_by_ha_state(ha_state)

Parse HA state and update gas leak detection flag, tamper and alarm_mute.

Parameters:

Name Type Description Default
ha_state dict

HA state dict; 'on' means gas leak detected.

required
Source code in custom_components/sber_mqtt_bridge/devices/gas_sensor.py
def fill_by_ha_state(self, ha_state: dict) -> None:
    """Parse HA state and update gas leak detection flag, tamper and alarm_mute.

    Args:
        ha_state: HA state dict; 'on' means gas leak detected.
    """
    super().fill_by_ha_state(ha_state)
    self.gas_detected = ha_state.get("state") == "on"
    self._parse_tamper_alarm_mute(ha_state.get("attributes", {}))

SmokeSensorEntity

Датчик дыма.

Sber Smoke Sensor entity -- maps HA smoke binary sensors to Sber sensor_smoke.

SMOKE_SENSOR_CATEGORY module-attribute

SMOKE_SENSOR_CATEGORY = 'sensor_smoke'

Sber device category for smoke sensor entities.

SmokeSensorEntity

SmokeSensorEntity(entity_data)

Bases: TamperAlarmMuteMixin, SimpleReadOnlySensor

Sber smoke sensor entity.

Reports smoke detection state from HA binary_sensor entities (device_class=smoke) to the Sber cloud via the smoke_state feature.

Per Sber specification, smoke_state uses BOOL type: - true = smoke detected - false = no smoke

Optionally supports alarm_mute (BOOL) if the HA entity provides it in attributes.

Initialize smoke sensor entity.

Parameters:

Name Type Description Default
entity_data dict

HA entity registry dict containing entity metadata.

required
Source code in custom_components/sber_mqtt_bridge/devices/smoke_sensor.py
def __init__(self, entity_data: dict) -> None:
    """Initialize smoke sensor entity.

    Args:
        entity_data: HA entity registry dict containing entity metadata.
    """
    super().__init__(SMOKE_SENSOR_CATEGORY, entity_data)
    self.smoke_detected: bool = False

fill_by_ha_state

fill_by_ha_state(ha_state)

Parse HA state and update smoke detection flag, tamper and alarm_mute.

Parameters:

Name Type Description Default
ha_state dict

HA state dict; 'on' means smoke detected.

required
Source code in custom_components/sber_mqtt_bridge/devices/smoke_sensor.py
def fill_by_ha_state(self, ha_state: dict) -> None:
    """Parse HA state and update smoke detection flag, tamper and alarm_mute.

    Args:
        ha_state: HA state dict; 'on' means smoke detected.
    """
    super().fill_by_ha_state(ha_state)
    self.smoke_detected = ha_state.get("state") == "on"
    self._parse_tamper_alarm_mute(ha_state.get("attributes", {}))