Bonjour!
Je commence à jouer un peu avec mon instance Home-assistant et j’ai voulu ajouter quelques sensors provenant de mon UPS de marque Next.
J’aimerai pouvoir obtenir le voltage entrant afin de pouvoir mesurer les variations dans le temps.
En lisant la doc, je me rend compte qu’il est possible d’obtenir cette valeur via SNMP.
J’ai pu déterminer l’OID ciblé via un MIB Browser et finalement j’abouti à cette configuration dans mon fichier configuration.yaml.
# UPS
sensor:
- platform: snmp
name: "UPS Input Voltage"
device_class: voltage
unit_of_measurement: V
host: 192.168.1.17
baseoid: .1.3.6.1.4.1.935.10.1.1.2.16.1.3
community: public
state_class: measurement
version: "2c"
Seulement voilà, lorsque je redémarre mon instance, mon sensor n’apparait pas et voici ce que je trouve dans les logs:
2024-06-21 22:18:48.834 ERROR (MainThread) [homeassistant.components.sensor] Error adding entity sensor.ups_input_voltage for domain sensor with platform snmp
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 658, 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 661, 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/helpers/entity_platform.py", line 600, in _async_add_entities
await coro
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 914, in _async_add_entity
await entity.add_to_platform_finish()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1354, in add_to_platform_finish
await self.async_added_to_hass()
File "/usr/src/homeassistant/homeassistant/components/snmp/sensor.py", line 202, in async_added_to_hass
await self.async_update()
File "/usr/src/homeassistant/homeassistant/components/snmp/sensor.py", line 218, in async_update
self._process_manual_data(raw_value)
File "/usr/src/homeassistant/homeassistant/helpers/trigger_template_entity.py", line 239, in _process_manual_data
self.async_write_ha_state()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1000, in async_write_ha_state
self._async_write_ha_state()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1126, in _async_write_ha_state
state, attr, capabilities, shadowed_attr = self.__async_calculate_state()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1061, in __async_calculate_state
state = self._stringify_state(available)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1006, in _stringify_state
if (state := self.state) is None:
^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 665, in state
raise ValueError(
ValueError: Sensor sensor.ups_input_voltage has device class 'voltage', state class 'measurement' unit 'V' and suggested precision 'None' thus indicating it has a numeric value; however, it has the non-numeric value: '' (<class 'str'>)
Seulement, je ne vois vraiment pas ce qui coince… car si j’exécute la commande
snmpwalk -v 2c -c public 192.168.1.17 .1.3.6.1.4.1.935.10.1.1.2.16.1.3
J’obtiens pourtant bien un bon résultat…
Alors voilà, j’imagine que je fais une bête erreur mais étant novice, je ne comprend pas pourquoi HA obtient apparemment une valeur correspondant à une string vide…
Merci d’avance pour votre aide!