home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
72.39k stars 30.29k forks source link

MQTT discovery not update the name of sensor #128136

Open kzajac83 opened 3 hours ago

kzajac83 commented 3 hours ago

The problem

Hello

The problem is arrived discovery msg not change definition of the sensor.

BR, Krzysiek

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 Core

Integration causing the issue

MQTT

Link to integration documentation on our website

https://www.home-assistant.io/integrations/mqtt/#mqtt-discovery

Diagnostics information

I created discovery message according instruction from https://www.home-assistant.io/integrations/mqtt/#mqtt-discovery .

On begging it was working, this mean I was developing new structure of discovery msg hence send few times the discovery message with changed especially namefields (for main and device section). Finally I send this:

/usr/bin/mosquitto_pub -h 192.168.15.20 -t "homeassistant/sensor/HeatMeter/CO_4/config" -m '{"name": "total_energy_consumption_kwh", "device_class": "energy", "state_topic": "homeassistant/sensor/HeatMeter/CO_4/state", "unique_id": "67782120", "device": {"identifiers": ["67782120"], "name": "CO_4 HeatMeter kamheat" }}' -u mqtt_user -P mqtt_user

I see in MQTT in diagnostic download data mqtt-45740f6e9a7f411fcfbdaa52b411321a-CO_4 HeatMeter kamheat-2fa42595b11624f76906037b360f69f8.json and in HA that discovery msg has been delivered correct:

image

However the sensor of MQTT still show old (one of earlier attempt of discovery msg) and now cannot change it. I can change name of device but name of sensor is constant (now I sending total_energy_consumption_kwh)

image

image

Also the subscription payload also arrive (you can see it in attached earlier json diagnostic data) but not assign data to the sensor

Example YAML snippet

MQTT section from configuration yaml. In theory should not have impact because section device is not correct and display wrong for 2nd energy sensor. 

mqtt:
    sensor:
    - name: "total_m3"
      state_topic: "licznik_glowny/water"
      unit_of_measurement: "m³"
      device_class: "water"
      state_class: "total"
      value_template: "{{ value_json.total_m3 }}"
      #value_template: "{{ as_datetime(value) }}"
      unique_id: "unique_id_wodomierz"
      device:
        name: "Adapr NA 1"
        identifiers:
          - "04913581"
    - name: "total_energy_gj"
      state_topic: "wmbusmeters/CO_4"
      unit_of_measurement: "GJ"
      device_class: "energy"
      state_class: "total"
      value_template: "{{ value_json.total_energy_gj | round(3) }}"
      unique_id: "{{ value_json.fabrication_no }}"
      device:
        name: "{{ value_json.meter }}"
        identifiers: "{{ value_json.fabrication_no }}"      
        #hw_version: "{{ value_json.meter }}"
        manufacturer: "{{ value_json.meter }}"

Anything in the logs that might be useful for us?

No response

Additional information

No response

home-assistant[bot] commented 3 hours ago

Hey there @emontnemery, @jbouwh, @bdraco, mind taking a look at this issue as it has been labeled with an integration (mqtt) you are listed as a code owner for? Thanks!

Code owner commands Code owners of `mqtt` can trigger bot actions by commenting: - `@home-assistant close` Closes the issue. - `@home-assistant rename Awesome new title` Renames the issue. - `@home-assistant reopen` Reopen the issue. - `@home-assistant unassign mqtt` Removes the current integration label and assignees on the issue, add the integration domain after the command. - `@home-assistant add-label needs-more-information` Add a label (needs-more-information, problem in dependency, problem in custom component) to the issue. - `@home-assistant remove-label needs-more-information` Remove a label (needs-more-information, problem in dependency, problem in custom component) on the issue.

(message by CodeOwnersMention)


mqtt documentation mqtt source (message by IssueLinks)

jbouwh commented 3 hours ago

The sensor it self is updated, only not in this view. I think this is an issue with the frontend and not MQTT specific. If you click on the sensor after updating it, it will show the correct and updated name.

jbouwh commented 3 hours ago

After Home Assistant is restarted the correct name will be shown in the UI.

jbouwh commented 3 hours ago

I linked to https://github.com/home-assistant/frontend/issues/22210. It seems there is an issue in the frontend.

kzajac83 commented 2 hours ago

@jbouwh maybe somehow connected to mentioned issue but for sure I change web browser language to US and no impact.

Also earlier it was not need restart HA but for check made full restart and unfortenetly almost no change. Well there is a change that now inform me about missing entity but probably due to missing "-r" / retention flag used. This is correct thinking? So msg arrives (picture below) but due to missing the "-r" HA ignore it (sorry don't know how to make smaller pictures), yes?

image

image

image

After resend the same discovery as earlier now the name of sensor is correct

image

but no data however seems configuration is correct:

image

PS. I have to define each item (and I have 25 of them) with a payload in order for all 25 to be displayed on this device or can they appear dynamically based on incoming subscrible messages?

jbouwh commented 10 minutes ago

I guess that when you add the entities to a dashboard, you will see them update correctly. The reason language or name is not updated seems frontend related, that is why I linked the issue.

jbouwh commented 6 minutes ago

For now, yes, yo need to define a discovery payload for each item. We are working on a device based discovery, but this functionality is not available yet. If you have one json with all the data inside you can subscribe to the same topic for all entities and use a value template to substract the correct value.

https://www.home-assistant.io/docs/configuration/templating/#using-templates-with-the-mqtt-integration