MQTT sensors suddenly stopped working [Solved]

Sorry in advance for the long post…

I’ve got a couple of Falcon Pi Players I’m using to drive my holiday shows. They can report status information via MQTT. So I set up a couple of sensors for each FPP, and they were working fine. Then we had the hurricane come through (FL), and the sign that one of them was driving got damaged.

Repaired the sign, and test all is working fine. MQTT messages are making it to the broker, and are being seen inside of HA. However, both the sensors for the sign stay in the ‘Unavailable’ status.

Again, I’ve got a 2nd FPP reporting through the same broker, and HA is seeing those updates fine.

HA Version: Home Assistant 2022.11.3

The MQTT sensor defs are:

sensor:
  #################################################################################################
  # Falcon Pi Player sensors
  # The JSON published by the FPP devices contains arrays of nested objects.  The activePlaylists
  # is an array, and contained within it is a currentItems array.  Thus far I have only seen
  # 1 item in each array, so we will go with that for now.  We will setup 2 sensors for each player
  # one for the playlist, and one for the current item in the playlist.
  # Values seen for the 'status' value thus far are: 
  #   playing
  #   stoppingGracefully
  #   idle
  #
  # From community, sensor time-updated only changes when the state of the sensor changes, NOT
  # when attribute values change.
  #################################################################################################
  - name: "FPP-Master Active Playlist"
    state_topic: "falcon/player/FPP-Master/playlist_details"
    object_id: fpp_master_active_playlist_objectid
    unique_id: fpp_master_active_playlist_uniqueid
    # status values seen thus far
    #   playing
    #   idle
    #   stoppingGracefully
    value_template: "{{ value_json.status }}"
    expire_after: 60
    availability: 
      - topic: "falcon/player/FPP-Master/playlist_details"
        value_template: "{{ value_json.status }}"
        payload_available: "playing"
      - topic: "falcon/player/FPP-Master/playlist_details"
        value_template: "{{ value_json.status }}"
        payload_available: "idle"
    json_attributes_topic: "falcon/player/FPP-Master/playlist_details"
    # json_attributes_template: "{{ value_json.activePlaylists[0] | tojson }}"
    json_attributes_template: >-
      {
      {%- if value_json.activePlaylists | length() > 0 %}
        "playlistName": "{{ value_json.activePlaylists[0].name | default('') }}",
        "description": "{{ value_json.activePlaylists[0].description | default('') }}",
        "repeat": "{{ value_json.activePlaylists[0].repeat | default('') }}"
      {%- endif %}
      }
  - name: "FPP-Master Active Playlist Item"
    state_topic: "falcon/player/FPP-Master/playlist_details"
    object_id: fpp_master_active_playlist_item_objectid
    unique_id: fpp_master_active_playlist_item_uniqueid
    value_template: "{{ value_json.status }}"
    expire_after: 60
    availability: 
      - topic: "falcon/player/FPP-Master/playlist_details"
        value_template: "{{ value_json.status }}"
        payload_available: "playing"
      - topic: "falcon/player/FPP-Master/playlist_details"
        value_template: "{{ value_json.status }}"
        payload_available: "idle"
    json_attributes_topic: "falcon/player/FPP-Master/playlist_details"
    json_attributes_template: >-
      {
      {%- if value_json.activePlaylists | length() > 0 %}
        "type": "{{ value_json.activePlaylists[0].currentItems[0].type | default('') }}",
        "playOnce": "{{ value_json.activePlaylists[0].currentItems[0].playOnce | default('') }}",
        "sequenceName": "{{ value_json.activePlaylists[0].currentItems[0].sequenceName | default('') }}",
        "mediaArtist": "{{ value_json.activePlaylists[0].currentItems[0].mediaArtist | default('') }}",
        "mediaTitle": "{{ value_json.activePlaylists[0].currentItems[0].mediaTitle | default('') }}",
        "mediaName": "{{ value_json.activePlaylists[0].currentItems[0].mediaName | default('') }}",
        "secondsElapsed": "{{ value_json.activePlaylists[0].currentItems[0].secondsElapsed | default('') }}",
        "secondsRemaining": "{{ value_json.activePlaylists[0].currentItems[0].secondsRemaining | default('') }}",
        "secondsTotal": "{{ value_json.activePlaylists[0].currentItems[0].secondsTotal | default('') }}"
      {%- endif %}
      }
  #################################################################################################
  - name: "FPP-Sign Active Playlist"
    state_topic: "falcon/player/FPP-Sign/playlist_details"
    object_id: fpp_sign_active_playlist_objectid
    unique_id: fpp_sign_active_playlist_uniqueid
    value_template: "{{ value_json.status }}"
    expire_after: 60
    availability: 
      - topic: "falcon/player/FPP-Sign/playlist_details"
        value_template: "{{ value_json.status }}"
        payload_available: "playing"
      - topic: "falcon/player/FPP-Sign/playlist_details"
        value_template: "{{ value_json.status }}"
        payload_available: "idle"
    json_attributes_topic: "falcon/player/FPP-Sign/playlist_details"
    json_attributes_template: >-
      {
      {%- if value_json.activePlaylists | length() > 0 %}
        "playlistName": "{{ value_json.activePlaylists[0].name | default('') }}",
        "description": "{{ value_json.activePlaylists[0].description | default('') }}",
        "repeat": "{{ value_json.activePlaylists[0].repeat | default('') }}"
      {%- endif %}
      }
  - name: "FPP-Sign Active Playlist Item"
    state_topic: "falcon/player/FPP-Sign/playlist_details"
    object_id: fpp_sign_active_playlist_item_objectid
    unique_id: fpp_sign_active_playlist_item_uniqueid
    value_template: "{{ value_json.status }}"
    expire_after: 60
    availability: 
      - topic: "falcon/player/FPP-Sign/playlist_details"
        value_template: "{{ value_json.status }}"
        payload_available: "playing"
      - topic: "falcon/player/FPP-Sign/playlist_details"
        value_template: "{{ value_json.status }}"
        payload_available: "idle"
    json_attributes_topic: "falcon/player/FPP-Sign/playlist_details"
    json_attributes_template: >-
      {
      {%- if value_json.activePlaylists | length() > 0 %}
        "type": "{{ value_json.activePlaylists[0].currentItems[0].type | default('') }}",
        "playOnce": "{{ value_json.activePlaylists[0].currentItems[0].playOnce | default('') }}",
        "sequenceName": "{{ value_json.activePlaylists[0].currentItems[0].sequenceName | default('') }}",
        "mediaArtist": "{{ value_json.activePlaylists[0].currentItems[0].mediaArtist | default('') }}",
        "mediaTitle": "{{ value_json.activePlaylists[0].currentItems[0].mediaTitle | default('') }}",
        "mediaName": "{{ value_json.activePlaylists[0].currentItems[0].mediaName | default('') }}",
        "secondsElapsed": "{{ value_json.activePlaylists[0].currentItems[0].secondsElapsed | default('') }}",
        "secondsRemaining": "{{ value_json.activePlaylists[0].currentItems[0].secondsRemaining | default('') }}",
        "secondsTotal": "{{ value_json.activePlaylists[0].currentItems[0].secondsTotal | default('') }}"
      {%- endif %}
      }
  #################################################################################################
  #################################################################################################
  - name: "FPP-Master Active Playlist Item Test"
    state_topic: "falcon/player/FPP-Master/playlist_details"
    object_id: fpp_master_active_playlist_item_test_objectid
    unique_id: fpp_master_active_playlist_item_test_uniqueid
    value_template: "{{ value_json.status }}"
    expire_after: 60
    availability: 
      - topic: "falcon/player/FPP-Master/playlist_details"
        value_template: "{{ value_json.status }}"
        payload_available: "playing"
      - topic: "falcon/player/FPP-Master/playlist_details"
        value_template: "{{ value_json.status }}"
        payload_available: "idle"
    json_attributes_topic: "falcon/player/FPP-Master/playlist_details"
    json_attributes_template: >-
      {
        "playListCount": "{{ value_json.activePlaylists | length() }}"
      }

