Teslamate slowing down Home Assistant automations

I have Teslamate running in docker on a Mac mini, and Home Assistant running on a Pi 4. Recently, I noticed that whenever anyone was driving the car, my automations would show a huge lag between trigger and action. Most of them are in Node Red, and I noticed for example that after one would trigger, the call service node to say, turn on a light, would stay yellow for a long time, before finally turning green and the light would turn on. Normally, it would be instantaneous.

I tried to troubleshoot a bit and installed the systemmonitor integration. I could clearly see every time I would drive, the processor on the Pi would shoot up to well above 50% and stay there for the duration of the drive, with occasional peaks going up even higher. Normally, I run at about 10%. If I wasn’t the one driving and I was at home, I would be able to verify that all the automations would start to run slowly.

Some more investigation showed that neither Mosquitto nor Node Red appeared to be the ones using the processor, so it must have been something within Home Assistant. I set up a simple counter to see how often the Teslamate entities were being updated during a drive, and I was surprised to see that they were updating thousands of times during a 20 minute errand run. Which makes sense if you think about it I guess, given that things like speed, latitude, power, etc is constantly changing while you’re driving.

I have had this set up for over a year, and I never noticed it before. However, since I’m usually the one driving this car, I would not have noticed any slowdown at home. So I’m not sure if it’s always been there,

I fixed the problem by moving the entities that seem to change the most (e.g., odometer, speed, power, etc) out of the mqtt.yaml file and making an automation I Node Red which throttles the update of the home assistant entities to something more reasonable, one every minute or even slower for some of them. If others are seeing this problem, and are interested, I’d be happy to post more details about the process.

Very old post but I’d certainly be interested in seeing what you have done if thats still possible? I am seeing similar and was about to start writing something myself but as the main driver I don’t often get the chance to see what’s happening in home assistant but can certainly see the location etc in home assistant can get quite behind.

Are you familiar with Node-Red? If so, I can post the flows that I created to take care of this. But in a nutshell, I set up flows for each variable that teslamate defines to limit the update rate. Most of them get updated about once every 20 seconds now. The way I did it was to define an input_number variable. Let’s use power as an example. I then use an MQTT node in node red that subscribes to the topic “teslamate/cars/1/power”. I feed the output to a rate limiter node (that is set to drop intermediate messages)and then to a call-service node that sets that output to the input_number.tesla_power entity that I had previously defined in yaml or helper. I then have a template entity in yaml that uses
value_template: “{{ states(‘input_number.tesla_power’) | round(0) }}”
as a template.
It’s pretty straightforward, and you can set the update rate differently for each variable of interest.

Sorry I should have mentioned, yes I am familiar with Node Red, thanks for the explanation of the flows, that makes sense. I wasn’t sure where you were interrupting the communications. I’ll have a go and see if I can make something work.

Here is the flow I tried to describe:

