A way to show in front end that (which) automation has triggered?

and maybe also that condition has been met, or not, and action executed (or not).

Could be very handy for debugging, and sometimes just to know what is HASS doing in your home :slight_smile:

Any suggestions on how to achieve this? Create a notification for each action (where, persistent?)

Or?

I would use from time to time to check it, not few times I wonder if an automation has done the ACTION or not, and is not easy to tell (well, so far I didn’t find an easy way…)

Yes, I use this automation:

- alias: Automation ran
  id: 'Automation ran'
  initial_state: 'off'
  trigger:
    platform: event
    event_type: state_changed
  condition:
    condition: template
    value_template: >
      {% set skip_list = ['automation_ran', 'count_warnings', 'count_errors',
                           'activate_map_sensors_actueel', 'call_family_home',
                           'timed_python_scripts_per_20_secs'] %}
      {{ trigger.event.data.entity_id.startswith('automation.') and
         trigger.event.data.entity_id.split('.')[1] not in skip_list and
         'old_state' in trigger.event.data and 'new_state' in trigger.event.data }}
  action:
    - condition: template
      value_template: >
        {{ trigger.event.data.new_state.attributes.last_triggered !=
           trigger.event.data.old_state.attributes.last_triggered }}
    - service: notify.filed_automations
      data_template:
        message: >
         {{ as_timestamp(trigger.event.data.new_state.last_updated)|timestamp_custom("%d %b: %X") }}: {{ trigger.event.data.new_state.name }}
    - service: python_script.last_automation
      data_template:
        event: '{{ trigger.event }}'

with this python script:

last_automation.py

# Get params
event = data.get('event')
#logger.error("LAST AUTOMATION: " + str(event))
# Sample: <Event call_service[L]: domain=automation, service=trigger, service_data=entity_id=automation.call_service_event_automation, service_call_id=1972124944-486>

# Find the automation name
#** pos_start = event.find('entity_id=')+10
pos_start = event.find('entity_id=')+21
pos_end = event.find(',', pos_start)

# Get the entity_id
#** entity_id = event[pos_start:pos_end]
entity_id = 'automation.' + event[pos_start:pos_end]

# get the state object
state = hass.states.get(entity_id)

# Make a time string in 24 hour format
#time_string = datetime.datetime.now().strftime('%I:%M')
dt = datetime.datetime.now() #state.attributes.get('last_triggered') #
time = "%02d:%02d:%02d" % (dt.hour, dt.minute, dt.second)
# try to get the automation friendly name
msg = []

try:
    msg = state.name
except:
    msg = None

if msg:
   if not msg.startswith('Set '):
       # Sensor update
       hass.states.set('sensor.last_automation', msg, {
#            'custom_ui_state_card': 'state-card-value_only',
#            'text': sensor_message,
            'unit_of_measurement': 'Aut',
            'friendly_name': time,
            'entity_picture': '/local/buttons/play-mode-repeat.png' })

then use the sensor sensor.last_automaton in frontend.

beware, if automation heavy, it can be a burden to the system. so you might want to comment out several automations in the skip list as I did.

I use this in my Home dashboard card, and have the automation there to en/disable on demand:

2 Likes

Wow thanks lot of good ideas

forgot to mention you need to add this sensor for the service filed_automations:

  - platform: file
    file_path: /config/filed_automations.txt
    name: Filed automations

which is a cool way of logging all ran automations.

Yes, Wow.
This looks like being really useful…

what is this? Do I need to change it in my configuration?

Sorry I know nothing about python

its commented out. everything after the # is not used in the script. It was used for testing purposes to find the correct syntax ea. You can even take it out

I got an error, so I changed to the below, and got also an error

2018-11-11 13:13:38 ERROR (MainThread) [homeassistant.config] Invalid config for [sensor.file]: not a file for dictionary value @ data['file_path']. Got '/local/filed_automations.txt'. (See ?, line ?). Please check the docs at https://home-assistant.io/components/sensor.file/

maybe do I need to create an empty file first?

  - platform: file
    file_path: /local/filed_automations.txt
    name: Filed automations

Can you share your configuration?