The 2 sensors for the FPP-Master are working fine, the 2 for FPP-Sign are staying as Unavailable.

Using the Listener in the MQTT integration, I see the following topic messages coming in

Message 15 received on falcon/player/FPP-Sign/playlist_details at 17:30:
{
    "activePlaylists": [
        {
            "currentItems": [
                {
                    "playOnce": 0,
                    "secondsElapsed": 562,
                    "secondsRemaining": 337,
                    "secondsTotal": 900,
                    "sequenceName": "Thanksgiving P10 Panel.fseq",
                    "type": "sequence"
                }
            ],
            "description": "",
            "name": "Thanksgiving",
            "repeat": 1
        }
    ],
    "status": "playing"
}

I set the logging for the mqtt integration to debug, and I see messages like this in the log:

2022-11-19 17:08:20.307 DEBUG (MainThread) [homeassistant.components.mqtt.models] Rendering incoming payload '{
	"activePlaylists" : 
	[
		{
			"currentItems" : 
			[
				{
					"playOnce" : 0,
					"secondsElapsed" : 107,
					"secondsRemaining" : 792,
					"secondsTotal" : 900,
					"sequenceName" : "Thanksgiving P10 Panel.fseq",
					"type" : "sequence"
				}
			],
			"description" : "",
			"name" : "Thanksgiving",
			"repeat" : 1
		}
	],
	"status" : "playing"
}
' with variables {'entity_id': 'sensor.fpp_sign_active_playlist_item_objectid', 'name': 'FPP-Sign Active Playlist Item', 'this': <template TemplateStateFromEntityId(sensor.fpp_sign_active_playlist_item_objectid)>} and Template("{ {%- if value_json.activePlaylists | length() > 0 %}
  "type": "{{ value_json.activePlaylists[0].currentItems[0].type | default('') }}",
  "playOnce": "{{ value_json.activePlaylists[0].currentItems[0].playOnce | default('') }}",
  "sequenceName": "{{ value_json.activePlaylists[0].currentItems[0].sequenceName | default('') }}",
  "mediaArtist": "{{ value_json.activePlaylists[0].currentItems[0].mediaArtist | default('') }}",
  "mediaTitle": "{{ value_json.activePlaylists[0].currentItems[0].mediaTitle | default('') }}",
  "mediaName": "{{ value_json.activePlaylists[0].currentItems[0].mediaName | default('') }}",
  "secondsElapsed": "{{ value_json.activePlaylists[0].currentItems[0].secondsElapsed | default('') }}",
  "secondsRemaining": "{{ value_json.activePlaylists[0].currentItems[0].secondsRemaining | default('') }}",
  "secondsTotal": "{{ value_json.activePlaylists[0].currentItems[0].secondsTotal | default('') }}"
{%- endif %} }")

