Example Sensor Platform

This is a minimum implementation of a platform for the sensor component.


Copy the code below and create it as a file in <config_dir>/custom_components/sensor/example.py.

Add the following to your configuration.yaml:

# Example configuration.yaml entry
  platform: example


from homeassistant.const import TEMP_CELSIUS
from homeassistant.helpers.entity import Entity

def setup_platform(hass, config, add_devices, discovery_info=None):
    """Setup the sensor platform."""

class ExampleSensor(Entity):
    """Representation of a Sensor."""

    def name(self):
        """Return the name of the sensor."""
        return 'Example Temperature'

    def state(self):
        """Return the state of the sensor."""
        return 23

    def unit_of_measurement(self):
        """Return the unit of measurement."""
        return TEMP_CELSIUS