hansij66 / dsmr2mqtt

DSMR to MQTT; Smartmeter to MQTT; Slimme meter naar MQTT
GNU General Public License v3.0
9 stars 14 forks source link

Home Assistant Auto Discovery error for voltage sensors #11

Closed JoniR closed 2 weeks ago

JoniR commented 1 month ago

Description: Home Assistant's auto-discovery feature does not accept 'device_class': 'V' for voltage sensors. The correct device class for voltage should be 'voltage' as per the Home Assistant documentation. This discrepancy prevents voltage sensors from being automatically discovered.

Steps to Reproduce:

  1. Configure an MQTT sensor with the following parameters:

    {
    "unique_id": "V1",
    "state_topic": "dsmr/el",
    "unit_of_measurement": "V",
    "value_template": "{{ value_json.V1 }}",
    "device_class": "V",
    "icon": "mdi:gauge",
    "device": {
    "identifiers": ["dsmr"]
    },
    "name": "Voltage L1",
    "platform": "mqtt"
    }
  2. Publish the MQTT discovery message to the topic homeassistant/sensor/dsmr/V1/config.

  3. Observe the error in the Home Assistant logs.

Expected Behavior: The voltage sensor should be automatically discovered and added to Home Assistant without any errors.

Actual Behavior: An error is logged, and the voltage sensor is not discovered.

Error Log: Error 'expected SensorDeviceClass or one of 'date', 'enum', 'timestamp', 'apparent_power', 'aqi', 'atmospheric_pressure', 'battery', 'carbon_monoxide', 'carbon_dioxide', 'conductivity', 'current', 'data_rate', 'data_size', 'distance', 'duration', 'energy', 'energy_storage', 'frequency', 'gas', 'humidity', 'illuminance', 'irradiance', 'moisture', 'monetary', 'nitrogen_dioxide', 'nitrogen_monoxide', 'nitrous_oxide', 'ozone', 'ph', 'pm1', 'pm10', 'pm25', 'power_factor', 'power', 'precipitation', 'precipitation_intensity', 'pressure', 'reactive_power', 'signal_strength', 'sound_pressure', 'speed', 'sulphur_dioxide', 'temperature', 'volatile_organic_compounds', 'volatile_organic_compounds_parts', 'voltage', 'volume', 'volume_storage', 'volume_flow_rate', 'water', 'weight', 'wind_speed' for dictionary value @ data['device_class']' when processing MQTT discovery message topic: 'homeassistant/sensor/dsmr/V1/config', message: '{'unique_id': 'V1', 'state_topic': 'dsmr/el', 'unit_of_measurement': 'V', 'value_template': '{{ value_json.V1 }}', 'device_class': 'V', 'icon': 'mdi:gauge', 'device': {'identifiers': ['dsmr']}, 'name': 'Voltage L1', 'platform': 'mqtt'}'

hansij66 commented 1 month ago

Thanks for feedback. I will check & fix. After the summer holidays.

Ribbertje commented 2 weeks ago

In hadiscovery.py

changed elif d["unit_of_measurement"] == "V": d["device_class"] = "V" To elif d["unit_of_measurement"] == "V": d["device_class"] = "VOLTAGE" And the issue is fixed, the entities also show up in HA now

hansij66 commented 2 weeks ago

v4.0.1