Notification message with templates and multiple entities

Struggling to get what should be a very simple automation to work. I have two freezer temperature sensors, and I’m trying to write an automation to notify our phone when it happens. I’ve tried several different variations of using the “trigger” variable, but each try gives me a different error when I try to manually run the automation. Here’s the latest code:

id: '1703126247572'
alias: Freezer Temp Warning
description: ''
trigger:
  - platform: numeric_state
    entity_id:
      - sensor.garage_freezer_temperature
      - sensor.kitchen_freezer_thermometer_temperature
    for:
      hours: 0
      minutes: 5
      seconds: 0
    above: 20
    attribute: current_temperature
condition: []
action:
  - service: notify.all
    data:
      title: Freezer Warning!
      message: '{{ trigger.to_state.name }} is too high: {{ state_attr(trigger.for, 'temperature') }} F '
mode: single

I’ve also used “trigger.name”, “trigger.event.data.name”, etc. I’ve tried many different variations based on google searches. I get an error that looks like this when I click “Run” on the automation:

Executed: December 22, 2023 at 11:27:16 AM
Error: Error rendering data template: UndefinedError: 'dict object' has no attribute 'to_state'

Is the “trigger” object not populated when you manually trigger the automation to test it?

If I try this:


service: notify. All
data:
  title: Freezer Warning!
  message: '{{ state_attr(trigger.entity_id, ''friendly_name'') }} is too high.'

I get this error:


Executed: December 22, 2023 at 11:34:07 AM
Error: Error rendering data template: UndefinedError: 'dict object' has no attribute 'entity_id'

According to the Numeric State properties, “entity_id” should be a property of the trigger: https://www.home-assistant.io/docs/automation/templating/

No, neither the “Run” button or automation.trigger service populate the trigger variable.

To test your automation, you can temporarily set the state of one of your sensors in the States tab of the Developer Tools using the “Set State” button.

1 Like