Split-Single-Phase-Energy-Meter icon indicating copy to clipboard operation
Split-Single-Phase-Energy-Meter copied to clipboard

FR: Adjust Publish Rate for MQTT

Open politekcmo opened this issue 5 years ago • 3 comments

It would be fantastic if there was a way to adjust how frequently the ESP publishes to MQTT from the device itself. It's quite fast right now, and that is definitely desirable but I would love to adjust it down for applications that have less bandwidth available.

politekcmo avatar Dec 20 '19 21:12 politekcmo

In my testing this works right, but I believe this is a solid way to allow for a customizable delay. Would you mind looking it over? https://github.com/politekcmo/Split-Single-Phase-Energy-Meter

politekcmo avatar Jan 18 '20 21:01 politekcmo

Adding an actual delay would block other functions from running. A better way to do it would be to compare a publish delay (or publish every x seconds) against millis.

Also, the MQTT library has been changed in the latest version to add one that uses async (so it doesn't block other things from running).

CircuitSetup avatar May 27 '20 19:05 CircuitSetup

If you are using ESPhome it's simple to include this near the top of the YAML in the substitutions section

update_time: 10s

Then add the following for each sensor under each "- platform:" section update_interval: ${update_time}

Then all you have to do is change the reporting time to how often you want it to happen. Shouldn't matter if you are using MQTT or the HomeAssistant/ESPhome API's You can also hard set the "update_interval:" on each section individually and disregard the "update_time" setting altogether.

https://github.com/nightshade00013/ESPHome_EnergyMonitor/blob/master/NightShade4chan32.yaml

nightshade00013 avatar Sep 24 '22 23:09 nightshade00013