What triggered this?

Here’s an example of an automation that can be triggered by either one of two input_booleans or time. It records to the logbook whichever trigger activated the automation.

- alias: 'My Automation'
  trigger:
  - platform: state
    entity_id: input_boolean.flipper, input_boolean.toggler
  - platform: time
    at: '16:34:00'
  action:
  - service: logbook.log
    data_template:
      name: "My Automation"
      message: "Triggered by {{'time' if trigger.now is defined else trigger.to_state.entity_id }}" 

As per Petro’s comment, you have to be careful with how you handle the trigger object. For example, if time triggered the automation, trigger.now will be defined but trigger.to_state will not. In contrast, if one of the input_booleans triggered it, then trigger.to_state will be defined but trigger.now will not.

The result of triggering the automation looks like this:

Screenshot%20from%202019-05-03%2016-34-38

It’s kind of interesting that the “Triggered by time” message appears before the system-generated “Time changed to 16:34”. Nevertheless, it’s clear from the log what was responsible for triggering “My Automation”.

4 Likes