I know this is most likely a simple and extremely noobie type question but after hours of reading different threads and Google’ing the heck out of this I can’t seem to get it sorted out.
What I’m trying to do, create a single automation to notify me when Home Assistant services are shutdown or startup.
Right now I have this;
- id: '1683137743046'
alias: Notify (T+S) - Home Assistant Shutdown
description: Telegram and SMTP notification of Home Assistant status
trigger:
- platform: homeassistant
event: shutdown
condition: []
action:
- service: telegram_bot.send_message
data:
message: '⚠️ Home Assistant Services: shutdown ⚠️'
mode: single
- id: '1683141972262'
alias: Notify (T+S) - Home Assistant Startup
description: Telegram and SMTP notification of Home Assistant status
trigger:
- platform: homeassistant
event: start
condition: []
action:
- service: telegram_bot.send_message
data:
message: '✅ Home Assistant Services: started ✅'
mode: single
And this works perfectly fine… However, as I develop my skill and learn more what I want is something like this;
- id: '1683137743046'
alias: Notify (T+S) - Home Assistant Service Status
description: Telegram and SMTP notification of Home Assistant status
trigger:
- platform: homeassistant
event: shutdown
- platform: homeassistant
event: startup
condition: []
action:
- service: telegram_bot.send_message
data:
message: '⚠️ Home Assistant Services: {{ trigger.event }}⚠️'
mode: single
The above just sends a message – Home Assistant Services:
So I can’t get the variables to work. In this case, the event that was triggered.
When testing this and click ‘Run’ from the Automation, since there is no actual event that happened or state being changed the “trigger.event” is blank.
DUH!
So once you actually restart Home Assistant services, I get the right notifications.
Sometimes you just have type it all out to figure it out.
An automation’s Run command only executes the automation’s actions, therefore the trigger object is undefined. Any references within actions to the trigger object will fail.
Similarly, if one defines any Trigger Variables, they’ll also be undefined if you attempt to test the automation using Run.