esphome / issues

Issue Tracker for ESPHome
https://esphome.io/
290 stars 36 forks source link

mqtt_subscribe sensor not obeying expire_after #5426

Closed Mastiffen closed 9 months ago

Mastiffen commented 9 months ago

The problem

I have this code I want to use in my boat to receive trim state from my outboard motor from Node-RED (originating from NMEA2000). It's important that the number does not "live" too long, because if I turn off the ignition the engine interface that sends NMEA2000 is turned off, and any changes, like trimming/tilting the engine to the top, will not be read. It will still show as being where it was when I turned off the ignition. I am using the trim state (100-0, if I remember correctly) as a condition in a template switch that controls the jackplate on the boat.

  - platform: mqtt_subscribe
    name: "Trimsensor"
    id: trimsensor
    topic: madmax/trim
    expire_after: 10s

But the sensor does not expire in the webserver GUI or in the ESP internally, it is read as the last value until I do a reboot of the ESP.

This may of course be me misunderstanding the workings of this sensor, but expire_after is obviously a valid option, because when I tried set_expire_after I got this:

[set_expire_after] is an invalid option for [sensor.mqtt_subscribe]. Did you mean [expire_after]?

Which version of ESPHome has the issue?

2023.12.9

What type of installation are you using?

pip

Which version of Home Assistant has the issue?

No response

What platform are you using?

ESP32

Board

esp32-VROOM-32D

Component causing the issue

mqtt_subscribe sensor

Example YAML snippet

No response

Anything in the logs that might be useful for us?

No response

Additional information

No response

ssieb commented 9 months ago

That's part of the outgoing mqtt parameters. It's not specific to the subscribe. If you want to "expire" a sensor, you can use the timeout: filter.