MQTT Binary Sensor template to ON with any change in topic

I have an MQTT topic that will only report an ON status, and never reports and OFF status. When it reports the ON status, it puts the timestamp as the value of the sensor. I can modify the format of the timestamp and/or put a static string before or after the timestamp if needed.

I’d like to make an MQTT binary sensor for this, and anytime that I see a new timestamp or value, set it to ON and then use the expire_after function of the sensor to reset the binary sensor back to off within a second.

But how can I leverage the template when it’s looking for the ON value to account for this? Basically I’m looking for any change in value with the template, but not sure if this is possible to do.

The off_delay option is what you want. Something like this:

mqtt:
  - binary_sensor:
      name: "Your Auto Off Sensor"
      state_topic: "your/topic/here"
      value_template: "{{ 'ON' if value else 'OFF' }}"
      off_delay: 42 # turns off after 42 seconds

I’m pretty sure that value template will turn on the binary sensor every time any new value is received on the topic. It will then turn off after the off_delay time. Untested though. Let us know what happens.

Awesome, thank you. That template is exactly what I am looking for!