home-assistant.io/source/developers/platform_example_sensor.markdown
clach04 14edd83418 Make name of example clearly an example (#654)
So that when this shows up in the dashboard it is a sample and not a real device.
2016-07-19 21:43:21 +02:00

1023 B

layout, title, description, date, sidebar, comments, sharing, footer
layout title description date sidebar comments sharing footer
page Example sensor platform Minimum implementation of a Home Assistant platform. 2016-04-16 14:24 -07:00 true false true true

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

{% linkable_title Installation %}

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
sensor:
  platform: example

{% linkable_title Code %}

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


def setup_platform(hass, config, add_devices, discovery_info=None):
    add_devices([ExampleSensor()])


class ExampleSensor(Entity):
    @property
    def name(self):
        return 'Example Temperature'

    @property
    def state(self):
        return 23

    @property
    def unit_of_measurement(self):
        return TEMP_CELSIUS