Cannot get command_line sensor with ipmitool to function

Hi all,

I’m trying to use ipmitool to query the sensor data of my Supermicro server. The command itself works when typed into the CLI of the Home Assistant server, but does not function as a sensor. The command:

[core-ssh ~]$ ipmitool -H host01-oob -U hass -P redacted sensor | awk -F' *[|] *' '$1=="CPU Temp"{print $2}' | cut -d. -f1

As you can see, it returns the temperature in degrees Celsius without a problem. I’ve copied this command into a sensor block as follows:

  - sensor:
      name: host01 CPU Temperature
      unique_id: host01_cpu_temp
      command: ipmitool -H host01-oob -U hass -P redacted sensor | awk -F' *[|] *' '$1=="CPU Temp"{print $2}' | cut -d. -f1
      device_class: temperature
      unit_of_measurement: "°C"

There are no issues with the syntax (at least not that the linter complains about), but the following error is generated in the logs and the sensor is unavailable.

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/sensor/", line 581, in state
    numerical_value = int(value)
ValueError: invalid literal for int() with base 10: ''

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

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/", line 471, in async_add_entities
    await asyncio.gather(*tasks)
  File "/usr/src/homeassistant/homeassistant/helpers/", line 749, in _async_add_entity
    await entity.add_to_platform_finish()
  File "/usr/src/homeassistant/homeassistant/helpers/", line 849, in add_to_platform_finish
    await self.async_added_to_hass()
  File "/usr/src/homeassistant/homeassistant/components/command_line/", line 140, in async_added_to_hass
    await self._update_entity_state(None)
  File "/usr/src/homeassistant/homeassistant/components/command_line/", line 164, in _update_entity_state
    await self._async_update()
  File "/usr/src/homeassistant/homeassistant/components/command_line/", line 202, in _async_update
  File "/usr/src/homeassistant/homeassistant/helpers/", line 590, in async_write_ha_state
  File "/usr/src/homeassistant/homeassistant/helpers/", line 654, in _async_write_ha_state
    state = self._stringify_state(available)
  File "/usr/src/homeassistant/homeassistant/helpers/", line 596, in _stringify_state
    if (state := self.state) is None:
  File "/usr/src/homeassistant/homeassistant/components/sensor/", line 585, in state
    raise ValueError(
ValueError: Sensor sensor.host01_cpu_temperature has device class 'None', state class 'None' unit '°C' and suggested precision 'None' thus indicating it has a numeric value; however, it has the non-numeric value: '' (<class 'str'>)

Any ideas? I’ve searched around for any similar issues have come up dry. Thanks in advance!

I’ve simplified the command, only querying the specific sensor value, in an attempt to reduce the string wrangling and number of quotes. The same error still shows in the log, however.

  - sensor:
      name: host01 CPU Temperature
      unique_id: host01_cpu_temp
      command: "ipmitool -H host01-oob -U hass -P redacted sensor reading 'CPU Temp' | awk '{print $NF}'"
      device_class: temperature
      unit_of_measurement: "°C"

I think this is because I’ve installed ipmitool via SSH but because I’m using Home Assistant OS, SSH access is via the Terminal & SSH add-on which runs in an isolated Docker container. When the command is run through Home Assistant core, ipmitool isn’t available.

Is there a way to install it?

Created an automation to install ipmitool in the homeassistant container on start. All good now!

alias: Install Dependencies on Start
description: ""
  - platform: homeassistant
    event: start
condition: []
  - service: shell_command.install_dependencies
    data: {}
mode: single
  install_dependencies: apk add ipmitool
1 Like