(ref: Automation trigger variables - Home Assistant (home-assistant.io))
I’m considering passing the whole this
variable from an automation to a script. I am having trouble using it in a script though because the ‘format’ of the this
variable doesn’t seem to be (usefully) ‘portable’.
For example, an automation with a state
trigger generates the following:
{
'entity_id': 'automation.my_automation',
'state': 'on',
'attributes': {
'id': 'my_automation',
'last_triggered': datetime.datetime(2024, 2, 17, 10, 41, 27, 507745, tzinfo=datetime.timezone.utc),
'mode': 'queued',
'current': 0,
'max': 50,
'friendly_name': 'My Automation'
},
'last_changed': '2024-02-17T08:56:11.505558+00:00',
'last_updated': '2024-02-17T10:41:28.521367+00:00',
'context': {
'id': '01HPVAG7EKVW9HW9X',
'parent_id':
'01HPVAG7EJTGQRGVR',
'user_id': None
}
}
I have an issue I can’t solve:
It doesn’t like the item last_triggered
'last_triggered': datetime.datetime(2024, 2, 17, 10, 41, 27, 507745, tzinfo=datetime.timezone.utc)
Is the state variable valid JSON? If so am just doing something wrong or can HA templating just not parse it correctly? (I’ve tried other tools with the same problems e.g. JSON Path Finder)
If I remove the item last_triggered
everything is fine