And I’m not seeing any errors. I see the same messages in the log for the FPP-Master sensors as well, which is the one that’s working.

What other troubleshooting can I try to figure out why these sensors have stopped working, and to get them back active?

Ok, got it back to working. Looks like the issue was the availability settings on the sensors:

    availability: 
      - topic: "falcon/player/FPP-Master/playlist_details"
        value_template: "{{ value_json.status }}"
        payload_available: "playing"
      - topic: "falcon/player/FPP-Master/playlist_details"
        value_template: "{{ value_json.status }}"
        payload_available: "idle"

As soon as I commented out the 2nd entry, all the sensors became available again.
So, the MQTT topic sent by the FPP can have one of several statuses: “playing”,“idle”,“stoppingGracefully” are the ones I’ve see so far.

So, how does one create multiple availability values within the sensor definition?
The MQTT Sensor integration docs just say:

availability list (optional)
A list of MQTT topics subscribed to receive availability (online/offline) updates. Must not be used together with availability_topic.

payload_available string (optional, default: online)
The payload that represents the available state.

payload_not_available string (optional, default: offline)
The payload that represents the unavailable state.

topic string REQUIRED
An MQTT topic subscribed to receive availability (online/offline) updates.

value_template template (optional)
Defines a template to extract device’s availability from the topic. To determine the devices’s availability result of this template will be compared to payload_available and payload_not_available.

It appears I cannot put multiple entries in the list that reference the same topic. So, how can I test the payload value to be one of a list of values? Can the payload_available be a template?

Think I got it working. Put the list of potential values into the value_template:

    availability: 
      - topic: "falcon/player/FPP-Master/playlist_details"
        value_template: >
          {{ value_json.status in ["playing","idle","stoppingGracefully"] }}
        payload_available: "True"