Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable disabled entity cause disable all others with no retain flag #129759

Closed
kzajac83 opened this issue Nov 3, 2024 · 18 comments · Fixed by home-assistant/home-assistant.io#35763

Comments

@kzajac83
Copy link

kzajac83 commented Nov 3, 2024

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

@home-assistant
Copy link

home-assistant bot commented Nov 3, 2024

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
Copy link
Contributor

jbouwh commented Nov 4, 2024

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.

@jbouwh
Copy link
Contributor

jbouwh commented Nov 4, 2024

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.

@kzajac83
Copy link
Author

kzajac83 commented Nov 4, 2024

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":

image

then after switch to enable and click "update" appear below popup window:

image

After the operation all entices change to unavailable, some example for all entices w/o retied flag:
image

Additional in log appear below error:

image

(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:

image

Then I see this:

image

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)

image

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):

image

or CO_1

image

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.

@jbouwh
Copy link
Contributor

jbouwh commented Nov 4, 2024

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.

@jbouwh
Copy link
Contributor

jbouwh commented Nov 4, 2024

Under normal conditions:
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.

@jbouwh
Copy link
Contributor

jbouwh commented Nov 4, 2024

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.

@kzajac83
Copy link
Author

kzajac83 commented Nov 4, 2024

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:

  1. Once after HA (re)start I generate many MQTT discovery msgs, whole command is here: MQTT_Discovery_msg.txt. After received the msgs HA creating 19 MQTT devices and about 900 entices with unique_id.

Important info:

  • Partially the messages include defined entices with option enabled_by_default = false this mean disabled by default. Some of it later I will enabling in HA and will create a issue.
  • All entices have no retention flags or availability definition.
  1. Every 3 min (180 sec) is executing command from external system:

/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.

  1. Until restart HA or enable disabled entice all is fine

  2. 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.

image

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.

image

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...

image

@jbouwh
Copy link
Contributor

jbouwh commented Nov 5, 2024

So your conclusion is:

But unavailability become ALL enabled entities from all devices w/o retained flag!

You would expect the entity that is to be enabled to be unavailable till it receives a state update, but the other entities should keep its state. Instead all other, already enabled entities, loose their state as well. Is that correct?

@kzajac83
Copy link
Author

kzajac83 commented Nov 5, 2024

Yes, this is correct. But...

Lost state for all others entices w/o retained or availability till received new values (in my case every 3 min) would be not a problem, if this be working :)

But above not working, on screenshots I try shown that after 40 min all working earlier entices that become unavaliable was not updated (should be updated in my case up to 3 min) after enable only one entice and I need send again about 900 MQTT discovery msg for all others entices w/o retained flag or availability. This is root of my cause.

@jbouwh
Copy link
Contributor

jbouwh commented Nov 5, 2024

I did test with 2 entities (2 different devices). One loaded, one disabled (, all without retain flag).

Then I published state for the enabled entity and enabled the disabled one. The state of the already enabled entity became unavailable. So I was able to reproduce your issue. I guess this might be something outside the MQTT integration. When we enable an entity after 30 sec it seems to influence the states of all already loaded entities.

@kzajac83
Copy link
Author

kzajac83 commented Nov 5, 2024

I'm happy that you reproduce the issue. However if no MQTT area then maybe you know who I should call?

From my perspective enabling disabled entice could execute similar functions like restart HA because under "MQTT Info" missing all definitions of entices (after enable entice no subscription topic, payloads etc). The same is after restart HA.

@emontnemery
Copy link
Contributor

emontnemery commented Nov 5, 2024

Enabling or disabling an entity makes the MQTT config entry reload. This means the behavior after enabling or disabling an entity is the same as when Home Assistant starts.

If you don't want discovery messages to be retained, you need to listen to home assistant's birth message and publish the discovery messages when that's received.

If you don't want state messages to be retained, you should periodically retransmit them also when they've not changed, perhaps once every 5 minutes.

@kzajac83 it's a bit unclear to me if your concern is non-retained discovery messages, non-retained state messages or both.

@emontnemery
Copy link
Contributor

emontnemery commented Nov 5, 2024

@kzajac83 according to @jbouwh your concern is non-retained discovery messages. How can things work for you when Home Assistant starts, that should have the same issue as enabling or disabling an entity.

@kzajac83
Copy link
Author

kzajac83 commented Nov 5, 2024