[{“id”:“b7b6f4228c320889”,“type”:“subflow”,“name”:“Delay/Throttle”,“info”:“”,“category”:“”,“in”:[{“x”:120,“y”:200,“wires”:[{“id”:“621634dbfbf9d8d7”}]}],“out”:[{“x”:640,“y”:200,“wires”:[{“id”:“e39b84dd51d14c64”,“port”:0}]}],“env”:[{“name”:“Delay”,“type”:“str”,“value”:“”},{“name”:“Rate”,“type”:“str”,“value”:“”}],“meta”:{},“color”:“#DDAA99”},{“id”:“e39b84dd51d14c64”,“type”:“delay”,“z”:“b7b6f4228c320889”,“name”:“Rate Limit”,“pauseType”:“rate”,“timeout”:“5”,“timeoutUnits”:“seconds”,“rate”:“1”,“nbRateUnits”:“20”,“rateUnits”:“second”,“randomFirst”:“1”,“randomLast”:“5”,“randomUnits”:“seconds”,“drop”:true,“allowrate”:true,“outputs”:1,“x”:500,“y”:200,“wires”:[]},{“id”:“331dd9c41a4ebdeb”,“type”:“delay”,“z”:“b7b6f4228c320889”,“name”:“Delay”,“pauseType”:“delayv”,“timeout”:“1”,“timeoutUnits”:“seconds”,“rate”:“1”,“nbRateUnits”:“1”,“rateUnits”:“second”,“randomFirst”:“1”,“randomLast”:“5”,“randomUnits”:“seconds”,“drop”:false,“allowrate”:false,“outputs”:1,“x”:370,“y”:200,“wires”:[[“e39b84dd51d14c64”]]},{“id”:“621634dbfbf9d8d7”,“type”:“change”,“z”:“b7b6f4228c320889”,“name”:“Set msg”,“rules”:[{“t”:“set”,“p”:“delay”,“pt”:“msg”,“to”:“Delay”,“tot”:“env”},{“t”:“set”,“p”:“rate”,“pt”:“msg”,“to”:“Rate”,“tot”:“env”}],“action”:“”,“property”:“”,“from”:“”,“to”:“”,“reg”:false,“x”:240,“y”:200,“wires”:[[“331dd9c41a4ebdeb”]]},{“id”:“5ad590ee0d727352”,“type”:“mqtt in”,“z”:“4c07c660.e07768”,“g”:“275bf10b4a76f786”,“name”:“Power”,“topic”:“teslamate/cars/1/power”,“qos”:“2”,“datatype”:“auto-detect”,“broker”:“108f336c9b4f6dba”,“nl”:false,“rap”:true,“rh”:0,“inputs”:0,“x”:4530,“y”:1780,“wires”:[[“65618968b8dd25e3”]]},{“id”:“65618968b8dd25e3”,“type”:“subflow:b7b6f4228c320889”,“z”:“4c07c660.e07768”,“g”:“275bf10b4a76f786”,“name”:“1s/60s”,“env”:[{“name”:“Delay”,“value”:“1000”,“type”:“str”},{“name”:“Rate”,“value”:“60000”,“type”:“str”}],“x”:4650,“y”:1780,“wires”:[[“fb757f5eb5c716c0”]]},{“id”:“fb757f5eb5c716c0”,“type”:“api-call-service”,“z”:“4c07c660.e07768”,“g”:“275bf10b4a76f786”,“name”:“Set Power”,“server”:“38c68cbe.2f0d04”,“version”:5,“debugenabled”:false,“domain”:“input_number”,“service”:“set_value”,“areaId”:,“deviceId”:,“entityId”:[“input_number.tesla_power”],“data”:“{"value": payload}”,“dataType”:“jsonata”,“mergeContext”:“”,“mustacheAltTags”:false,“outputProperties”:,“queue”:“none”,“x”:4790,“y”:1780,“wires”:[]},{“id”:“108f336c9b4f6dba”,“type”:“mqtt-broker”,“name”:“MQTT”,“broker”:“192.168.86.46”,“port”:“1883”,“clientid”:“”,“autoConnect”:true,“usetls”:false,“protocolVersion”:“4”,“keepalive”:“60”,“cleansession”:true,“birthTopic”:“”,“birthQos”:“0”,“birthPayload”:“”,“birthMsg”:{},“closeTopic”:“”,“closeQos”:“0”,“closePayload”:“”,“closeMsg”:{},“willTopic”:“”,“willQos”:“0”,“willPayload”:“”,“willMsg”:{},“userProps”:“”,“sessionExpiry”:“”},{“id”:“38c68cbe.2f0d04”,“type”:“server”,“name”:“Home Assistant”,“version”:5,“addon”:true,“rejectUnauthorizedCerts”:true,“ha_boolean”:“y|yes|true|on|home|open”,“connectionDelay”:false,“cacheJson”:true,“heartbeat”:false,“heartbeatInterval”:“30”,“areaSelector”:“friendlyName”,“deviceSelector”:“friendlyName”,“entitySelector”:“friendlyName”,“statusSeparator”:"at: ",“statusYear”:“hidden”,“statusMonth”:“short”,“statusDay”:“numeric”,“statusHourCycle”:“h23”,“statusTimeFormat”:“h:m”,“enableGlobalContextStore”:true}]

and this is a simple subflow I call that does a delay and a rate limit:

[{“id”:“e39b84dd51d14c64”,“type”:“delay”,“z”:“b7b6f4228c320889”,“name”:“Rate Limit”,“pauseType”:“rate”,“timeout”:“5”,“timeoutUnits”:“seconds”,“rate”:“1”,“nbRateUnits”:“20”,“rateUnits”:“second”,“randomFirst”:“1”,“randomLast”:“5”,“randomUnits”:“seconds”,“drop”:true,“allowrate”:true,“outputs”:1,“x”:500,“y”:200,“wires”:[]},{“id”:“331dd9c41a4ebdeb”,“type”:“delay”,“z”:“b7b6f4228c320889”,“name”:“Delay”,“pauseType”:“delayv”,“timeout”:“1”,“timeoutUnits”:“seconds”,“rate”:“1”,“nbRateUnits”:“1”,“rateUnits”:“second”,“randomFirst”:“1”,“randomLast”:“5”,“randomUnits”:“seconds”,“drop”:false,“allowrate”:false,“outputs”:1,“x”:370,“y”:200,“wires”:[[“e39b84dd51d14c64”]]},{“id”:“621634dbfbf9d8d7”,“type”:“change”,“z”:“b7b6f4228c320889”,“name”:“Set msg”,“rules”:[{“t”:“set”,“p”:“delay”,“pt”:“msg”,“to”:“Delay”,“tot”:“env”},{“t”:“set”,“p”:“rate”,“pt”:“msg”,“to”:“Rate”,“tot”:“env”}],“action”:“”,“property”:“”,“from”:“”,“to”:“”,“reg”:false,“x”:240,“y”:200,“wires”:[[“331dd9c41a4ebdeb”]]}]

and this is what it all looks like: