MQTT Sensor:Unknown / Solar Assistant Device Mode

Good day all,

I am having an issue with 1 of my MQTT entities whereby the 1 sensor value is Unknown. I have checked the logs and the entity is publishing the correct state. All other sensors works just fine.

It is showing as unknown state, however

MQTT explorer is reporting ‘Grid’ which is the correct state/value.

Is anyone else having such an issue or knows how to correct this.

I have tried the following;

  1. Restarting,
  2. Rebooting,
  3. Restarting the Broker,
  4. Deleting the settings for this and re adding the installation files for the device,
  5. Stopped and restarted the service on the device that publishes the messages,
  6. Rebooted the device that publishes the messages.

Thanks.

None of your MQTT topics seem related to a sensor.device_mode entity

device_mode is under the screenshot included. I have double checked, the naming on others are the same and they work.

Whatever you say.
Even if the “config” topic is correct, which we cannot tell from you partial screenshost, ofc, it defines sensor.inverter_1_device_mode.

How is sensor.device_mode defined?

The inverter_1_ drops for all. Ignore the inverter_1_ from it. All other sensors work exactly the same way. The screenshots are for the same sensor although it may appear that way from my ‘partial’ screenshot.

Do you possibly have any idea why 30+ topics are working correctly and just one reports unknown?

How exactly do you think we can help you if you provide partial / wrong information?

How do you that? Obviously, that might be part of the problem…

I am terribly sorry for the mix up, I did include as much information as I could.

To answer your second question, I ‘do not’ do that, it is just the sequence I noticed. Checking my logs for another issue, I came across this now for the first time, not sure if this would assist with identifying the issue.

Logger: homeassistant.components.mqtt.models
Source: components/sensor/init.py:585
Integration: MQTT (documentation, issues)
First occurred: 8:12:06 AM (26197 occurrences)
Last logged: 11:46:32 PM

Exception raised when updating state of sensor.device_mode, topic: ‘solar_assistant2/inverter_1/device_mode/state’ with payload: b’Grid’
Exception raised when updating state of sensor.device_mode, topic: ‘solar_assistant2/inverter_1/device_mode/state’ with payload: b’Solar/Battery’
Traceback (most recent call last):
File “/usr/src/homeassistant/homeassistant/components/sensor/init.py”, line 581, in state
numerical_value = int(value)
^^^^^^^^^^
ValueError: invalid literal for int() with base 10: ‘Grid’

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File “/usr/src/homeassistant/homeassistant/components/mqtt/models.py”, line 270, in process_write_state_requests
entity.async_write_ha_state()
File “/usr/src/homeassistant/homeassistant/helpers/entity.py”, line 590, in async_write_ha_state
self._async_write_ha_state()
File “/usr/src/homeassistant/homeassistant/helpers/entity.py”, line 654, in _async_write_ha_state
state = self._stringify_state(available)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/usr/src/homeassistant/homeassistant/helpers/entity.py”, line 596, in _stringify_state
if (state := self.state) is None:
^^^^^^^^^^
File “/usr/src/homeassistant/homeassistant/components/sensor/init.py”, line 585, in state
raise ValueError(
ValueError: Sensor sensor.device_mode has device class ‘None’, state class ‘None’ unit ‘keyed’ and suggested precision ‘None’ thus indicating it has a numeric value; however, it has the non-numeric value: ‘Grid’ (<class ‘str’>)

I have read it, but I do not understand it.

  1. The error message relates to the fact that the MQTT config for sensor.inverter_1_device_mode specifies a unit_of_measurement (“keyed”) while its value is a string (“Grid”). That is not valid anymore, unit_of_measurement should be removed from the MQTT config topic.
  2. There is no automagical way sensor.inverter_1_device_mode would be transformed into sensor.device_mode, but whatever does it, the reson it is “unknown” is likely due to the error above.

What is pushing the MQTT config? You might point to them that what they send is wrong for the latest version of HA.

1 Like

Having a somewhat similar issue to this also.
Have to restar Solar Assistant and Home Assistant for it to work again.