Entity does not show "on" "off" toggle button in UI

I am building a new irrigiation component but the entities i createde do not show up as toggle able buttons in the ui.
Anyone knows what i am doing wrong?

class IrrigationZone(Entity):
    """Representation of an Irrigation zone."""

    def __init__(self, irrigation_id, attributes):
        """Initialize a Irrigation program."""
        self.entity_id = irrigation_id
        self._name = attributes.get(ATTR_NAME)
        self._switch = attributes.get(ATTR_SWITCH)
        self._duration = int(attributes.get(ATTR_DURATION))
        self._state = STATE_OFF
        self._icon_on = attributes.get(ATTR_ICON,
                                       DFLT_ICON_WATER)
        self._icon_off = attributes.get(ATTR_ICON_OFF,
                                        DFLT_ICON_WATER_OFF)
        self._state = STATE_OFF
        self._stop = False
        self._template = attributes.get(ATTR_TEMPLATE)
        self._runtime_remaining = 0

    async def async_added_to_hass(self):
        await super().async_added_to_hass()

        """ house keeping to help ensure solenoids are in a safe state """
        self.hass.bus.async_listen_once(
            EVENT_HOMEASSISTANT_START, self.async_stop_switch())
        return True

    @property
    def should_poll(self):
        """If entity should be polled."""
        return False

    @property
    def name(self):
        """Return the name of the variable."""
        if self._state == STATE_ON:
            x = '{} remaining {} (m).'.format(
                self._name, self._runtime_remaining
            )
        else:
            x = '{} def. duration {} (m).'.format(
                self._name, self._duration)
        return x

    @property
    def icon(self):
        """Return the icon to be used for this entity."""
        if self._state == STATE_ON:
            return self._icon_on
        else:
            return self._icon_off

    @property
    def is_on(self):
        """If the switch is currently on or off."""
        return self._state == STATE_ON

    def turn_on(self, **kwargs):
        """Turn the device on."""
        DATA = {CONST_ENTITY: self.entity_id}
        #await self.hass.services.async_call(DOMAIN,
        #                                'run_zone',
        #                                DATA)

    def turn_off(self, **kwargs):
        """Turn the device off."""
        DATA = {CONST_ENTITY: self.entity_id}
        
    @property
    def state(self):
        """Return the state of the component."""
        return self._state

    @asyncio.coroutine
    async def async_update(self):
        """Update the state from the template."""
        _LOGGER.info('async_update - %s', self.entity_id)

    @asyncio.coroutine
    async def async_stop_zone(self):
        _LOGGER.warn('async_stop_zone - %s', self.entity_id)
        self._stop = True
        DATA = {ATTR_ENTITY_ID: self._switch}
        await self.hass.services.async_call(CONST_SWITCH,
                                            SERVICE_TURN_OFF,
                                            DATA)
        self._state = STATE_OFF
        self.async_schedule_update_ha_state()

    @asyncio.coroutine
    async def async_stop_switch(self):
        _LOGGER.warn('async_stop_switch - %s', self._switch)
        DATA = {ATTR_ENTITY_ID: self._switch}
        await self.hass.services.async_call(CONST_SWITCH,
                                            SERVICE_TURN_OFF,
                                            DATA)
        self._state = STATE_OFF

    @asyncio.coroutine
    async def async_run_zone(self, DATA):
        _LOGGER.info('async_run_zone - %s', self._name)

You likely need to inherit from ToggleEntity as opposed to Entity. Defined in home-assistant/homeassistant/helpers/entity.py in GitHub.

1 Like

Thank you, i totally oversaw this.