Duplicate values written to InfluxDB

I have noticed that Home Assistant is writing all of my events to the InfluxDB twice (ie: duplicating every value). They are offset very slightly (ms apart), hence influx is not de-duplicating them.

I have even looked at a traffic dump (details below) and can confirm that it’s setting up 2x TCP connections, and posting the data twice.

Most of my sensors are over MQTT, and I’ve included a few relevant log lines below. This appears to be happening for all my sensors, I’m just focusing on one below to minimize noise.

I have tried updating to the latest Home Assistant (which obviously also restarts it), creating a new Influx DB and then writing to that (still the same thing in the new DB). My configuration for influx is very simple, ie:

influxdb:
    host: core.sf

That’s it, all writing to the default DB, and no authentication etc.

Best I can tell I have no other InfluxDB configuration (plus I would have thought changing the DB name in the config here would have caught that, but it was still getting written twice to the new DB).

This is the query and output showing the nearly (within a fraction of a second) duplicate entries:

curl "http://core.sf:8086/query?db=home_assistant&q=SELECT%20%22value%22%20FROM%20%22%C2%B0C%22%20WHERE%20(%22entity_id%22%20%3D%20'server_room_temperature')%20AND%20time%20%3E%3D%20now()%20-%201m" | json_pp
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   179    0   179    0     0   3140      0 --:--:-- --:--:-- --:--:--  3140
{
   "results" : [
      {
         "statement_id" : 0,
         "series" : [
            {
               "columns" : [
                  "time",
                  "value"
               ],
               "values" : [
                  [
                     "2020-04-15T01:35:19.912827904Z",
                     31.22
                  ],
                  [
                     "2020-04-15T01:35:19.912833024Z",
                     31.22
                  ]
               ],
               "name" : "°C"
            }
         ]
      }
   ]
}

The MQTT events that were sent for the temperature sensor:

[2020-04-15 11:34:19.889856] INFO: MQTT: homie/server-room/temperature/degrees	31.42
[2020-04-15 11:35:19.911679] INFO: MQTT: homie/server-room/temperature/degrees	31.22

(Showing the minute before for completeness, but with all the other noise removed)

The relevant debug logs from HASS:

2020-04-15 11:35:19 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on homie/server-room/temperature/degrees: b'31.22'
2020-04-15 11:35:19 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: entity_id=sensor.server_room_temperature, old_state=<state sensor.server_room_temperature=31.42; unit_of_measurement=°C, friendly_name=Server Room Temperature, icon=mdi:thermometer @ 2020-04-15T11:34:19.891698+10:00>, new_state=<state sensor.server_room_temperature=31.22; unit_of_measurement=°C, friendly_name=Server Room Temperature, icon=mdi:thermometer @ 2020-04-15T11:35:19.912792+10:00>>
2020-04-15 11:35:19 DEBUG (MainThread) [homeassistant.components.websocket_api.http.connection.139935041355920] Sending {'id': 74, 'type': 'event', 'event': {'event_type': 'state_changed', 'data': {'entity_id': 'sensor.server_room_temperature', 'old_state': <state sensor.server_room_temperature=31.42; unit_of_measurement=°C, friendly_name=Server Room Temperature, icon=mdi:thermometer @ 2020-04-15T11:34:19.891698+10:00>, 'new_state': <state sensor.server_room_temperature=31.22; unit_of_measurement=°C, friendly_name=Server Room Temperature, icon=mdi:thermometer @ 2020-04-15T11:35:19.912792+10:00>}, 'origin': 'LOCAL', 'time_fired': datetime.datetime(2020, 4, 15, 1, 35, 19, 912828, tzinfo=<UTC>), 'context': {'id': '44986d6954794b91b39babd106d16e29', 'parent_id': None, 'user_id': None}}}
2020-04-15 11:35:19 DEBUG (MainThread) [homeassistant.components.websocket_api.http.connection.139935246701072] Sending {'id': 2, 'type': 'event', 'event': <Event state_changed[L]: entity_id=sensor.server_room_temperature, old_state=<state sensor.server_room_temperature=31.42; unit_of_measurement=°C, friendly_name=Server Room Temperature, icon=mdi:thermometer @ 2020-04-15T11:34:19.891698+10:00>, new_state=<state sensor.server_room_temperature=31.22; unit_of_measurement=°C, friendly_name=Server Room Temperature, icon=mdi:thermometer @ 2020-04-15T11:35:19.912792+10:00>>}
2020-04-15 11:35:19 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on homie/server-room/temperature/humidity: b'49.78'
2020-04-15 11:35:19 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: entity_id=sensor.server_room_humidity, old_state=<state sensor.server_room_humidity=49.44; unit_of_measurement=%, friendly_name=Server Room Humidity, icon=mdi:water @ 2020-04-15T11:34:19.910935+10:00>, new_state=<state sensor.server_room_humidity=49.78; unit_of_measurement=%, friendly_name=Server Room Humidity, icon=mdi:water @ 2020-04-15T11:35:19.978488+10:00>>
2020-04-15 11:35:19 DEBUG (MainThread) [homeassistant.components.websocket_api.http.connection.139935041355920] Sending {'id': 74, 'type': 'event', 'event': {'event_type': 'state_changed', 'data': {'entity_id': 'sensor.server_room_humidity', 'old_state': <state sensor.server_room_humidity=49.44; unit_of_measurement=%, friendly_name=Server Room Humidity, icon=mdi:water @ 2020-04-15T11:34:19.910935+10:00>, 'new_state': <state sensor.server_room_humidity=49.78; unit_of_measurement=%, friendly_name=Server Room Humidity, icon=mdi:water @ 2020-04-15T11:35:19.978488+10:00>}, 'origin': 'LOCAL', 'time_fired': datetime.datetime(2020, 4, 15, 1, 35, 19, 978542, tzinfo=<UTC>), 'context': {'id': '3d338d5996044a87b77990c1a51f70b3', 'parent_id': None, 'user_id': None}}}
2020-04-15 11:35:19 DEBUG (MainThread) [homeassistant.components.websocket_api.http.connection.139935246701072] Sending {'id': 2, 'type': 'event', 'event': <Event state_changed[L]: entity_id=sensor.server_room_humidity, old_state=<state sensor.server_room_humidity=49.44; unit_of_measurement=%, friendly_name=Server Room Humidity, icon=mdi:water @ 2020-04-15T11:34:19.910935+10:00>, new_state=<state sensor.server_room_humidity=49.78; unit_of_measurement=%, friendly_name=Server Room Humidity, icon=mdi:water @ 2020-04-15T11:35:19.978488+10:00>>}

