1 post / 0 new
jamessimpson007
MQTT data spikes in Home Assistant

Dear clever people,

I’m hoping someone can point me in the right direction. I have OVMS with v3 server sending metrics via MQTT to my Home Assistant Mosquito add-on. I have it going via HiveMQ as that was the easiest way I could get it to integrate securely and use it whilst away from my home WiFi, using LTE. So I have 2 brokers (locally hosted mosquito and HiveMQ cloud), with a bridge between them. It’s all working well but I have ongoing issues with occasional gaps in data, presumably caused by transient availability issues, which then result in transient data spikes to what is presumably a retained MQTT message as the y-axis values of the spikes are usually identical. The OVMS module doesn’t give me any configuration options, but seems to send QOS 0 messages (looking at MQTT explorer and HiveMQ). I have the home assistant sensors set up manually using yaml.

These spikes cause problems further down the line with automations/calculations etc. If I publish a blank message to the relevant topic (using MQTT explorer) to “clear” the retained message it sorts things out for a while but then recurs. I’ve scoured the documentation and forums and experimented with all sorts of templates and availability settings. The only thing I’ve found that often works to "clean" the data is to set up a second trigger template sensor which only triggers to and from numerical states. It mostly works but isn’t very elegant and seems like using a sledge hammer to crack a nut. Can anyone recommend a simpler approach I could use within my MQTT yaml to filter these states out please?

here is one of my MQTT sensors:

  - name: MG ZS SoC MQTT
    unique_id: mg_zs_soc_mqtt
    state_topic: ovms/xxxx/xxxx/metric/v/b/soc
    unit_of_measurement: "%"
    device_class: battery

 

here is a typical example, with spikes to the same value, presumably a retained message which follows a brief period of unavailability. 

 

Am I missing something obvious to get cleaner data within HA?

Thanks

randomness