Notification within automation

Hello together,

I created this automation:

alias: Aussen u Weihna aus
description: Aussen- und Weihnachtsbeleuchtung aussschalten
trigger:
  - at: '23:00'
    platform: time
  - platform: numeric_state
    entity_id: sensor.helligkeit_2
    above: '30'
condition: []
action:
  - device_id: 63de5b12639347dd9701de211f924f45
    domain: light
    entity_id: light.wled_bieber_master
    type: turn_off
  - type: turn_off
    device_id: b2a32e84ecb9efaa1dcf6a91284766c4
    entity_id: light.wled_gruenwichtel
    domain: light
  - type: turn_off
    device_id: 03d7308c00ef7471e0b72653a465f507
    entity_id: light.wledfcblampe
    domain: light
  - type: turn_off
    device_id: 9fd74c3622a94fa997af527fdc6b8b87
    entity_id: switch.shelly_shsw_1_1d9ff5
    domain: switch
  - service: switch.turn_off
    data: {}
    entity_id: switch.balkon
  - service: notify.mobile_app_oneplus_a6003
    data:
      title: Aussen- u-Weihnachtsbeleuchtung ausgeschaltet
      message: >-
        Die Aussen- und Weihnachstsbeleuchtung wurde durch
        {{trigger.to_state.attributes.friendly_name}} ausgeschaltet
      data:
        color: green
        ledcolor: green
        sticky: 'true'
mode: single

The automation is working fine, but I have some problems with my notification.
If the automation is triggered by sensor.helligkeit_2 I get the notification, but if it is triggered by time I dont get it.

How can I change this behavior?

Best regards,
Stefan

Take a look at this:

Specifically, look at platform: time and platform: state

For time, {{trigger.to_state.attributes.friendly_name}} doesn’t exist.

You’re better off just using the state_attr function in this case

- service: notify.mobile_app_oneplus_a6003
    data:
      title: Aussen- u-Weihnachtsbeleuchtung ausgeschaltet
      message: >-
        Die Aussen- und Weihnachstsbeleuchtung wurde durch
        {{state_attr('sensor.helligkeit_2', 'friendly_name') }} ausgeschaltet

Or, you can check to see if it was a time trigger and not send the notification with the ‘choose’ action if you wanted.

1 Like

ok, thx. I will try it and read a bit more about templates and so on