2019-02-13 20:21:14 +00:00
|
|
|
"""Support for monitoring a Smappee energy sensor."""
|
2021-08-20 21:20:45 +00:00
|
|
|
from homeassistant.components.sensor import (
|
|
|
|
STATE_CLASS_MEASUREMENT,
|
|
|
|
STATE_CLASS_TOTAL_INCREASING,
|
|
|
|
SensorEntity,
|
|
|
|
)
|
2021-07-20 18:06:23 +00:00
|
|
|
from homeassistant.const import (
|
2021-08-20 21:20:45 +00:00
|
|
|
DEVICE_CLASS_ENERGY,
|
2021-07-20 18:06:23 +00:00
|
|
|
DEVICE_CLASS_POWER,
|
2021-08-20 21:20:45 +00:00
|
|
|
DEVICE_CLASS_VOLTAGE,
|
2021-07-20 18:06:23 +00:00
|
|
|
ELECTRIC_POTENTIAL_VOLT,
|
2021-08-20 21:20:45 +00:00
|
|
|
ENERGY_KILO_WATT_HOUR,
|
2021-07-20 18:06:23 +00:00
|
|
|
ENERGY_WATT_HOUR,
|
|
|
|
POWER_WATT,
|
|
|
|
)
|
2019-03-21 05:56:46 +00:00
|
|
|
|
2020-08-10 11:34:18 +00:00
|
|
|
from .const import DOMAIN
|
2018-02-18 22:34:28 +00:00
|
|
|
|
2020-06-17 11:28:28 +00:00
|
|
|
TREND_SENSORS = {
|
|
|
|
"total_power": [
|
|
|
|
"Total consumption - Active power",
|
|
|
|
None,
|
|
|
|
POWER_WATT,
|
|
|
|
"total_power",
|
|
|
|
DEVICE_CLASS_POWER,
|
2020-08-10 11:34:18 +00:00
|
|
|
True, # both cloud and local
|
2020-06-17 11:28:28 +00:00
|
|
|
],
|
|
|
|
"alwayson": [
|
|
|
|
"Always on - Active power",
|
|
|
|
None,
|
2019-07-31 19:25:30 +00:00
|
|
|
POWER_WATT,
|
2020-06-17 11:28:28 +00:00
|
|
|
"alwayson",
|
|
|
|
DEVICE_CLASS_POWER,
|
2020-08-10 11:34:18 +00:00
|
|
|
False, # cloud only
|
2020-06-17 11:28:28 +00:00
|
|
|
],
|
|
|
|
"power_today": [
|
|
|
|
"Total consumption - Today",
|
2021-08-20 21:20:45 +00:00
|
|
|
None,
|
2020-06-17 11:28:28 +00:00
|
|
|
ENERGY_WATT_HOUR,
|
|
|
|
"power_today",
|
2021-08-20 21:20:45 +00:00
|
|
|
DEVICE_CLASS_ENERGY,
|
2020-08-10 11:34:18 +00:00
|
|
|
False, # cloud only
|
2020-06-17 11:28:28 +00:00
|
|
|
],
|
|
|
|
"power_current_hour": [
|
|
|
|
"Total consumption - Current hour",
|
2021-08-20 21:20:45 +00:00
|
|
|
None,
|
2020-06-17 11:28:28 +00:00
|
|
|
ENERGY_WATT_HOUR,
|
|
|
|
"power_current_hour",
|
2021-08-20 21:20:45 +00:00
|
|
|
DEVICE_CLASS_ENERGY,
|
2020-08-10 11:34:18 +00:00
|
|
|
False, # cloud only
|
2019-07-31 19:25:30 +00:00
|
|
|
],
|
2020-06-17 11:28:28 +00:00
|
|
|
"power_last_5_minutes": [
|
|
|
|
"Total consumption - Last 5 minutes",
|
2021-08-20 21:20:45 +00:00
|
|
|
None,
|
2020-06-17 11:28:28 +00:00
|
|
|
ENERGY_WATT_HOUR,
|
|
|
|
"power_last_5_minutes",
|
2021-08-20 21:20:45 +00:00
|
|
|
DEVICE_CLASS_ENERGY,
|
2020-08-10 11:34:18 +00:00
|
|
|
False, # cloud only
|
2020-02-28 19:46:48 +00:00
|
|
|
],
|
2019-07-31 19:25:30 +00:00
|
|
|
"alwayson_today": [
|
2020-06-17 11:28:28 +00:00
|
|
|
"Always on - Today",
|
2021-08-20 21:20:45 +00:00
|
|
|
None,
|
2020-06-17 11:28:28 +00:00
|
|
|
ENERGY_WATT_HOUR,
|
|
|
|
"alwayson_today",
|
2021-08-20 21:20:45 +00:00
|
|
|
DEVICE_CLASS_ENERGY,
|
2020-08-10 11:34:18 +00:00
|
|
|
False, # cloud only
|
2020-06-17 11:28:28 +00:00
|
|
|
],
|
|
|
|
}
|
2020-07-08 20:45:01 +00:00
|
|
|
REACTIVE_SENSORS = {
|
|
|
|
"total_reactive_power": [
|
|
|
|
"Total consumption - Reactive power",
|
|
|
|
None,
|
|
|
|
POWER_WATT,
|
|
|
|
"total_reactive_power",
|
|
|
|
DEVICE_CLASS_POWER,
|
|
|
|
]
|
|
|
|
}
|
2020-06-17 11:28:28 +00:00
|
|
|
SOLAR_SENSORS = {
|
|
|
|
"solar_power": [
|
|
|
|
"Total production - Active power",
|
|
|
|
None,
|
|
|
|
POWER_WATT,
|
|
|
|
"solar_power",
|
|
|
|
DEVICE_CLASS_POWER,
|
2020-08-10 11:34:18 +00:00
|
|
|
True, # both cloud and local
|
2019-07-31 19:25:30 +00:00
|
|
|
],
|
|
|
|
"solar_today": [
|
2020-06-17 11:28:28 +00:00
|
|
|
"Total production - Today",
|
2021-08-20 21:20:45 +00:00
|
|
|
None,
|
2020-06-17 11:28:28 +00:00
|
|
|
ENERGY_WATT_HOUR,
|
|
|
|
"solar_today",
|
2021-08-22 02:17:36 +00:00
|
|
|
DEVICE_CLASS_ENERGY,
|
2020-08-10 11:34:18 +00:00
|
|
|
False, # cloud only
|
2019-07-31 19:25:30 +00:00
|
|
|
],
|
2020-06-17 11:28:28 +00:00
|
|
|
"solar_current_hour": [
|
|
|
|
"Total production - Current hour",
|
2021-08-20 21:20:45 +00:00
|
|
|
None,
|
2020-06-17 11:28:28 +00:00
|
|
|
ENERGY_WATT_HOUR,
|
|
|
|
"solar_current_hour",
|
2021-08-22 02:17:36 +00:00
|
|
|
DEVICE_CLASS_ENERGY,
|
2020-08-10 11:34:18 +00:00
|
|
|
False, # cloud only
|
2019-07-31 19:25:30 +00:00
|
|
|
],
|
2020-06-17 11:28:28 +00:00
|
|
|
}
|
|
|
|
VOLTAGE_SENSORS = {
|
|
|
|
"phase_voltages_a": [
|
|
|
|
"Phase voltages - A",
|
2021-08-20 21:20:45 +00:00
|
|
|
None,
|
2021-07-20 18:06:23 +00:00
|
|
|
ELECTRIC_POTENTIAL_VOLT,
|
2020-06-17 11:28:28 +00:00
|
|
|
"phase_voltage_a",
|
2021-08-20 21:20:45 +00:00
|
|
|
DEVICE_CLASS_VOLTAGE,
|
2020-07-07 14:15:52 +00:00
|
|
|
["ONE", "TWO", "THREE_STAR", "THREE_DELTA"],
|
2020-02-25 01:52:14 +00:00
|
|
|
],
|
2020-06-17 11:28:28 +00:00
|
|
|
"phase_voltages_b": [
|
|
|
|
"Phase voltages - B",
|
2021-08-20 21:20:45 +00:00
|
|
|
None,
|
2021-07-20 18:06:23 +00:00
|
|
|
ELECTRIC_POTENTIAL_VOLT,
|
2020-06-17 11:28:28 +00:00
|
|
|
"phase_voltage_b",
|
2021-08-20 21:20:45 +00:00
|
|
|
DEVICE_CLASS_VOLTAGE,
|
2020-07-07 14:15:52 +00:00
|
|
|
["TWO", "THREE_STAR", "THREE_DELTA"],
|
2020-02-25 01:52:14 +00:00
|
|
|
],
|
2020-06-17 11:28:28 +00:00
|
|
|
"phase_voltages_c": [
|
|
|
|
"Phase voltages - C",
|
2021-08-20 21:20:45 +00:00
|
|
|
None,
|
2021-07-20 18:06:23 +00:00
|
|
|
ELECTRIC_POTENTIAL_VOLT,
|
2020-06-17 11:28:28 +00:00
|
|
|
"phase_voltage_c",
|
2021-08-20 21:20:45 +00:00
|
|
|
DEVICE_CLASS_VOLTAGE,
|
2020-07-07 14:15:52 +00:00
|
|
|
["THREE_STAR"],
|
2019-07-31 19:25:30 +00:00
|
|
|
],
|
2020-06-17 11:28:28 +00:00
|
|
|
"line_voltages_a": [
|
|
|
|
"Line voltages - A",
|
2021-08-20 21:20:45 +00:00
|
|
|
None,
|
2021-07-20 18:06:23 +00:00
|
|
|
ELECTRIC_POTENTIAL_VOLT,
|
2020-06-17 11:28:28 +00:00
|
|
|
"line_voltage_a",
|
2021-08-20 21:20:45 +00:00
|
|
|
DEVICE_CLASS_VOLTAGE,
|
2020-07-07 14:15:52 +00:00
|
|
|
["ONE", "TWO", "THREE_STAR", "THREE_DELTA"],
|
2019-07-31 19:25:30 +00:00
|
|
|
],
|
2020-06-17 11:28:28 +00:00
|
|
|
"line_voltages_b": [
|
|
|
|
"Line voltages - B",
|
2021-08-20 21:20:45 +00:00
|
|
|
None,
|
2021-07-20 18:06:23 +00:00
|
|
|
ELECTRIC_POTENTIAL_VOLT,
|
2020-06-17 11:28:28 +00:00
|
|
|
"line_voltage_b",
|
2021-08-20 21:20:45 +00:00
|
|
|
DEVICE_CLASS_VOLTAGE,
|
2020-07-07 14:15:52 +00:00
|
|
|
["TWO", "THREE_STAR", "THREE_DELTA"],
|
2020-06-17 11:28:28 +00:00
|
|
|
],
|
|
|
|
"line_voltages_c": [
|
|
|
|
"Line voltages - C",
|
2021-08-20 21:20:45 +00:00
|
|
|
None,
|
2021-07-20 18:06:23 +00:00
|
|
|
ELECTRIC_POTENTIAL_VOLT,
|
2020-06-17 11:28:28 +00:00
|
|
|
"line_voltage_c",
|
2021-08-20 21:20:45 +00:00
|
|
|
DEVICE_CLASS_VOLTAGE,
|
2020-07-07 14:15:52 +00:00
|
|
|
["THREE_STAR", "THREE_DELTA"],
|
2019-07-31 19:25:30 +00:00
|
|
|
],
|
2018-02-18 22:34:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-06-17 11:28:28 +00:00
|
|
|
async def async_setup_entry(hass, config_entry, async_add_entities):
|
2018-02-18 22:34:28 +00:00
|
|
|
"""Set up the Smappee sensor."""
|
2020-08-10 11:34:18 +00:00
|
|
|
smappee_base = hass.data[DOMAIN][config_entry.entry_id]
|
2018-02-18 22:34:28 +00:00
|
|
|
|
2020-06-17 11:28:28 +00:00
|
|
|
entities = []
|
|
|
|
for service_location in smappee_base.smappee.service_locations.values():
|
|
|
|
# Add all basic sensors (realtime values and aggregators)
|
2020-08-10 11:34:18 +00:00
|
|
|
# Some are available in local only env
|
2021-07-15 04:44:57 +00:00
|
|
|
for sensor, attributes in TREND_SENSORS.items():
|
|
|
|
if not service_location.local_polling or attributes[5]:
|
2020-08-10 11:34:18 +00:00
|
|
|
entities.append(
|
|
|
|
SmappeeSensor(
|
|
|
|
smappee_base=smappee_base,
|
|
|
|
service_location=service_location,
|
|
|
|
sensor=sensor,
|
2021-07-15 04:44:57 +00:00
|
|
|
attributes=attributes,
|
2020-08-10 11:34:18 +00:00
|
|
|
)
|
2020-06-17 11:28:28 +00:00
|
|
|
)
|
|
|
|
|
2020-07-08 20:45:01 +00:00
|
|
|
if service_location.has_reactive_value:
|
2021-07-15 04:44:57 +00:00
|
|
|
for reactive_sensor, attributes in REACTIVE_SENSORS.items():
|
2020-07-08 20:45:01 +00:00
|
|
|
entities.append(
|
|
|
|
SmappeeSensor(
|
|
|
|
smappee_base=smappee_base,
|
|
|
|
service_location=service_location,
|
|
|
|
sensor=reactive_sensor,
|
2021-07-15 04:44:57 +00:00
|
|
|
attributes=attributes,
|
2020-07-08 20:45:01 +00:00
|
|
|
)
|
|
|
|
)
|
|
|
|
|
2020-08-10 11:34:18 +00:00
|
|
|
# Add solar sensors (some are available in local only env)
|
2020-06-17 11:28:28 +00:00
|
|
|
if service_location.has_solar_production:
|
2021-07-15 04:44:57 +00:00
|
|
|
for sensor, attributes in SOLAR_SENSORS.items():
|
|
|
|
if not service_location.local_polling or attributes[5]:
|
2020-08-10 11:34:18 +00:00
|
|
|
entities.append(
|
|
|
|
SmappeeSensor(
|
|
|
|
smappee_base=smappee_base,
|
|
|
|
service_location=service_location,
|
|
|
|
sensor=sensor,
|
2021-07-15 04:44:57 +00:00
|
|
|
attributes=attributes,
|
2020-08-10 11:34:18 +00:00
|
|
|
)
|
2019-07-31 19:25:30 +00:00
|
|
|
)
|
2020-06-17 11:28:28 +00:00
|
|
|
|
|
|
|
# Add all CT measurements
|
|
|
|
for measurement_id, measurement in service_location.measurements.items():
|
|
|
|
entities.append(
|
|
|
|
SmappeeSensor(
|
|
|
|
smappee_base=smappee_base,
|
|
|
|
service_location=service_location,
|
|
|
|
sensor="load",
|
|
|
|
attributes=[
|
|
|
|
measurement.name,
|
|
|
|
None,
|
|
|
|
POWER_WATT,
|
|
|
|
measurement_id,
|
|
|
|
DEVICE_CLASS_POWER,
|
|
|
|
],
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
2020-07-08 20:45:01 +00:00
|
|
|
# Add phase- and line voltages if available
|
|
|
|
if service_location.has_voltage_values:
|
|
|
|
for sensor_name, sensor in VOLTAGE_SENSORS.items():
|
|
|
|
if service_location.phase_type in sensor[5]:
|
2021-04-22 08:12:13 +00:00
|
|
|
if (
|
|
|
|
sensor_name.startswith("line_")
|
|
|
|
and service_location.local_polling
|
|
|
|
):
|
|
|
|
continue
|
2020-07-08 20:45:01 +00:00
|
|
|
entities.append(
|
|
|
|
SmappeeSensor(
|
|
|
|
smappee_base=smappee_base,
|
|
|
|
service_location=service_location,
|
|
|
|
sensor=sensor_name,
|
|
|
|
attributes=sensor,
|
|
|
|
)
|
2020-06-17 11:28:28 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
# Add Gas and Water sensors
|
|
|
|
for sensor_id, sensor in service_location.sensors.items():
|
|
|
|
for channel in sensor.channels:
|
|
|
|
gw_icon = "mdi:gas-cylinder"
|
|
|
|
if channel.get("type") == "water":
|
|
|
|
gw_icon = "mdi:water"
|
2018-02-18 22:34:28 +00:00
|
|
|
|
2020-06-17 11:28:28 +00:00
|
|
|
entities.append(
|
|
|
|
SmappeeSensor(
|
|
|
|
smappee_base=smappee_base,
|
|
|
|
service_location=service_location,
|
|
|
|
sensor="sensor",
|
|
|
|
attributes=[
|
|
|
|
channel.get("name"),
|
|
|
|
gw_icon,
|
|
|
|
channel.get("uom"),
|
|
|
|
f"{sensor_id}-{channel.get('channel')}",
|
|
|
|
None,
|
|
|
|
],
|
2019-12-29 16:18:23 +00:00
|
|
|
)
|
2020-06-17 11:28:28 +00:00
|
|
|
)
|
2018-04-06 21:14:31 +00:00
|
|
|
|
2021-08-20 21:20:45 +00:00
|
|
|
# Add today_energy_kwh sensors for switches
|
|
|
|
for actuator_id, actuator in service_location.actuators.items():
|
|
|
|
if actuator.type == "SWITCH":
|
|
|
|
entities.append(
|
|
|
|
SmappeeSensor(
|
|
|
|
smappee_base=smappee_base,
|
|
|
|
service_location=service_location,
|
|
|
|
sensor="switch",
|
|
|
|
attributes=[
|
|
|
|
f"{actuator.name} - energy today",
|
|
|
|
None,
|
|
|
|
ENERGY_KILO_WATT_HOUR,
|
|
|
|
actuator_id,
|
|
|
|
DEVICE_CLASS_ENERGY,
|
|
|
|
False, # cloud only
|
|
|
|
],
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
2020-06-17 11:28:28 +00:00
|
|
|
async_add_entities(entities, True)
|
2018-02-18 22:34:28 +00:00
|
|
|
|
|
|
|
|
2021-03-22 18:54:14 +00:00
|
|
|
class SmappeeSensor(SensorEntity):
|
2018-02-18 22:34:28 +00:00
|
|
|
"""Implementation of a Smappee sensor."""
|
|
|
|
|
2020-06-17 11:28:28 +00:00
|
|
|
def __init__(self, smappee_base, service_location, sensor, attributes):
|
2018-04-06 21:14:31 +00:00
|
|
|
"""Initialize the Smappee sensor."""
|
2020-06-17 11:28:28 +00:00
|
|
|
self._smappee_base = smappee_base
|
|
|
|
self._service_location = service_location
|
2018-02-18 22:34:28 +00:00
|
|
|
self._sensor = sensor
|
|
|
|
self.data = None
|
|
|
|
self._state = None
|
2020-06-17 11:28:28 +00:00
|
|
|
self._name = attributes[0]
|
|
|
|
self._icon = attributes[1]
|
|
|
|
self._unit_of_measurement = attributes[2]
|
|
|
|
self._sensor_id = attributes[3]
|
|
|
|
self._device_class = attributes[4]
|
2018-02-18 22:34:28 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def name(self):
|
2020-06-17 11:28:28 +00:00
|
|
|
"""Return the name for this sensor."""
|
2021-08-20 21:20:45 +00:00
|
|
|
if self._sensor in ("sensor", "load", "switch"):
|
2020-06-17 11:28:28 +00:00
|
|
|
return (
|
|
|
|
f"{self._service_location.service_location_name} - "
|
|
|
|
f"{self._sensor.title()} - {self._name}"
|
|
|
|
)
|
2018-02-18 22:34:28 +00:00
|
|
|
|
2020-06-17 11:28:28 +00:00
|
|
|
return f"{self._service_location.service_location_name} - {self._name}"
|
2018-02-18 22:34:28 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def icon(self):
|
|
|
|
"""Icon to use in the frontend."""
|
|
|
|
return self._icon
|
|
|
|
|
|
|
|
@property
|
2021-08-12 15:40:55 +00:00
|
|
|
def native_value(self):
|
2018-02-18 22:34:28 +00:00
|
|
|
"""Return the state of the sensor."""
|
|
|
|
return self._state
|
|
|
|
|
2020-06-17 11:28:28 +00:00
|
|
|
@property
|
|
|
|
def device_class(self):
|
|
|
|
"""Return the class of this device, from component DEVICE_CLASSES."""
|
|
|
|
return self._device_class
|
|
|
|
|
2021-08-20 21:20:45 +00:00
|
|
|
@property
|
|
|
|
def state_class(self):
|
|
|
|
"""Return the state class of this device."""
|
|
|
|
scm = STATE_CLASS_MEASUREMENT
|
|
|
|
|
|
|
|
if self._sensor in (
|
|
|
|
"power_today",
|
|
|
|
"power_current_hour",
|
|
|
|
"power_last_5_minutes",
|
|
|
|
"solar_today",
|
|
|
|
"solar_current_hour",
|
|
|
|
"alwayson_today",
|
|
|
|
"switch",
|
|
|
|
):
|
|
|
|
scm = STATE_CLASS_TOTAL_INCREASING
|
|
|
|
|
|
|
|
return scm
|
|
|
|
|
2018-02-18 22:34:28 +00:00
|
|
|
@property
|
2021-08-12 15:40:55 +00:00
|
|
|
def native_unit_of_measurement(self):
|
2018-02-18 22:34:28 +00:00
|
|
|
"""Return the unit of measurement of this entity, if any."""
|
|
|
|
return self._unit_of_measurement
|
|
|
|
|
|
|
|
@property
|
2020-08-27 11:56:20 +00:00
|
|
|
def unique_id(
|
|
|
|
self,
|
|
|
|
):
|
2020-06-17 11:28:28 +00:00
|
|
|
"""Return the unique ID for this sensor."""
|
2021-08-20 21:20:45 +00:00
|
|
|
if self._sensor in ("load", "sensor", "switch"):
|
2020-06-17 11:28:28 +00:00
|
|
|
return (
|
|
|
|
f"{self._service_location.device_serial_number}-"
|
|
|
|
f"{self._service_location.service_location_id}-"
|
|
|
|
f"{self._sensor}-{self._sensor_id}"
|
|
|
|
)
|
|
|
|
|
|
|
|
return (
|
|
|
|
f"{self._service_location.device_serial_number}-"
|
|
|
|
f"{self._service_location.service_location_id}-"
|
|
|
|
f"{self._sensor}"
|
|
|
|
)
|
|
|
|
|
|
|
|
@property
|
|
|
|
def device_info(self):
|
|
|
|
"""Return the device info for this sensor."""
|
|
|
|
return {
|
|
|
|
"identifiers": {(DOMAIN, self._service_location.device_serial_number)},
|
|
|
|
"name": self._service_location.service_location_name,
|
|
|
|
"manufacturer": "Smappee",
|
|
|
|
"model": self._service_location.device_model,
|
|
|
|
"sw_version": self._service_location.firmware_version,
|
|
|
|
}
|
2018-02-18 22:34:28 +00:00
|
|
|
|
2020-06-17 11:28:28 +00:00
|
|
|
async def async_update(self):
|
2018-02-18 22:34:28 +00:00
|
|
|
"""Get the latest data from Smappee and update the state."""
|
2020-06-17 11:28:28 +00:00
|
|
|
await self._smappee_base.async_update()
|
2018-02-18 22:34:28 +00:00
|
|
|
|
2020-06-17 11:28:28 +00:00
|
|
|
if self._sensor == "total_power":
|
|
|
|
self._state = self._service_location.total_power
|
|
|
|
elif self._sensor == "total_reactive_power":
|
|
|
|
self._state = self._service_location.total_reactive_power
|
|
|
|
elif self._sensor == "solar_power":
|
|
|
|
self._state = self._service_location.solar_power
|
|
|
|
elif self._sensor == "alwayson":
|
|
|
|
self._state = self._service_location.alwayson
|
2021-07-29 23:20:03 +00:00
|
|
|
elif self._sensor in (
|
2020-06-17 11:28:28 +00:00
|
|
|
"phase_voltages_a",
|
|
|
|
"phase_voltages_b",
|
|
|
|
"phase_voltages_c",
|
2021-07-29 23:20:03 +00:00
|
|
|
):
|
2020-06-17 11:28:28 +00:00
|
|
|
phase_voltages = self._service_location.phase_voltages
|
|
|
|
if phase_voltages is not None:
|
|
|
|
if self._sensor == "phase_voltages_a":
|
|
|
|
self._state = phase_voltages[0]
|
|
|
|
elif self._sensor == "phase_voltages_b":
|
|
|
|
self._state = phase_voltages[1]
|
|
|
|
elif self._sensor == "phase_voltages_c":
|
|
|
|
self._state = phase_voltages[2]
|
2021-07-29 23:20:03 +00:00
|
|
|
elif self._sensor in ("line_voltages_a", "line_voltages_b", "line_voltages_c"):
|
2020-06-17 11:28:28 +00:00
|
|
|
line_voltages = self._service_location.line_voltages
|
|
|
|
if line_voltages is not None:
|
|
|
|
if self._sensor == "line_voltages_a":
|
|
|
|
self._state = line_voltages[0]
|
|
|
|
elif self._sensor == "line_voltages_b":
|
|
|
|
self._state = line_voltages[1]
|
|
|
|
elif self._sensor == "line_voltages_c":
|
|
|
|
self._state = line_voltages[2]
|
2021-07-29 23:20:03 +00:00
|
|
|
elif self._sensor in (
|
2020-06-17 11:28:28 +00:00
|
|
|
"power_today",
|
|
|
|
"power_current_hour",
|
|
|
|
"power_last_5_minutes",
|
|
|
|
"solar_today",
|
|
|
|
"solar_current_hour",
|
|
|
|
"alwayson_today",
|
2021-07-29 23:20:03 +00:00
|
|
|
):
|
2020-06-17 11:28:28 +00:00
|
|
|
trend_value = self._service_location.aggregated_values.get(self._sensor)
|
|
|
|
self._state = round(trend_value) if trend_value is not None else None
|
|
|
|
elif self._sensor == "load":
|
|
|
|
self._state = self._service_location.measurements.get(
|
|
|
|
self._sensor_id
|
|
|
|
).active_total
|
|
|
|
elif self._sensor == "sensor":
|
|
|
|
sensor_id, channel_id = self._sensor_id.split("-")
|
|
|
|
sensor = self._service_location.sensors.get(int(sensor_id))
|
|
|
|
for channel in sensor.channels:
|
|
|
|
if channel.get("channel") == int(channel_id):
|
|
|
|
self._state = channel.get("value_today")
|
2021-08-20 21:20:45 +00:00
|
|
|
elif self._sensor == "switch":
|
|
|
|
cons = self._service_location.actuators.get(
|
|
|
|
self._sensor_id
|
|
|
|
).consumption_today
|
|
|
|
if cons is not None:
|
|
|
|
self._state = round(cons / 1000.0, 2)
|