Skip to content

Commit

Permalink
feat(sensor): removed current consumption sensors due to insufficient…
Browse files Browse the repository at this point in the history
… data provided by Octopus Energy

BREAKING CHANGE:
Latest consumption sensors are no longer available, which may cause issues anywhere they are used.
  • Loading branch information
BottlecapDave committed Dec 4, 2021
1 parent 8daa588 commit 0470ff3
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 150 deletions.
6 changes: 3 additions & 3 deletions README.md
Expand Up @@ -23,16 +23,16 @@ You'll get the following sensors if you have an electricity meter with an active

You'll get the following sensors for each electricity meter with an active agreement:

* `sensor.octopus_energy_electricity_{{METER_SERIAL_NUMBER}}_latest_consumption` - The latest consumption reported by the meter. It looks like Octopus is about a day behind with their data, therefore this is often zero and will probably be removed in the future.
* `sensor.octopus_energy_electricity_{{METER_SERIAL_NUMBER}}_previous_accumulative_consumption` - The total consumption reported by the meter for the previous day.

You'll get the following sensors for each gas meter with an active agreement:

* `sensor.octopus_energy_gas_{{METER_SERIAL_NUMBER}}_latest_consumption` - The latest consumption reported by the meter. It looks like Octopus is about a day behind with their data, therefore this is often zero and will probably be removed in the future.
* `sensor.octopus_energy_gas_{{METER_SERIAL_NUMBER}}_previous_accumulative_consumption` - The total consumption reported by the meter for the previous day.

While you can add these sensors to [energy dashboard](https://www.home-assistant.io/blog/2021/08/04/home-energy-management/), because Octopus doesn't provide live consumption data, it will be off by a day.

Please note, that it's not possible to include current consumption sensors. This is due to Octopus Energy only providing data up to the previous day.

### Target Rates

If you go through the [setup](https://my.home-assistant.io/redirect/config_flow_start/?domain=octopus_energy) process after you've configured your account, you can set up target rate sensors. These sensors calculate the lowest continuous or intermittent prices and turn on when these periods are active. These sensors can then be used in automations to turn on/off devices that save you (and the planet) energy and money.
Expand All @@ -45,6 +45,6 @@ When you sign into your account, if you have gas meters, we'll setup some sensor

## Known Issues/Limitations

- Latest consumption is at the mercy of how often Octopus Energy updates their records. This seems to be a day behind based on local testing.
- Octopus Energy only provide data up to the previous day, so it's not possible to expose current consumption. If you would like this to change, then you'll need to email Octopus Energy.
- Only the first property associated with an account is exposed.
- Gas meter SMETS1/SMETS2 setting has to be set globally and manually as Octopus Energy doesn't provide this information.
147 changes: 0 additions & 147 deletions custom_components/octopus_energy/sensor.py
Expand Up @@ -207,77 +207,6 @@ def state(self):

return self._state

class OctopusEnergyLatestElectricityReading(SensorEntity):
"""Sensor for displaying the current electricity rate."""

def __init__(self, client, mpan, serial_number):
"""Init sensor."""
self._mpan = mpan
self._serial_number = serial_number
self._client = client

self._attributes = {
"MPAN": mpan,
"Serial Number": serial_number
}

self._state = None

@property
def unique_id(self):
"""The id of the sensor."""
return f"octopus_energy_electricity_{self._serial_number}_latest_consumption"

@property
def name(self):
"""Name of the sensor."""
return f"Octopus Energy Electricity {self._serial_number} Latest Consumption"

@property
def device_class(self):
"""The type of sensor"""
return DEVICE_CLASS_ENERGY

@property
def state_class(self):
"""The state class of sensor"""
return STATE_CLASS_TOTAL_INCREASING

@property
def unit_of_measurement(self):
"""The unit of measurement of sensor"""
return ENERGY_KILO_WATT_HOUR

@property
def icon(self):
"""Icon of the sensor."""
return "mdi:lightning-bolt"

@property
def extra_state_attributes(self):
"""Attributes of the sensor."""
return self._attributes

@property
def state(self):
"""Native value of the sensor."""
return self._state

async def async_update(self):
"""Retrieve the latest consumption"""
# We only need to do this every half an hour
current_datetime = now()
if (current_datetime.minute % 30) == 0 or self._state == None:
_LOGGER.info('Updating OctopusEnergyLatestElectricityReading')

period_from = as_utc(current_datetime - timedelta(hours=1))
period_to = as_utc(current_datetime)
data = await self._client.async_electricity_consumption(self._mpan, self._serial_number, period_from, period_to)
if data != None and len(data) > 0:
self._state = data[0]["consumption"]
else:
self._state = 0

class OctopusEnergyPreviousAccumulativeElectricityReading(SensorEntity):
"""Sensor for displaying the previous days accumulative electricity reading."""

Expand Down Expand Up @@ -358,82 +287,6 @@ async def async_update(self):
self._state = 0
self._data = []

class OctopusEnergyLatestGasReading(SensorEntity):
"""Sensor for displaying the current gas rate."""

def __init__(self, client, mprn, serial_number, is_smets1_meter):
"""Init sensor."""
self._mprn = mprn
self._serial_number = serial_number
self._is_smets1_meter = is_smets1_meter
self._client = client

self._attributes = {
"MPRN": mprn,
"Serial Number": serial_number,
"Is SMETS1 Meter": is_smets1_meter
}

self._state = None

@property
def unique_id(self):
"""The id of the sensor."""
return f"octopus_energy_gas_{self._serial_number}_latest_consumption"

@property
def name(self):
"""Name of the sensor."""
return f"Octopus Energy Gas {self._serial_number} Latest Consumption"

@property
def device_class(self):
"""The type of sensor"""
return DEVICE_CLASS_GAS

@property
def state_class(self):
"""The state class of sensor"""
return STATE_CLASS_TOTAL_INCREASING

@property
def unit_of_measurement(self):
"""The unit of measurement of sensor"""
return VOLUME_CUBIC_METERS

@property
def icon(self):
"""Icon of the sensor."""
return "mdi:fire"

@property
def extra_state_attributes(self):
"""Attributes of the sensor."""
return self._attributes

@property
def state(self):
"""Native value of the sensor."""
return self._state

async def async_update(self):
"""Retrieve the latest consumption"""
# We only need to do this every half an hour
current_datetime = now()
if (current_datetime.minute % 30) == 0 or self._state == None:
_LOGGER.info('Updating OctopusEnergyLatestGasReading')

period_from = as_utc(current_datetime - timedelta(hours=1))
period_to = as_utc(current_datetime)
data = await self._client.async_gas_consumption(self._mprn, self._serial_number, period_from, period_to)
if data != None and len(data) > 0:
self._state = data[0]["consumption"]
else:
self._state = 0

if self._is_smets1_meter:
self._state = convert_kwh_to_m3(self._state)

class OctopusEnergyPreviousAccumulativeGasReading(SensorEntity):
"""Sensor for displaying the previous days accumulative gas reading."""

Expand Down

0 comments on commit 0470ff3

Please sign in to comment.