NumberEntity not editable over UI

I’m developing custom integration that creates entity inheriting from NumberEntity, to my surprise it is not editable over the UI:

I’m wondering what i’m doing wrong?

class FoxESSEnergyBatMinSoC(CoordinatorEntity, NumberEntity):

    _attr_device_class = DEVICE_CLASS_BATTERY
    _attr_unit_of_measurement = "%"
    _attr_value = 4

    def __init__(self, coordinator, name, deviceID):
        super().__init__(coordinator=coordinator)
        _LOGGER.debug("Initing Entity - Bat Min SoC")
        self._attr_name = name+" - Bat Min SoC"
        self._attr_name = name+" - Bat Min SoC"
        self._attr_unique_id = deviceID+"-bat_min_SoC"

    def set_value(self, value: float) -> None:
        """Update the current value."""


    async def async_set_value(self, value):
        """Update the current value."""
        self._attr_value = value
        self.async_write_ha_state()

Documentation does not cover that topic :confused: Is there any other source of knowledge different thathttps://developers.home-assistant.io/docs/core/entity/number/ ?

Hi - I have the same problem, did you manage to solve it?

Oh - I’ve only just noticed that coincidentally we’ve had the same problem within 10 hours of each other!

Get rid of this line as you are implementing the async version.

@gjohansson thx for tip!, removed but it is still not editable ;/

@Gadgit83 no i was not able :confused: Did you ?

Would seem you are missing the value property.
Look here as example: core/number.py at 2c1d2c323db72d623b58ccbddb54f525f5c627ba · home-assistant/core · GitHub

Unfortunately it did not help.

What interesting this entity is reported as a sensor not number :confused: Screenshot 2022-05-04 at 15.05.38

So you put it in sensor.py instead of number.py?

1 Like

Tried both adding only the async version of set_value, plus have the value property, and have defined it within a number.py, but still same behaviour - no editable value.

image

You have some required attributes which is missing: core/homeassistant/components/number at eebf3acb93507f8f706f8043d57fdfd09942a750 · home-assistant/core · GitHubinit.py#L102-L108
Min, Max, Step

@gjohansson indeed , moving it to proper file fixed my problem. thank you 🙇‍♂️

Have now added those attributes, and they are being pulled through by the front end, however, still no adjustable input. @macxq would you perhaps mind sharing your complete number.py, so I can try and make sure I’m doing the correct things?

@macxq also coincidentally - it appears you’re trying to achieve the same thing as me with Solar inverter control?

image
image

Ah - sorted it - the issue was that I was not calling async_setup_platforms() with “sensor” and “number” separately, but instead I was importing ‘number’ into the ‘sensor.py’ setup script.

Wrong code:

PLATFORMS: list[str] = ["sensor"]

async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
    """Set up Solarman Collector from a config entry."""
    _LOGGER.debug(f'__init__.py:async_setup_entry({entry.as_dict()})')
    hass.config_entries.async_setup_platforms(entry, PLATFORMS)
    entry.async_on_unload(entry.add_update_listener(update_listener))
    return True

Fixed code:

PLATFORMS: list[str] = ["sensor","number"]

async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
    """Set up Solarman Collector from a config entry."""
    _LOGGER.debug(f'__init__.py:async_setup_entry({entry.as_dict()})')
    hass.config_entries.async_setup_platforms(entry, PLATFORMS)
    entry.async_on_unload(entry.add_update_listener(update_listener))
    return True

Thanks for all your help!

Yes, I’m developing FoxESS - solar inerter integration :slight_smile: GitHub - macxq/foxess-ha: Home Assistant & FoxESS integration. Monitor you photovoltaic installation directly from HA ☀️ ⚡️