Different action message depending on current state template

Hi, how to do something like below? Do a different type of message action depending on current state (sun):

- id: '1553163933856'
  alias: Motion detected
  description: ''
  trigger:
  - entity_id: input_boolean.motion_sensor
    from: 'off'
    platform: state
    to: 'on'
  condition: []
  action:
    - service: notify.notify
      data_template:
        message: Motion detected in the back!    
        data: >
          {% if is_state('sun.sun', 'above_horizon') %}
            push:
              sound:
                name: Google-Motion-Detected.wav
                critical: 1
                volume: 1.0
          {% else %}
            push:
              sound: Google-Motion-Detected.wav
          {% endif %}

Thanks!

Same way as has been done for data. Copy the data code into message, remove push: code, replace with chosen text messages. Data_template doesn’t only work for a data section. It allows you to template any section.

Hi, thanks for the reply. Can you give me an example, please? Thanks!

Here you go.

  action:
    - service: notify.notify
      data_template:
        message: >
          {% if is_state('sun.sun', 'above_horizon') %}
            message one
          {% else %}
            message two
          {% endif %}
        data: >
          {% if is_state('sun.sun', 'above_horizon') %}
            push:
              sound:
                name: Google-Motion-Detected.wav
                critical: 1
                volume: 1.0
          {% else %}
            push:
              sound: Google-Motion-Detected.wav
          {% endif %}

Thank you so much!

Sure. Have fun!

Sorry, I’m getting this error:
Error executing script. Invalid data for call_service at pos 1: expected dict for dictionary value @ data[‘data’]

It’s complaining about the data: portion of your script. I don’t know what push:, etc. is so I don’t know how to help.