@emontnemery Your explanation confirm my suspicions that enabling disabled entice launch starting HA functions.

To check your words I made a few tests and enable some disabled entice (with and without retained or availability) and cause the same effect. After the operation affected was only entices without retention flag.

it's a bit unclear to me if your concern is non-retained discovery messages, non-retained state messages or both.

I think about both.
I use "non-retained discovery messages" sending once (after HA start).
Regarding "non-retained state messages" then I also not used them when sending msgs every 3 min but until now I was not thinking what is difference when use retained flag for discovery msg and state msg? May I take this opportunity to ask for an explanation?

[...] How can things work for you when Home Assistant starts, that should have the same issue as enabling or disabling an entity.

I send notification to my external system when HA start and the system trigger MQTT discovery messages.

But please not focusing on my system, I can easy add retained flag or try build availability msg but creating the issue I'd like focus on Home Assistance system and described problem. From my perspective why touching something in one place (enabling one entice) have impact for all other entices in whole system? Creating the issue my intention was shown that HA have a problem, I was not thinking about enhancement my discovery messages or state messages or my external system because I can do that and soon will do. I also understood that enabling or disabling entices is very rare one-time action comparing to long time operational status.

Moreover MQTT discovery messages for disabled entices has been also send with option enabled_by_default = false but in "MQTT Info" popup window you don't see it. This is not clear behavior for me but I won't pursue this thread.

So summary - I'd like only tell you that from user point, like me, current behavior of system is not perfect and for sure is no logical, in my opinion enabling entice should have impact only for this one entice, not all rest.

Nor would I have created an issue if it had been described in the documentation.

@emontnemery
Copy link
Contributor

OK, I see.

I think this is mostly a documentation problem then, the documentation should explain that external sources which provide Home Assistant entities via MQTT need to listen to the home assistant birth messageand re-publish when that's received.

I send notification to my external system when HA start and the system trigger MQTT discovery messages.

This is not reliable, you should instead make your external system listen to the birth topic (unless configured differently, online published on topic homeassistant).

@kzajac83
Copy link
Author

kzajac83 commented Nov 6, 2024

Yes, general agree.
Additional propose that documentation should also mention about impact enabling any disabled entity on all working entities w/o retained flag whether there are standalone or assign to device.

On end I'd like quickly touch below points because was addressee in discussion but not answer word about it.

  1. I ask but question lost, this is still not cleat for me: what is difference between set retained flag to discovery msg and state msg?
  2. As alternative to update documentation but need assign more effort is found root of cause why enabling disabled entity impact for all others, should only for this one particular entity. From my perspective this is a bug but not force pressure, just kindly suggest.
  3. Also not clear for me is why in "MQTT Info" in MQTT device web page is not displaying discovery msg for disabled entities?

And new question (related to 3.)
4. Is possible check subscribed topic and payload for standalone entity?

@jbouwh
Copy link
Contributor

jbouwh commented Nov 14, 2024

  1. I ask but question lost, this is still not cleat for me: what is difference between set retained flag to discovery msg and state msg?

On a discovery message a retained flag will ensure the mqtt broker replays the last message when MQTT starts up, so it will set up without the need to receive a device config from the device. Else the entity will be unavailable until a discovery message is sent by the device, for example after receiving the birth message, or send in intervals.
A retained state message will set the state to the last known state when the entity loads. When the entity loads it will subscribve to the state topic, and if a retained value is at the broker, it will be replayed and set the state. Else the state will be unknown till the device sends an update.

2. As alternative to update documentation but need assign more effort is found root of cause why enabling disabled entity impact for all others, should only for this one particular entity. From my perspective this is a bug but not force pressure, just kindly suggest.

A disabled entity will not be loaded until it is enabled. To be able to debug, you must not disable the entity at startup. When you enable an entity, Home Assistant will reload the MQTT config entry. I will make sure the documentation is improved at this point.

3. Also not clear for me is why in "MQTT Info" in MQTT device web page is not displaying discovery msg for disabled entities?

This is because the MQTT info only is initialized when the entity is added, but note that you can also enable mqtt debug logging to detect any issues. Because mqtt info is stored by reference of entity_id, it cannot be initialized till the entity is loaded.

And new question (related to 3.) 4. Is possible check subscribed topic and payload for standalone entity?

You can check the mqtt debug logging.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants