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
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 "?
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.
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.
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_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!