Hello!
Lets say I have a sensor that needs some warmup time after power on before its readings will make any sense. Like MH-Z19 needs about 3 minutes.
Is there a way to add such a delay before sending MQTT messages for such sensor?
Thanks.
Hello and welcome, I’m not an MQTT specialist but I’m sure one will be along pretty soon to help you out. Good Luck
There is an update interval setting for that component.
Depending on your requirements, the easiest option would be to set
update_interval: 180s
Yes this works on power on, but I don’t want that update interval itself to be that long.
I currently managed to add delay by simply hanging the whole ESP for several minutes on every boot
esphome:
on_boot:
priority: 200
then:
- lambda: |-
delay(120000);
But this feels really ugly since the whole controller is unresponsive during this wait time.
I wonder if there are better solutions.
A bit late to the party, but I solved this by using the uptime sensor and using an if conditional. It makes for a bit more ugly YAML, but it means the background isn’t suspended.
on_boot:
priority: 200
then:
- display.page.show: page1
- component.update: small_display
sensor:
- platform: uptime
name: Uptime Sensor
id: id_uptime
#something something
- if:
condition:
lambda: 'return id(id_uptime).state > 5;'
then:
- logger.log:
format: "Screen 1!"
tag: USER
level: WARN
- display.page.show: page1
- component.update: small_display
Just wanted to say this (with a much shorter 500mS delay) seems to also have fixed all my unreliable sensor detection on a battery powered ESP8266 device that turned the sensors on/off with a GPIO to save power in deep-sleep. Similar issue, where it took more time for the voltage regulators/capacitors to stabilize enough to reliably be detected by the component initialization than it took for the ESP to boot.
Thanks!