Open kzajac83 opened 1 day 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!
(message by CodeOwnersMention)
mqtt documentation mqtt source (message by IssueLinks)
Note that I am not seeing any configuration details and logs, which makes it hard to tell what is happenig in detail. Overall applies that when retaining a MQTT config message this will trigger loading the config during startup. In other cases the integration must wait for the MQTT birth message or have a repeated config message. If you enable an entitiy that was discovered in a disabled state, then that is not related to the config message being retained or not.
Also: when you do not use a retained flag for your config message, you should resend it after Home Assistant is restarted ( so after the Birth message, or repeated), or Home Assistant will have no clue about the entitiy and its state, and it will only hold some registry entities with customizations if the discovery payload has a unique_id
and a device part.
Sorry for missing details. Yes, I use unique_id
in MQTT discovery msg and resend the msg no impact for history of entices.
CASE 1
General I have more than 15 devices created by MQTT device w/o retain flag, for example device named "CWU_10" with many sensors is created by below commands:
/usr/bin/mosquitto_pub -h 192.168.15.20 -t "homeassistant/sensor/CWU_10/historical_total_m3/config" -m '{"name" : "historical_total_m3", "state_topic" : "wmbusmeters/00345343", "unique_id" : "historical_total_m3_00345343_aptmbusna.xmq", "expire_after" : "370", "value_template" : "{{ value_json.historical_total_m3 }}", "unit_of_measurement" : "m³", "state_class" : "TOTAL_INCREASING", "device_class" : "VOLUME", "json_attributes_topic" : "wmbusmeters/00345343", "json_attributes_template" : "{{ { \"Description\" : \"Historical total volume\" } | tojson }}", "device": {"serial_number" : "00345343", "hw_version" : "n/a" ,"manufacturer" : "Apator", "identifiers" : "00345343", "name" : "CWU_10", "model" : " (aptmbusna.xmq)" }, "origin" : {"name" : "wmbusmeters", "support_url" : "https://github.com/wmbusmeters/wmbusmeters/","sw_version" : "wmbusmeters: 1.17.1-29-g3af7a4c 3af7a4c8a881c10498f1e14d950d4e502ab2fa7e"}}' -u mqtt_user -P mqtt_user
/usr/bin/mosquitto_pub -h 192.168.15.20 -t "homeassistant/sensor/CWU_10/operating_battery_h/config" -m '{"name" : "operating_battery_h", "state_topic" : "wmbusmeters/00345343", "unique_id" : "operating_battery_h_00345343_aptmbusna.xmq", "expire_after" : "370", "value_template" : "{{ value_json.operating_battery_h }}", "unit_of_measurement" : "h", "json_attributes_topic" : "wmbusmeters/00345343", "json_attributes_template" : "{{ { \"Description\" : \"Duration working device on battery\" } | tojson }}", "device": {"serial_number" : "00345343", "hw_version" : "n/a" ,"manufacturer" : "Apator", "identifiers" : "00345343", "name" : "CWU_10", "model" : " (aptmbusna.xmq)" }, "origin" : {"name" : "wmbusmeters", "support_url" : "https://github.com/wmbusmeters/wmbusmeters/","sw_version" : "wmbusmeters: 1.17.1-29-g3af7a4c 3af7a4c8a881c10498f1e14d950d4e502ab2fa7e"}}' -u mqtt_user -P mqtt_user
/usr/bin/mosquitto_pub -h 192.168.15.20 -t "homeassistant/sensor/CWU_10/total_volume_m3/config" -m '{"name" : "total_volume_m3", "state_topic" : "wmbusmeters/00345343", "unique_id" : "total_volume_m3_00345343_aptmbusna.xmq", "expire_after" : "370", "value_template" : "{{ value_json.total_volume_m3 }}", "unit_of_measurement" : "m³", "state_class" : "TOTAL_INCREASING", "device_class" : "VOLUME", "json_attributes_topic" : "wmbusmeters/00345343", "json_attributes_template" : "{{ { \"Description\" : \"Total volume\" } | tojson }}", "device": {"serial_number" : "00345343", "hw_version" : "n/a" ,"manufacturer" : "Apator", "identifiers" : "00345343", "name" : "CWU_10", "model" : " (aptmbusna.xmq)" }, "origin" : {"name" : "wmbusmeters", "support_url" : "https://github.com/wmbusmeters/wmbusmeters/","sw_version" : "wmbusmeters: 1.17.1-29-g3af7a4c 3af7a4c8a881c10498f1e14d950d4e502ab2fa7e"}}' -u mqtt_user -P mqtt_user
/usr/bin/mosquitto_pub -h 192.168.15.20 -t "homeassistant/sensor/CWU_10/historical_meter_h/config" -m '{"name" : "historical_meter_h", "state_topic" : "wmbusmeters/00345343", "unique_id" : "historical_meter_h_00345343_aptmbusna.xmq", "expire_after" : "370", "value_template" : "{{ value_json.historical_meter_h }}", "unit_of_measurement" : "h", "json_attributes_topic" : "wmbusmeters/00345343", "json_attributes_template" : "{{ { \"Description\" : \"Historical date\" } | tojson }}", "device": {"serial_number" : "00345343", "hw_version" : "n/a" ,"manufacturer" : "Apator", "identifiers" : "00345343", "name" : "CWU_10", "model" : " (aptmbusna.xmq)" }, "origin" : {"name" : "wmbusmeters", "support_url" : "https://github.com/wmbusmeters/wmbusmeters/","sw_version" : "wmbusmeters: 1.17.1-29-g3af7a4c 3af7a4c8a881c10498f1e14d950d4e502ab2fa7e"}}' -u mqtt_user -P mqtt_user
/usr/bin/mosquitto_pub -h 192.168.15.20 -t "homeassistant/sensor/CWU_10/rssi_dbm/config" -m '{"name" : "rssi_dbm", "state_topic" : "wmbusmeters/00345343", "unique_id" : "rssi_dbm_00345343_aptmbusna.xmq", "expire_after" : "370", "enabled_by_default" : "False", "entity_category" : "diagnostic", "value_template" : "{{ value_json.rssi_dbm }}", "unit_of_measurement" : "dBm", "state_class" : "MEASUREMENT", "device_class" : "SIGNAL_STRENGTH", "json_attributes_topic" : "wmbusmeters/00345343", "json_attributes_template" : "{{ { \"Description\" : \"The rssi for the received telegram as reported by the device.\" } | tojson }}", "device": {"serial_number" : "00345343", "hw_version" : "n/a" ,"manufacturer" : "Apator", "identifiers" : "00345343", "name" : "CWU_10", "model" : " (aptmbusna.xmq)" }, "origin" : {"name" : "wmbusmeters", "support_url" : "https://github.com/wmbusmeters/wmbusmeters/","sw_version" : "wmbusmeters: 1.17.1-29-g3af7a4c 3af7a4c8a881c10498f1e14d950d4e502ab2fa7e"}}' -u mqtt_user -P mqtt_user
/usr/bin/mosquitto_pub -h 192.168.15.20 -t "homeassistant/sensor/CWU_10/current_volume_flow_m3h/config" -m '{"name" : "current_volume_flow_m3h", "state_topic" : "wmbusmeters/00345343", "unique_id" : "current_volume_flow_m3h_00345343_aptmbusna.xmq", "expire_after" : "370", "value_template" : "{{ value_json.current_volume_flow_m3h }}", "unit_of_measurement" : "m³/h", "state_class" : "MEASUREMENT", "device_class" : "VOLUME_FLOW_RATE", "json_attributes_topic" : "wmbusmeters/00345343", "json_attributes_template" : "{{ { \"Description\" : \"Current volume flow\" } | tojson }}", "device": {"serial_number" : "00345343", "hw_version" : "n/a" ,"manufacturer" : "Apator", "identifiers" : "00345343", "name" : "CWU_10", "model" : " (aptmbusna.xmq)" }, "origin" : {"name" : "wmbusmeters", "support_url" : "https://github.com/wmbusmeters/wmbusmeters/","sw_version" : "wmbusmeters: 1.17.1-29-g3af7a4c 3af7a4c8a881c10498f1e14d950d4e502ab2fa7e"}}' -u mqtt_user -P mqtt_user
/usr/bin/mosquitto_pub -h 192.168.15.20 -t "homeassistant/sensor/CWU_10/meter_h/config" -m '{"name" : "meter_h", "state_topic" : "wmbusmeters/00345343", "unique_id" : "meter_h_00345343_aptmbusna.xmq", "expire_after" : "370", "value_template" : "{{ value_json.meter_h }}", "unit_of_measurement" : "h", "json_attributes_topic" : "wmbusmeters/00345343", "json_attributes_template" : "{{ { \"Description\" : \"Overlay time\" } | tojson }}", "device": {"serial_number" : "00345343", "hw_version" : "n/a" ,"manufacturer" : "Apator", "identifiers" : "00345343", "name" : "CWU_10", "model" : " (aptmbusna.xmq)" }, "origin" : {"name" : "wmbusmeters", "support_url" : "https://github.com/wmbusmeters/wmbusmeters/","sw_version" : "wmbusmeters: 1.17.1-29-g3af7a4c 3af7a4c8a881c10498f1e14d950d4e502ab2fa7e"}}' -u mqtt_user -P mqtt_user
/usr/bin/mosquitto_pub -h 192.168.15.20 -t "homeassistant/sensor/CWU_10/id/config" -m '{"entity_category" : "diagnostic", "name" : "id", "value_template" : "{{ value_json.id }}" , "enabled_by_default" : "False", "state_topic" : "wmbusmeters/00345343", "unique_id" : "id_00345343_aptmbusna.xmq", "expire_after" : "370", "json_attributes_topic" : "wmbusmeters/00345343", "json_attributes_template" : "{{ { \"Description\" : \"The meter id number.\" } | tojson }}", "device": {"serial_number" : "00345343", "hw_version" : "n/a" ,"manufacturer" : "Apator", "identifiers" : "00345343", "name" : "CWU_10", "model" : " (aptmbusna.xmq)" }, "origin" : {"name" : "wmbusmeters", "support_url" : "https://github.com/wmbusmeters/wmbusmeters/","sw_version" : "wmbusmeters: 1.17.1-29-g3af7a4c 3af7a4c8a881c10498f1e14d950d4e502ab2fa7e"}}' -u mqtt_user -P mqtt_user
/usr/bin/mosquitto_pub -h 192.168.15.20 -t "homeassistant/sensor/CWU_10/name/config" -m '{"entity_category" : "diagnostic", "name" : "name", "value_template" : "{{ value_json.name }}" , "enabled_by_default" : "False", "state_topic" : "wmbusmeters/00345343", "unique_id" : "name_00345343_aptmbusna.xmq", "expire_after" : "370", "json_attributes_topic" : "wmbusmeters/00345343", "json_attributes_template" : "{{ { \"Description\" : \"Your name for the meter.\" } | tojson }}", "device": {"serial_number" : "00345343", "hw_version" : "n/a" ,"manufacturer" : "Apator", "identifiers" : "00345343", "name" : "CWU_10", "model" : " (aptmbusna.xmq)" }, "origin" : {"name" : "wmbusmeters", "support_url" : "https://github.com/wmbusmeters/wmbusmeters/","sw_version" : "wmbusmeters: 1.17.1-29-g3af7a4c 3af7a4c8a881c10498f1e14d950d4e502ab2fa7e"}}' -u mqtt_user -P mqtt_user
/usr/bin/mosquitto_pub -h 192.168.15.20 -t "homeassistant/sensor/CWU_10/media/config" -m '{"entity_category" : "diagnostic", "name" : "media", "value_template" : "{{ value_json.media }}" , "enabled_by_default" : "False", "state_topic" : "wmbusmeters/00345343", "unique_id" : "media_00345343_aptmbusna.xmq", "expire_after" : "370", "json_attributes_topic" : "wmbusmeters/00345343", "json_attributes_template" : "{{ { \"Description\" : \"What does the meter measure?\" } | tojson }}", "device": {"serial_number" : "00345343", "hw_version" : "n/a" ,"manufacturer" : "Apator", "identifiers" : "00345343", "name" : "CWU_10", "model" : " (aptmbusna.xmq)" }, "origin" : {"name" : "wmbusmeters", "support_url" : "https://github.com/wmbusmeters/wmbusmeters/","sw_version" : "wmbusmeters: 1.17.1-29-g3af7a4c 3af7a4c8a881c10498f1e14d950d4e502ab2fa7e"}}' -u mqtt_user -P mqtt_user
/usr/bin/mosquitto_pub -h 192.168.15.20 -t "homeassistant/sensor/CWU_10/meter/config" -m '{"entity_category" : "diagnostic", "name" : "meter", "value_template" : "{{ value_json.meter }}" , "enabled_by_default" : "False", "state_topic" : "wmbusmeters/00345343", "unique_id" : "meter_00345343_aptmbusna.xmq", "expire_after" : "370", "json_attributes_topic" : "wmbusmeters/00345343", "json_attributes_template" : "{{ { \"Description\" : \"Meter driver.\" } | tojson }}", "device": {"serial_number" : "00345343", "hw_version" : "n/a" ,"manufacturer" : "Apator", "identifiers" : "00345343", "name" : "CWU_10", "model" : " (aptmbusna.xmq)" }, "origin" : {"name" : "wmbusmeters", "support_url" : "https://github.com/wmbusmeters/wmbusmeters/","sw_version" : "wmbusmeters: 1.17.1-29-g3af7a4c 3af7a4c8a881c10498f1e14d950d4e502ab2fa7e"}}' -u mqtt_user -P mqtt_user
/usr/bin/mosquitto_pub -h 192.168.15.20 -t "homeassistant/sensor/CWU_10/timestamp/config" -m '{"entity_category" : "diagnostic", "name" : "timestamp", "device_class": "timestamp", "value_template" : "{{ value_json.timestamp | as_datetime() }}" , "enabled_by_default" : "True", "state_topic" : "wmbusmeters/00345343", "unique_id" : "timestamp_00345343_aptmbusna.xmq", "expire_after" : "370", "json_attributes_topic" : "wmbusmeters/00345343", "json_attributes_template" : "{{ { \"Description\" : \"Timestamp when wmbusmeters received the telegram. Local time for hr/fields UTC for json.\" } | tojson }}", "device": {"serial_number" : "00345343", "hw_version" : "n/a" ,"manufacturer" : "Apator", "identifiers" : "00345343", "name" : "CWU_10", "model" : " (aptmbusna.xmq)" }, "origin" : {"name" : "wmbusmeters", "support_url" : "https://github.com/wmbusmeters/wmbusmeters/","sw_version" : "wmbusmeters: 1.17.1-29-g3af7a4c 3af7a4c8a881c10498f1e14d950d4e502ab2fa7e"}}' -u mqtt_user -P mqtt_user
/usr/bin/mosquitto_pub -h 192.168.15.20 -t "homeassistant/sensor/CWU_10/device/config" -m '{"entity_category" : "diagnostic", "name" : "device", "value_template" : "{{ value_json.device }}" , "enabled_by_default" : "False", "state_topic" : "wmbusmeters/00345343", "unique_id" : "device_00345343_aptmbusna.xmq", "expire_after" : "370", "json_attributes_topic" : "wmbusmeters/00345343", "json_attributes_template" : "{{ { \"Description\" : \"The wmbus device that received the telegram.\" } | tojson }}", "device": {"serial_number" : "00345343", "hw_version" : "n/a" ,"manufacturer" : "Apator", "identifiers" : "00345343", "name" : "CWU_10", "model" : " (aptmbusna.xmq)" }, "origin" : {"name" : "wmbusmeters", "support_url" : "https://github.com/wmbusmeters/wmbusmeters/","sw_version" : "wmbusmeters: 1.17.1-29-g3af7a4c 3af7a4c8a881c10498f1e14d950d4e502ab2fa7e"}}' -u mqtt_user -P mqtt_user
/usr/bin/mosquitto_pub -h 192.168.15.20 -t "homeassistant/sensor/CWU_10/fabrication_no/config" -m '{"entity_category" : "diagnostic", "name" : "fabrication_no", "value_template" : "{{ value_json.fabrication_no }}" , "enabled_by_default" : "False", "state_topic" : "wmbusmeters/00345343", "unique_id" : "fabrication_no_00345343_aptmbusna.xmq", "expire_after" : "370", "json_attributes_topic" : "wmbusmeters/00345343", "json_attributes_template" : "{{ { \"Description\" : \"Fabrication number.\" } | tojson }}", "device": {"serial_number" : "00345343", "hw_version" : "n/a" ,"manufacturer" : "Apator", "identifiers" : "00345343", "name" : "CWU_10", "model" : " (aptmbusna.xmq)" }, "origin" : {"name" : "wmbusmeters", "support_url" : "https://github.com/wmbusmeters/wmbusmeters/","sw_version" : "wmbusmeters: 1.17.1-29-g3af7a4c 3af7a4c8a881c10498f1e14d950d4e502ab2fa7e"}}' -u mqtt_user -P mqtt_user
/usr/bin/mosquitto_pub -h 192.168.15.20 -t "homeassistant/sensor/CWU_10/optical_diagnostic/config" -m '{"entity_category" : "diagnostic", "name" : "optical_diagnostic", "value_template" : "{{ value_json.optical_diagnostic }}" , "enabled_by_default" : "False", "state_topic" : "wmbusmeters/00345343", "unique_id" : "optical_diagnostic_00345343_aptmbusna.xmq", "expire_after" : "370", "json_attributes_topic" : "wmbusmeters/00345343", "json_attributes_template" : "{{ { \"Description\" : \"Optical diagnostic raw data\" } | tojson }}", "device": {"serial_number" : "00345343", "hw_version" : "n/a" ,"manufacturer" : "Apator", "identifiers" : "00345343", "name" : "CWU_10", "model" : " (aptmbusna.xmq)" }, "origin" : {"name" : "wmbusmeters", "support_url" : "https://github.com/wmbusmeters/wmbusmeters/","sw_version" : "wmbusmeters: 1.17.1-29-g3af7a4c 3af7a4c8a881c10498f1e14d950d4e502ab2fa7e"}}' -u mqtt_user -P mqtt_user
/usr/bin/mosquitto_pub -h 192.168.15.20 -t "homeassistant/sensor/CWU_10/oscilator_diagnostic/config" -m '{"entity_category" : "diagnostic", "name" : "oscilator_diagnostic", "value_template" : "{{ value_json.oscilator_diagnostic }}" , "enabled_by_default" : "False", "state_topic" : "wmbusmeters/00345343", "unique_id" : "oscilator_diagnostic_00345343_aptmbusna.xmq", "expire_after" : "370", "json_attributes_topic" : "wmbusmeters/00345343", "json_attributes_template" : "{{ { \"Description\" : \"Oscilator raw diagnostic data\" } | tojson }}", "device": {"serial_number" : "00345343", "hw_version" : "n/a" ,"manufacturer" : "Apator", "identifiers" : "00345343", "name" : "CWU_10", "model" : " (aptmbusna.xmq)" }, "origin" : {"name" : "wmbusmeters", "support_url" : "https://github.com/wmbusmeters/wmbusmeters/","sw_version" : "wmbusmeters: 1.17.1-29-g3af7a4c 3af7a4c8a881c10498f1e14d950d4e502ab2fa7e"}}' -u mqtt_user -P mqtt_user
/usr/bin/mosquitto_pub -h 192.168.15.20 -t "homeassistant/sensor/CWU_10/power_supply_diagnostic/config" -m '{"entity_category" : "diagnostic", "name" : "power_supply_diagnostic", "value_template" : "{{ value_json.power_supply_diagnostic }}" , "enabled_by_default" : "False", "state_topic" : "wmbusmeters/00345343", "unique_id" : "power_supply_diagnostic_00345343_aptmbusna.xmq", "expire_after" : "370", "json_attributes_topic" : "wmbusmeters/00345343", "json_attributes_template" : "{{ { \"Description\" : \"Power supply raw diagnostic data\" } | tojson }}", "device": {"serial_number" : "00345343", "hw_version" : "n/a" ,"manufacturer" : "Apator", "identifiers" : "00345343", "name" : "CWU_10", "model" : " (aptmbusna.xmq)" }, "origin" : {"name" : "wmbusmeters", "support_url" : "https://github.com/wmbusmeters/wmbusmeters/","sw_version" : "wmbusmeters: 1.17.1-29-g3af7a4c 3af7a4c8a881c10498f1e14d950d4e502ab2fa7e"}}' -u mqtt_user -P mqtt_user
/usr/bin/mosquitto_pub -h 192.168.15.20 -t "homeassistant/sensor/CWU_10/events_permanent_type/config" -m '{"entity_category" : "diagnostic", "name" : "events_permanent_type", "value_template" : "{{ value_json.events_permanent_type }}" , "enabled_by_default" : "False", "state_topic" : "wmbusmeters/00345343", "unique_id" : "events_permanent_type_00345343_aptmbusna.xmq", "expire_after" : "370", "json_attributes_topic" : "wmbusmeters/00345343", "json_attributes_template" : "{{ { \"Description\" : \"Pernamemnt events type statuses\" } | tojson }}", "device": {"serial_number" : "00345343", "hw_version" : "n/a" ,"manufacturer" : "Apator", "identifiers" : "00345343", "name" : "CWU_10", "model" : " (aptmbusna.xmq)" }, "origin" : {"name" : "wmbusmeters", "support_url" : "https://github.com/wmbusmeters/wmbusmeters/","sw_version" : "wmbusmeters: 1.17.1-29-g3af7a4c 3af7a4c8a881c10498f1e14d950d4e502ab2fa7e"}}' -u mqtt_user -P mqtt_user
/usr/bin/mosquitto_pub -h 192.168.15.20 -t "homeassistant/sensor/CWU_10/events_active_type/config" -m '{"entity_category" : "diagnostic", "name" : "events_active_type", "value_template" : "{{ value_json.events_active_type }}" , "enabled_by_default" : "False", "state_topic" : "wmbusmeters/00345343", "unique_id" : "events_active_type_00345343_aptmbusna.xmq", "expire_after" : "370", "json_attributes_topic" : "wmbusmeters/00345343", "json_attributes_template" : "{{ { \"Description\" : \"Active events type statuses\" } | tojson }}", "device": {"serial_number" : "00345343", "hw_version" : "n/a" ,"manufacturer" : "Apator", "identifiers" : "00345343", "name" : "CWU_10", "model" : " (aptmbusna.xmq)" }, "origin" : {"name" : "wmbusmeters", "support_url" : "https://github.com/wmbusmeters/wmbusmeters/","sw_version" : "wmbusmeters: 1.17.1-29-g3af7a4c 3af7a4c8a881c10498f1e14d950d4e502ab2fa7e"}}' -u mqtt_user -P mqtt_user
When I choose some disabled entity (created in similar way as above msg) w/o retain flag, for example from other device "CO_5":
then after switch to enable and click "update" appear below popup window:
After the operation all entices change to unavailable, some example for all entices w/o retied flag:
Additional in log appear below error:
(please note yesterday when found the issue also appear the error but occur only one in logs and not repeated any more when tested the issue many times yesterday so I was not sure is connected. Today I restart HA due to HACS update addon and after enable entity w/o retained flag appear again the same error in logs. But when testing today again only one appear. Of course after today restart HA I send MQTT discovry msg because no retained flag but this is not related to the issue).
Due to unavailable statuses I need send again all MQTT discovery msg.
CASE 2
For test add for device "CWU_4" retain flag (MQTT discovery msg are)
/usr/bin/mosquitto_pub -h 192.168.15.20 -r -t "homeassistant/sensor/CWU_4/historical_total_m3/config" -m '{"name" : "historical_total_m3", "state_topic" : "wmbusmeters/00345355", "unique_id" : "historical_total_m3_00345355_aptmbusna.xmq", "expire_after" : "370", "value_template" : "{{ value_json.historical_total_m3 }}", "unit_of_measurement" : "m³", "state_class" : "TOTAL_INCREASING", "device_class" : "VOLUME", "json_attributes_topic" : "wmbusmeters/00345355", "json_attributes_template" : "{{ { \"Description\" : \"Historical total volume\" } | tojson }}", "device": {"serial_number" : "00345355", "hw_version" : "n/a" ,"manufacturer" : "Apator", "identifiers" : "00345355", "name" : "CWU_4", "model" : " (aptmbusna.xmq)" }, "origin" : {"name" : "wmbusmeters", "support_url" : "https://github.com/wmbusmeters/wmbusmeters/","sw_version" : "wmbusmeters: 1.17.1-29-g3af7a4c 3af7a4c8a881c10498f1e14d950d4e502ab2fa7e"}}' -u mqtt_user -P mqtt_user
/usr/bin/mosquitto_pub -h 192.168.15.20 -r -t "homeassistant/sensor/CWU_4/operating_battery_h/config" -m '{"name" : "operating_battery_h", "state_topic" : "wmbusmeters/00345355", "unique_id" : "operating_battery_h_00345355_aptmbusna.xmq", "expire_after" : "370", "value_template" : "{{ value_json.operating_battery_h }}", "unit_of_measurement" : "h", "json_attributes_topic" : "wmbusmeters/00345355", "json_attributes_template" : "{{ { \"Description\" : \"Duration working device on battery\" } | tojson }}", "device": {"serial_number" : "00345355", "hw_version" : "n/a" ,"manufacturer" : "Apator", "identifiers" : "00345355", "name" : "CWU_4", "model" : " (aptmbusna.xmq)" }, "origin" : {"name" : "wmbusmeters", "support_url" : "https://github.com/wmbusmeters/wmbusmeters/","sw_version" : "wmbusmeters: 1.17.1-29-g3af7a4c 3af7a4c8a881c10498f1e14d950d4e502ab2fa7e"}}' -u mqtt_user -P mqtt_user
/usr/bin/mosquitto_pub -h 192.168.15.20 -r -t "homeassistant/sensor/CWU_4/total_volume_m3/config" -m '{"name" : "total_volume_m3", "state_topic" : "wmbusmeters/00345355", "unique_id" : "total_volume_m3_00345355_aptmbusna.xmq", "expire_after" : "370", "value_template" : "{{ value_json.total_volume_m3 }}", "unit_of_measurement" : "m³", "state_class" : "TOTAL_INCREASING", "device_class" : "VOLUME", "json_attributes_topic" : "wmbusmeters/00345355", "json_attributes_template" : "{{ { \"Description\" : \"Total volume\" } | tojson }}", "device": {"serial_number" : "00345355", "hw_version" : "n/a" ,"manufacturer" : "Apator", "identifiers" : "00345355", "name" : "CWU_4", "model" : " (aptmbusna.xmq)" }, "origin" : {"name" : "wmbusmeters", "support_url" : "https://github.com/wmbusmeters/wmbusmeters/","sw_version" : "wmbusmeters: 1.17.1-29-g3af7a4c 3af7a4c8a881c10498f1e14d950d4e502ab2fa7e"}}' -u mqtt_user -P mqtt_user
/usr/bin/mosquitto_pub -h 192.168.15.20 -r -t "homeassistant/sensor/CWU_4/historical_meter_h/config" -m '{"name" : "historical_meter_h", "state_topic" : "wmbusmeters/00345355", "unique_id" : "historical_meter_h_00345355_aptmbusna.xmq", "expire_after" : "370", "value_template" : "{{ value_json.historical_meter_h }}", "unit_of_measurement" : "h", "json_attributes_topic" : "wmbusmeters/00345355", "json_attributes_template" : "{{ { \"Description\" : \"Historical date\" } | tojson }}", "device": {"serial_number" : "00345355", "hw_version" : "n/a" ,"manufacturer" : "Apator", "identifiers" : "00345355", "name" : "CWU_4", "model" : " (aptmbusna.xmq)" }, "origin" : {"name" : "wmbusmeters", "support_url" : "https://github.com/wmbusmeters/wmbusmeters/","sw_version" : "wmbusmeters: 1.17.1-29-g3af7a4c 3af7a4c8a881c10498f1e14d950d4e502ab2fa7e"}}' -u mqtt_user -P mqtt_user
/usr/bin/mosquitto_pub -h 192.168.15.20 -r -t "homeassistant/sensor/CWU_4/rssi_dbm/config" -m '{"name" : "rssi_dbm", "state_topic" : "wmbusmeters/00345355", "unique_id" : "rssi_dbm_00345355_aptmbusna.xmq", "expire_after" : "370", "enabled_by_default" : "False", "entity_category" : "diagnostic", "value_template" : "{{ value_json.rssi_dbm }}", "unit_of_measurement" : "dBm", "state_class" : "MEASUREMENT", "device_class" : "SIGNAL_STRENGTH", "json_attributes_topic" : "wmbusmeters/00345355", "json_attributes_template" : "{{ { \"Description\" : \"The rssi for the received telegram as reported by the device.\" } | tojson }}", "device": {"serial_number" : "00345355", "hw_version" : "n/a" ,"manufacturer" : "Apator", "identifiers" : "00345355", "name" : "CWU_4", "model" : " (aptmbusna.xmq)" }, "origin" : {"name" : "wmbusmeters", "support_url" : "https://github.com/wmbusmeters/wmbusmeters/","sw_version" : "wmbusmeters: 1.17.1-29-g3af7a4c 3af7a4c8a881c10498f1e14d950d4e502ab2fa7e"}}' -u mqtt_user -P mqtt_user
/usr/bin/mosquitto_pub -h 192.168.15.20 -r -t "homeassistant/sensor/CWU_4/current_volume_flow_m3h/config" -m '{"name" : "current_volume_flow_m3h", "state_topic" : "wmbusmeters/00345355", "unique_id" : "current_volume_flow_m3h_00345355_aptmbusna.xmq", "expire_after" : "370", "value_template" : "{{ value_json.current_volume_flow_m3h }}", "unit_of_measurement" : "m³/h", "state_class" : "MEASUREMENT", "device_class" : "VOLUME_FLOW_RATE", "json_attributes_topic" : "wmbusmeters/00345355", "json_attributes_template" : "{{ { \"Description\" : \"Current volume flow\" } | tojson }}", "device": {"serial_number" : "00345355", "hw_version" : "n/a" ,"manufacturer" : "Apator", "identifiers" : "00345355", "name" : "CWU_4", "model" : " (aptmbusna.xmq)" }, "origin" : {"name" : "wmbusmeters", "support_url" : "https://github.com/wmbusmeters/wmbusmeters/","sw_version" : "wmbusmeters: 1.17.1-29-g3af7a4c 3af7a4c8a881c10498f1e14d950d4e502ab2fa7e"}}' -u mqtt_user -P mqtt_user
/usr/bin/mosquitto_pub -h 192.168.15.20 -r -t "homeassistant/sensor/CWU_4/meter_h/config" -m '{"name" : "meter_h", "state_topic" : "wmbusmeters/00345355", "unique_id" : "meter_h_00345355_aptmbusna.xmq", "expire_after" : "370", "value_template" : "{{ value_json.meter_h }}", "unit_of_measurement" : "h", "json_attributes_topic" : "wmbusmeters/00345355", "json_attributes_template" : "{{ { \"Description\" : \"Overlay time\" } | tojson }}", "device": {"serial_number" : "00345355", "hw_version" : "n/a" ,"manufacturer" : "Apator", "identifiers" : "00345355", "name" : "CWU_4", "model" : " (aptmbusna.xmq)" }, "origin" : {"name" : "wmbusmeters", "support_url" : "https://github.com/wmbusmeters/wmbusmeters/","sw_version" : "wmbusmeters: 1.17.1-29-g3af7a4c 3af7a4c8a881c10498f1e14d950d4e502ab2fa7e"}}' -u mqtt_user -P mqtt_user
/usr/bin/mosquitto_pub -h 192.168.15.20 -r -t "homeassistant/sensor/CWU_4/id/config" -m '{"entity_category" : "diagnostic", "name" : "id", "value_template" : "{{ value_json.id }}" , "enabled_by_default" : "False", "state_topic" : "wmbusmeters/00345355", "unique_id" : "id_00345355_aptmbusna.xmq", "expire_after" : "370", "json_attributes_topic" : "wmbusmeters/00345355", "json_attributes_template" : "{{ { \"Description\" : \"The meter id number.\" } | tojson }}", "device": {"serial_number" : "00345355", "hw_version" : "n/a" ,"manufacturer" : "Apator", "identifiers" : "00345355", "name" : "CWU_4", "model" : " (aptmbusna.xmq)" }, "origin" : {"name" : "wmbusmeters", "support_url" : "https://github.com/wmbusmeters/wmbusmeters/","sw_version" : "wmbusmeters: 1.17.1-29-g3af7a4c 3af7a4c8a881c10498f1e14d950d4e502ab2fa7e"}}' -u mqtt_user -P mqtt_user
/usr/bin/mosquitto_pub -h 192.168.15.20 -r -t "homeassistant/sensor/CWU_4/name/config" -m '{"entity_category" : "diagnostic", "name" : "name", "value_template" : "{{ value_json.name }}" , "enabled_by_default" : "False", "state_topic" : "wmbusmeters/00345355", "unique_id" : "name_00345355_aptmbusna.xmq", "expire_after" : "370", "json_attributes_topic" : "wmbusmeters/00345355", "json_attributes_template" : "{{ { \"Description\" : \"Your name for the meter.\" } | tojson }}", "device": {"serial_number" : "00345355", "hw_version" : "n/a" ,"manufacturer" : "Apator", "identifiers" : "00345355", "name" : "CWU_4", "model" : " (aptmbusna.xmq)" }, "origin" : {"name" : "wmbusmeters", "support_url" : "https://github.com/wmbusmeters/wmbusmeters/","sw_version" : "wmbusmeters: 1.17.1-29-g3af7a4c 3af7a4c8a881c10498f1e14d950d4e502ab2fa7e"}}' -u mqtt_user -P mqtt_user
/usr/bin/mosquitto_pub -h 192.168.15.20 -r -t "homeassistant/sensor/CWU_4/media/config" -m '{"entity_category" : "diagnostic", "name" : "media", "value_template" : "{{ value_json.media }}" , "enabled_by_default" : "False", "state_topic" : "wmbusmeters/00345355", "unique_id" : "media_00345355_aptmbusna.xmq", "expire_after" : "370", "json_attributes_topic" : "wmbusmeters/00345355", "json_attributes_template" : "{{ { \"Description\" : \"What does the meter measure?\" } | tojson }}", "device": {"serial_number" : "00345355", "hw_version" : "n/a" ,"manufacturer" : "Apator", "identifiers" : "00345355", "name" : "CWU_4", "model" : " (aptmbusna.xmq)" }, "origin" : {"name" : "wmbusmeters", "support_url" : "https://github.com/wmbusmeters/wmbusmeters/","sw_version" : "wmbusmeters: 1.17.1-29-g3af7a4c 3af7a4c8a881c10498f1e14d950d4e502ab2fa7e"}}' -u mqtt_user -P mqtt_user
/usr/bin/mosquitto_pub -h 192.168.15.20 -r -t "homeassistant/sensor/CWU_4/meter/config" -m '{"entity_category" : "diagnostic", "name" : "meter", "value_template" : "{{ value_json.meter }}" , "enabled_by_default" : "False", "state_topic" : "wmbusmeters/00345355", "unique_id" : "meter_00345355_aptmbusna.xmq", "expire_after" : "370", "json_attributes_topic" : "wmbusmeters/00345355", "json_attributes_template" : "{{ { \"Description\" : \"Meter driver.\" } | tojson }}", "device": {"serial_number" : "00345355", "hw_version" : "n/a" ,"manufacturer" : "Apator", "identifiers" : "00345355", "name" : "CWU_4", "model" : " (aptmbusna.xmq)" }, "origin" : {"name" : "wmbusmeters", "support_url" : "https://github.com/wmbusmeters/wmbusmeters/","sw_version" : "wmbusmeters: 1.17.1-29-g3af7a4c 3af7a4c8a881c10498f1e14d950d4e502ab2fa7e"}}' -u mqtt_user -P mqtt_user
/usr/bin/mosquitto_pub -h 192.168.15.20 -r -t "homeassistant/sensor/CWU_4/timestamp/config" -m '{"entity_category" : "diagnostic", "name" : "timestamp", "device_class": "timestamp", "value_template" : "{{ value_json.timestamp | as_datetime() }}" , "enabled_by_default" : "True", "state_topic" : "wmbusmeters/00345355", "unique_id" : "timestamp_00345355_aptmbusna.xmq", "expire_after" : "370", "json_attributes_topic" : "wmbusmeters/00345355", "json_attributes_template" : "{{ { \"Description\" : \"Timestamp when wmbusmeters received the telegram. Local time for hr/fields UTC for json.\" } | tojson }}", "device": {"serial_number" : "00345355", "hw_version" : "n/a" ,"manufacturer" : "Apator", "identifiers" : "00345355", "name" : "CWU_4", "model" : " (aptmbusna.xmq)" }, "origin" : {"name" : "wmbusmeters", "support_url" : "https://github.com/wmbusmeters/wmbusmeters/","sw_version" : "wmbusmeters: 1.17.1-29-g3af7a4c 3af7a4c8a881c10498f1e14d950d4e502ab2fa7e"}}' -u mqtt_user -P mqtt_user
/usr/bin/mosquitto_pub -h 192.168.15.20 -r -t "homeassistant/sensor/CWU_4/device/config" -m '{"entity_category" : "diagnostic", "name" : "device", "value_template" : "{{ value_json.device }}" , "enabled_by_default" : "False", "state_topic" : "wmbusmeters/00345355", "unique_id" : "device_00345355_aptmbusna.xmq", "expire_after" : "370", "json_attributes_topic" : "wmbusmeters/00345355", "json_attributes_template" : "{{ { \"Description\" : \"The wmbus device that received the telegram.\" } | tojson }}", "device": {"serial_number" : "00345355", "hw_version" : "n/a" ,"manufacturer" : "Apator", "identifiers" : "00345355", "name" : "CWU_4", "model" : " (aptmbusna.xmq)" }, "origin" : {"name" : "wmbusmeters", "support_url" : "https://github.com/wmbusmeters/wmbusmeters/","sw_version" : "wmbusmeters: 1.17.1-29-g3af7a4c 3af7a4c8a881c10498f1e14d950d4e502ab2fa7e"}}' -u mqtt_user -P mqtt_user
/usr/bin/mosquitto_pub -h 192.168.15.20 -r -t "homeassistant/sensor/CWU_4/fabrication_no/config" -m '{"entity_category" : "diagnostic", "name" : "fabrication_no", "value_template" : "{{ value_json.fabrication_no }}" , "enabled_by_default" : "False", "state_topic" : "wmbusmeters/00345355", "unique_id" : "fabrication_no_00345355_aptmbusna.xmq", "expire_after" : "370", "json_attributes_topic" : "wmbusmeters/00345355", "json_attributes_template" : "{{ { \"Description\" : \"Fabrication number.\" } | tojson }}", "device": {"serial_number" : "00345355", "hw_version" : "n/a" ,"manufacturer" : "Apator", "identifiers" : "00345355", "name" : "CWU_4", "model" : " (aptmbusna.xmq)" }, "origin" : {"name" : "wmbusmeters", "support_url" : "https://github.com/wmbusmeters/wmbusmeters/","sw_version" : "wmbusmeters: 1.17.1-29-g3af7a4c 3af7a4c8a881c10498f1e14d950d4e502ab2fa7e"}}' -u mqtt_user -P mqtt_user
/usr/bin/mosquitto_pub -h 192.168.15.20 -r -t "homeassistant/sensor/CWU_4/optical_diagnostic/config" -m '{"entity_category" : "diagnostic", "name" : "optical_diagnostic", "value_template" : "{{ value_json.optical_diagnostic }}" , "enabled_by_default" : "False", "state_topic" : "wmbusmeters/00345355", "unique_id" : "optical_diagnostic_00345355_aptmbusna.xmq", "expire_after" : "370", "json_attributes_topic" : "wmbusmeters/00345355", "json_attributes_template" : "{{ { \"Description\" : \"Optical diagnostic raw data\" } | tojson }}", "device": {"serial_number" : "00345355", "hw_version" : "n/a" ,"manufacturer" : "Apator", "identifiers" : "00345355", "name" : "CWU_4", "model" : " (aptmbusna.xmq)" }, "origin" : {"name" : "wmbusmeters", "support_url" : "https://github.com/wmbusmeters/wmbusmeters/","sw_version" : "wmbusmeters: 1.17.1-29-g3af7a4c 3af7a4c8a881c10498f1e14d950d4e502ab2fa7e"}}' -u mqtt_user -P mqtt_user
/usr/bin/mosquitto_pub -h 192.168.15.20 -r -t "homeassistant/sensor/CWU_4/oscilator_diagnostic/config" -m '{"entity_category" : "diagnostic", "name" : "oscilator_diagnostic", "value_template" : "{{ value_json.oscilator_diagnostic }}" , "enabled_by_default" : "False", "state_topic" : "wmbusmeters/00345355", "unique_id" : "oscilator_diagnostic_00345355_aptmbusna.xmq", "expire_after" : "370", "json_attributes_topic" : "wmbusmeters/00345355", "json_attributes_template" : "{{ { \"Description\" : \"Oscilator raw diagnostic data\" } | tojson }}", "device": {"serial_number" : "00345355", "hw_version" : "n/a" ,"manufacturer" : "Apator", "identifiers" : "00345355", "name" : "CWU_4", "model" : " (aptmbusna.xmq)" }, "origin" : {"name" : "wmbusmeters", "support_url" : "https://github.com/wmbusmeters/wmbusmeters/","sw_version" : "wmbusmeters: 1.17.1-29-g3af7a4c 3af7a4c8a881c10498f1e14d950d4e502ab2fa7e"}}' -u mqtt_user -P mqtt_user
/usr/bin/mosquitto_pub -h 192.168.15.20 -r -t "homeassistant/sensor/CWU_4/power_supply_diagnostic/config" -m '{"entity_category" : "diagnostic", "name" : "power_supply_diagnostic", "value_template" : "{{ value_json.power_supply_diagnostic }}" , "enabled_by_default" : "False", "state_topic" : "wmbusmeters/00345355", "unique_id" : "power_supply_diagnostic_00345355_aptmbusna.xmq", "expire_after" : "370", "json_attributes_topic" : "wmbusmeters/00345355", "json_attributes_template" : "{{ { \"Description\" : \"Power supply raw diagnostic data\" } | tojson }}", "device": {"serial_number" : "00345355", "hw_version" : "n/a" ,"manufacturer" : "Apator", "identifiers" : "00345355", "name" : "CWU_4", "model" : " (aptmbusna.xmq)" }, "origin" : {"name" : "wmbusmeters", "support_url" : "https://github.com/wmbusmeters/wmbusmeters/","sw_version" : "wmbusmeters: 1.17.1-29-g3af7a4c 3af7a4c8a881c10498f1e14d950d4e502ab2fa7e"}}' -u mqtt_user -P mqtt_user
/usr/bin/mosquitto_pub -h 192.168.15.20 -r -t "homeassistant/sensor/CWU_4/events_permanent_type/config" -m '{"entity_category" : "diagnostic", "name" : "events_permanent_type", "value_template" : "{{ value_json.events_permanent_type }}" , "enabled_by_default" : "False", "state_topic" : "wmbusmeters/00345355", "unique_id" : "events_permanent_type_00345355_aptmbusna.xmq", "expire_after" : "370", "json_attributes_topic" : "wmbusmeters/00345355", "json_attributes_template" : "{{ { \"Description\" : \"Pernamemnt events type statuses\" } | tojson }}", "device": {"serial_number" : "00345355", "hw_version" : "n/a" ,"manufacturer" : "Apator", "identifiers" : "00345355", "name" : "CWU_4", "model" : " (aptmbusna.xmq)" }, "origin" : {"name" : "wmbusmeters", "support_url" : "https://github.com/wmbusmeters/wmbusmeters/","sw_version" : "wmbusmeters: 1.17.1-29-g3af7a4c 3af7a4c8a881c10498f1e14d950d4e502ab2fa7e"}}' -u mqtt_user -P mqtt_user
/usr/bin/mosquitto_pub -h 192.168.15.20 -r -t "homeassistant/sensor/CWU_4/events_active_type/config" -m '{"entity_category" : "diagnostic", "name" : "events_active_type", "value_template" : "{{ value_json.events_active_type }}" , "enabled_by_default" : "False", "state_topic" : "wmbusmeters/00345355", "unique_id" : "events_active_type_00345355_aptmbusna.xmq", "expire_after" : "370", "json_attributes_topic" : "wmbusmeters/00345355", "json_attributes_template" : "{{ { \"Description\" : \"Active events type statuses\" } | tojson }}", "device": {"serial_number" : "00345355", "hw_version" : "n/a" ,"manufacturer" : "Apator", "identifiers" : "00345355", "name" : "CWU_4", "model" : " (aptmbusna.xmq)" }, "origin" : {"name" : "wmbusmeters", "support_url" : "https://github.com/wmbusmeters/wmbusmeters/","sw_version" : "wmbusmeters: 1.17.1-29-g3af7a4c 3af7a4c8a881c10498f1e14d950d4e502ab2fa7e"}}' -u mqtt_user -P mqtt_user
When I enable entice with retained flag like below:
Then I see this:
After arrive msg with topic state then data is updated (please ignore unknown states, have issue for this entices but this is other cause not touching here)
But for all other etitces without retained again all are unavailable status for example device "CWU_5" (I'm sorry, yesterday in night when created the issue I wrote that in this cause no impact for entities w/o retained flag, this is not correct, there is also impact):
or CO_1
Summary.
When I change status of entice from disable to enable all entices w/o retained flag become into unavailable status and need sent again MQTT discovery msg for them.
Can you help me to step by step reproduce this my self (including a sample state update)?
Explain step by step what you would expect and what happens and should be correct to your opinion.
Under normal conditions: During HA startup:
I did some testing. When an entity is disabled, it does not publish a state. As soon as the entity is enabled a state update must be received and processed, till then the entity show unavailable, because there is no state yet. ~May be it is possible to trigger a state write after an entity was enabled so it will publish it latest state received.~
It seems when en entity is not enabled, it is not listening for state updates, till it is added to Home Assistant. This means that entities will not have a state till they are receiving one. It should not be needed though to resend the discovery payload.
Can you help me to step by step reproduce this my self (including a sample state update)?
Yes, I will try explain step by step:
Important info:
enabled_by_default = false
this mean disabled by default. Some of it later I will enabling in HA and will create a issue. /usr/bin/mosquitto_pub -h 192.168.15.20 -t wmbusmeters/$METER_ID -m "$JSON" -u mqtt_user -P mqtt_user
where $JSON
is one of json.zip file, each json is for each device contain many entices.
Payload of subscribe topics (for enable and disable entices) are sending from external system completely and independent from state of entice in HA. In other words external system sending values for all entices every 3 min.
Until restart HA or enable disabled entice all is fine
When one of disabled entice created by MQTT discovery msg from point 1. I change to enable then all entices w/o retention flags or availability functionality become to unavailable state. This is main problem.
Regarding below:
During HA startup:
- A discovery message is expected (or a retained one is replayed).
- If the entity has availability options, then an availability state update should follow (or it should be a retained value that is replayed when we subscribe for the availability topic).
- Next a state update should follow.
I use 1st option, sending MQTT discovery msg after HA restart, no using 2nd availability or retained.
About this:
When an entity is disabled, it does not publish a state. As soon as the entity is enabled a state update must be received and processed, till then the entity show unavailable, because there is no state yet.
It seems when en entity is not enabled, it is not listening for state updates, till it is added to Home Assistant. This means that entities will not have a state till they are receiving one. It should not be needed though to resend the discovery payload.
Agree that after change from disabled to enabled this one particular entity should get unavailable state and wait for subscribed topic for update the state.
But unavailability become ALL enabled entices from all devices w/o retained flags! Should one this one be unavailable.
So for example at 22:27:33 I enable ONE disabled entice and after that all enabled entices become unavailable. This all enabled and updated every 3 min entices are w/o retention and availability flag. Please note every 3 min is publishing (sending to HA MQTT) subscribed topics, from external system.
Additional please note that there missing all payloads and subscribed topics after enabled only one entice w/o retention flag and availability. But in background of the below picture you can found logbook where you see that there was updated values and become unavailable.
BTW. Just found something that could help. In normal state (when no try enabled entice) In MQTT Info page (like on picture below) there is no showed definition (subscribed topic) for disabled entices. But disabled entices are listed in gray and you can enable it. Also they has been created by MQTT discovery msg. Because there is no definition here then maybe MQTT HA logic is waiting again for discover msg? But this have no sense...
The problem
Enabling entice from disabled state cause for all other entities created by MQTT discovery msg with NO retain flag unavailability status. According documentation missing retain flag have only impact for HA restarting, not information that enabling entities have also impact for entices with NO retention flag.
Please note enabling disable entice WITH retention flag have no impact for other entices created by MQTT discovery msg with NO retention flag.
What version of Home Assistant Core has the issue?
core-2024.10.4
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
MQTT
Link to integration documentation on our website
https://www.home-assistant.io/integrations/mqtt/
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