MQTT Sensors not logging data to InfluxDB?

I have a custom device that is publishing a bunch of sensor data via MQTT discovery. I’m seeing the structure of the data in InfluxDB (entity names are in the right measurements) but no data. For example the following query returns no data:

SELECT mean("value") AS "mean_value"
FROM "homeassistant"."autogen"."%"
WHERE time > :dashboardTime: AND time < :upperDashboardTime:
AND "entity_id"='little_free_library_battery_soc'
GROUP BY time(:interval:), "entity_id"
FILL(null)

Is there something extra that needs done in either the MQTT sensor config or in the Influx config to get these logging? Maybe related is that the History view in HA does show/retain data for the sensors but there is nothing in the Logbook.

MQTT Discovery Config: homeassistant/sensor/little_free_library/battery_soc/config

{
  "device": {
    "name": "Little Free Library",
    "model": "photon",
    "manufacturer": "edalquist",
    "identifiers": [
      "library_monitor-E",
      "2b002000XXXXXXXXXXXXXX"
    ]
  },
  "name": "Little Free Library Battery %",
  "unique_id": "library_monitor-E_battery_soc",
  "device_class": "battery",
  "unit_of_measurement": "%",
  "state_topic": "particle/ha/little_free_library/battery",
  "value_template": "{{ value_json.soc }}",
  "expire_after": 14400
}

MQTT State: particle/ha/little_free_library/battery

{
  "voltage": 4.171500015,
  "soc": 97.5,
  "alert": "OFF",
  "charging": "ON"
}

HA Entity Name: sensor.little_free_library_battery_soc

This is on:

  • HA: 2020.12.2
  • Influx Addon: 3.7.9

Well I figured it out though I’m not really sure why.

The MQTT discovery documents need to have the force_update attribute set. That attribute is documented as:
Sends update events even if the value hasn’t changed. Useful if you want to have meaningful value graphs in history.

It isn’t clear exactly why this is needed to get InfluxDB logging but it works now.