Looking at those logs I see its firing 2x websocket connections, but I am running app daemon and have the web browser open. When I close the browser, there is only one web socket event fired (as expected I think).

Finally, the (decoded) TCP stream for traffic going to influx from HASS:

POST /write?db=home_assistant HTTP/1.1
Host: core.sf:8086
User-Agent: python-requests/2.23.0
Accept-Encoding: gzip, deflate
Accept: text/plain
Connection: keep-alive
Content-Type: application/octet-stream
Content-Length: 296
Authorization: Basic cm9vdDpyb290

..C,domain=sensor,entity_id=server_room_temperature friendly_name_str="Server Room Temperature",icon_str="mdi:thermometer",value=31.42 1586914459891752960
%,domain=sensor,entity_id=server_room_humidity friendly_name_str="Server Room Humidity",icon_str="mdi:water",value=49.44 1586914459910949888
HTTP/1.1 204 No Content
Content-Type: application/json
Request-Id: 3ad2d245-7eb9-11ea-a92e-0242ac130009
X-Influxdb-Build: OSS
X-Influxdb-Version: 1.7.10
X-Request-Id: 3ad2d245-7eb9-11ea-a92e-0242ac130009
Date: Wed, 15 Apr 2020 01:34:21 GMT

And on another TCP stream (date stamp happened to be slightly different to show the 2x posts):

POST /write?db=home_assistant HTTP/1.1
Host: core.sf:8086
User-Agent: python-requests/2.23.0
Accept-Encoding: gzip, deflate
Accept: text/plain
Connection: keep-alive
Content-Type: application/octet-stream
Content-Length: 296
Authorization: Basic cm9vdDpyb290

..C,domain=sensor,entity_id=server_room_temperature friendly_name_str="Server Room Temperature",icon_str="mdi:thermometer",value=31.42 1586914459891737088
%,domain=sensor,entity_id=server_room_humidity friendly_name_str="Server Room Humidity",icon_str="mdi:water",value=49.44 1586914459911021824
HTTP/1.1 204 No Content
Content-Type: application/json
Request-Id: 3ad2d33f-7eb9-11ea-a92f-0242ac130009
X-Influxdb-Build: OSS
X-Influxdb-Version: 1.7.10
X-Request-Id: 3ad2d33f-7eb9-11ea-a92f-0242ac130009
Date: Wed, 15 Apr 2020 01:34:20 GMT

Hopefully that’s all the information anyone may need to help point me in the right direction. I currently stumped as to what it could be - but best I can tell it’s some sort of bug in one of the modules (but not sure which one, however influx is looking most likely to me.) If there is anything else I can do, please let me know (eg: can I turn on more debugging in the Influx module?)

Cheers!