Automation to check MQTT topic, to many triggers a prblem?

So i just had 1 Node-red flow that checked a MQTT topic (my OT ESP).
Basically when there is no value being send for 2 minutes it will switch the device off/on via a switchable socket.

Remade that in an automation but i see its getting triggered every second which should happen as the topic is send every second :sweat_smile:
Built in the 2 minutes to account for updating wifi and stuff.

My question is this: Is it bad for an automation to trigger each second the whole day long? or does HA takes these kind of things into account?

I wouldn’t do it, but it will probably work.

If you share your code someone might come up with a better idea for you though. How to help us help you - or How to ask a good question.

For instance create an MQTT sensor on that topic and trigger on the sensor. MUCH more efficient that triggering an automation 86400 times a day.

You can set an mqtt entity up to mark itself unavailable if it does not receive an update in a particular time period.

https://www.home-assistant.io/integrations/sensor.mqtt/#expire_after

It would be a lot more efficient to only trigger when the entity becomes unavailable (state trigger) due to exceeding that setting.

1 Like

Thanks, i adjusted the existing mqtt sensor to have the expire_after and works like a charm.

I already had the MQTT sensor, so adding the expire was enough.
But yeah, i agreed it seemed alot :sweat_smile:

1 Like