How to solve warnings "it has the non-numeric value: unknown"

I have a number of MQTT sensors that are unavailable during startup.
I use templates that provides a default value before using the sensors in a filter, but I still get these kind of warnings during start-up.

Sensor sensor.average_solar has device class power, state class measurement and unit W thus indicating it has a numeric value; however, it has the non-numeric value: unknown (<class 'str'>); Please update your configuration if your entity is manually configured, otherwise create a bug report

However I don’t see why this is, as I’m defining a default value for the sensor:

    - name: Solar_power
      state_topic: "modbus/sdm1-2/Power"
      value_template: "{{ value | int(0) }}"
      unit_of_measurement: "W"
      device_class: power
      icon: mdi:solar-power
      unique_id: Solar_power

Before using this in a filter:

- platform: filter
  name: "average solar"
  entity_id: sensor.solar_power
  filters:
    - filter: range
      lower_bound: 0
    - filter: time_simple_moving_average
      window_size: "00:03"
      precision: 0

So why is my template not working properly, providing 0 during startup, so the filter doesn’t throw the warning about receiving the string "unknown "?

Your solar power sensor will still be unknown until the modbus sensor is polled or restored after a restart.

I suspect you will need to open a new issue for the sensor filter integration here:

You could try an automation to repost the incoming MQTT message as a new topic with the retain flag set, and then have your “Solar_power” sensor use the new topic. If the MQTT integration starts before the filter during startup, it would then use the retained value, hopefully avoiding the error.

1 Like

Ah. I saw “modbus” and missed that this was mqtt. You’re right, a retained message should help. However it would be best to fix the filter sensor.

Thanks for the tips!

Ah of course, I didn’t think of the fact that if the mqtt-sensor wasn’t triggered yet, the template with the default value also wouldn’t be evaluated yet.

I was able to change the publishing of the mqtt messages with the retain flag (and checked: indeed they are now always available now on Mosquito even if no new reading are published yet).

Unfortunately this didn’t solve the warning.

It seems that the MQTT-sensors are loaded (much) later than the sensor filter integration, so it seems there is no way around this except opening this as an issue for the filter integration.

I can’t however imagine that I’m the only one having mqtt-sensors and the filter integration, thought I have not found other people mentioning these warnings.

I’m as well having the same type of warnings in my case with MQTT-based sensors from telegraf measurements. I had a telegraf message updating the tx and rx data rate of podman containers and when starting Home assistant I always get the following warning:

ValueError: Sensor sensor.calixto_docker_zwave_net_rx has device class data_rate, state class measurement unit kB/s and suggested precision None thus indicating it has a numeric value; however, it has the non-numeric value: unknown (<class ‘str’>)
2023-06-05 10:28:39.373 ERROR (MainThread) [homeassistant.components.mqtt.models] Exception raised when updating state of sensor.calixto_docker_zwave_net_tx, topic: ‘telegraf/Calixto/docker_container_net’ with payload: b’{“fields”:{“container_id”:“1e1ed9d0ea6f7258585e56f79899828d4332727eaa6fa98fc844e69453a91e84”,“rx_bytes”:27837036,“rx_dropped”:0,“rx_errors”:0,“rx_packets”:0,“tx_bytes”:72038708,“tx_dropped”:0,“tx_errors”:0,“tx_packets”:0},“name”:“docker_container_net”,“tags”:{“PODMAN_SYSTEMD_UNIT”:“container-zwavejs.service”,“container_image”:“docker.io/zwavejs/zwave-js-ui",“container_name”:“zwavejs”,“container_status”:“running”,“container_version”:“latest”,“engine_host”:“calixto”,“host”:“Calixto”,“io.containers.autoupdate”:“registry”,“maintainer”:“robertsLando”,“network”:“network”,“org.opencontainers.image.authors”:"Daniel Lando \[email protected]\u003e”,“org.opencontainers.image.created”:“2023-06-01T14:33:17.146Z”,“org.opencontainers.image.description”:“Full featured Z-Wave Control Panel UI and MQTT gateway. Built using Nodejs, and Vue/Vuetify”,“org.opencontainers.image.documentation”:“https://zwave-js.github.io/zwave-js-ui",“org.opencontainers.image.licenses”:“MIT”,“org.opencontainers.image.revision”:“c32f69751f7215a0908a99ae7c495e6b62cf56c5”,“org.opencontainers.image.source”:“https://github.com/zwave-js/zwave-js-ui”,“org.opencontainers.image.title”:“zwave-js-ui”,“org.opencontainers.image.url”:“https://github.com/zwave-js/zwave-js-ui”,“org.opencontainers.image.vendor”:“zwave-js”,“org.opencontainers.image.version”:“8.18.0”,“server_version”:“4.5.1”},"timestamp”:1685953711}\n’
Traceback (most recent call last):
File “/usr/src/homeassistant/homeassistant/components/sensor/init.py”, line 579, in state
numerical_value = int(value)
ValueError: invalid literal for int() with base 10: ‘unknown’

ValueError: Sensor sensor.calixto_docker_zwave_net_tx has device class data_rate, state class measurement unit kB/s and suggested precision None thus indicating it has a numeric value; however, it has the non-numeric value: unknown (<class ‘str’>)

I have enabled the persistance flag both in Mosquitto and telegraf but the message when starting HA is still there. Any hints? Thanks!