core
core copied to clipboard
Command line sensor not observing availability template
The problem
I have a command line sensor that occasionally fails. So I added an availability template to account for this:
command_line:
- sensor:
name: UV Index
unique_id: c2d041f0-05b6-46e2-af8b-685c7fd0a580
command: "curl -k --silent 'https://uvdata.arpansa.gov.au/xml/'|sed -n '77p'|cut -c 12-14"
availability: "{{ value|is_number}}"
unit_of_measurement: " "
state_class: measurement
However when the sensor fails I still get the following error:
Logger: homeassistant
Source: components/sensor/__init__.py:664
First occurred: 03:05:16 (4 occurrences)
Last logged: 03:31:46
Error doing job: Task exception was never retrieved (None)
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 657, in state
numerical_value = int(value)
^^^^^^^^^^
ValueError: invalid literal for int() with base 10: ''
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 660, in state
numerical_value = float(value)
^^^^^^^^^^^^
ValueError: could not convert string to float: ''
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/components/command_line/sensor.py", line 142, in _update_entity_state
await self._async_update()
File "/usr/src/homeassistant/homeassistant/components/command_line/sensor.py", line 190, in _async_update
self._process_manual_data(value)
File "/usr/src/homeassistant/homeassistant/helpers/trigger_template_entity.py", line 234, in _process_manual_data
self.async_write_ha_state()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1005, in async_write_ha_state
self._async_write_ha_state()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1130, in _async_write_ha_state
self.__async_calculate_state()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1067, in __async_calculate_state
state = self._stringify_state(available)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1011, in _stringify_state
if (state := self.state) is None:
^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 664, in state
raise ValueError(
ValueError: Sensor sensor.uv_index has device class 'None', state class 'measurement' unit ' ' and suggested precision 'None' thus indicating it has a numeric value; however, it has the non-numeric value: '' (<class 'str'>)
The availability template should be checked before generating this error.
What version of Home Assistant Core has the issue?
core-2024.10.1
What was the last working version of Home Assistant Core?
No response
What type of installation are you running?
Home Assistant OS
Integration causing the issue
https://www.home-assistant.io/integrations/command_line/
Link to integration documentation on our website
No response
Diagnostics information
No response
Example YAML snippet
No response
Anything in the logs that might be useful for us?
No response
Additional information
No response