Set input date time at shutdown

Hi,

I am trying to set the time when Home Assistant is shutdown. The idea is to register this time under an input date time helper.

I created the following automation

alias: HA shutdown time
description: Shutdown time
trigger:
  - platform: homeassistant
    event: shutdown
condition: []
action:
  - service: input_datetime.set_datetime
    data:
      time: "{{ now().strftime('%H:%M:%S') }}"
    target:
      entity_id: input_datetime.ha_shutdown_time
mode: single

If I test the automation under UI … it sets the time in the input date time helper.

But If I shutdown or restart HA supervisor … there is no new time set under the input date time helper once the HA is restarted.

Is there something wrong in the automation or am I missing something else?

It appears that the shutdown event occurs so close to Home Assistant shutting down that some kinds of actions cannot be successfully executed.

1 Like

Yes, It looks like the service was closed before the automation started. The weird thing is that this automation was created using the UI, not directly at YAML. You can select as trigger when HA is shutdown and then as action you can select the service input_datetime.set_datetime.

So … do you know what type of services can be setup as action once HA shutdown has been triggered?

The Automation Editor allows you to compose whatever you want. It only ensures the syntax is correct, nothing else (i.e. it doesn’t check for logic errors which means it doesn’t confirm your choices of triggers, conditions and actions is logically correct).

Based on the posted Github Issue, it appears no one yet knows the answer to that question.