MQTT: Record timestamp of event

Tags: #<Tag:0x00007f326d5db528> #<Tag:0x00007f326d5db3c0> #<Tag:0x00007f326d5db2a8> #<Tag:0x00007f326d5db168>


If you want to record timestamps of different events you need to create several automations that generate MQTT messages and post them to corresponding topics of your choice.

For instance, you may want to record last timestamp the motion was detected, door or window opened or closed a button pressed, or a water leak or smoke detector triggers.

The blueprint below helps to simplify creation of such automations.

Import blueprint from here


Required inputs

The required inputs are Topic and Trigger Entity


Specify here the MQTT root topic you want to publish generated event messages, for example event/last_triggered. Note that you can use slashes ‘/’ to specify a path. You should not put ‘/’ at the end of the path.
The full path of MQTT topic will be constructed based on the template below:


Trigger entity id here will be without a domain.

Trigger Entity

The entity you want to monitor. Once the state of this entity changes a new MQTT message will be published to specified topic.

Optional inputs

Trigger Entity State

If omitted, any state change of Trigger Entity will generate a message. If you want to record only specific states, use Trigger Entity State for this. For instance, to record timestamps of only single button presses, specify button entity at Trigger Entity and single in this input. Similarly, if you want to record motion detected (not ‘no motion’) events, specify your motion sensor at Trigger Entity and on state here.
The default is none which means ‘any state change’.


Set this to false if you do not want MQTT to retain this message. true is the default value.

Enabling Entity

Use Enabling Entity to make the automation to trigger based on entity’s state (see below)

Enabling entity state

The automation will trigger only if Enabling Entity is present and it is in specified state.

Example automation

The automation below will publish MQTT message for all motion sensor detected motions

    - id: "test_mqtt"
      alias: Test MQTT
      description: ''
        path: yuri-vashchenko/mqtt_record_event_timestamp.yaml
          topic: 'events/last_motion'
          trigger_entity: binary_sensor.motion
          trigger_entity_state: 'on'