Automation action based on binary sensor

I want to base the action (message sent) on my motion detector status. I have the following, but something is wrong. any suggestions?

##Telegram lock, unlock, and check for motion        
- alias: 'telegram check for motion'
  id: '100'
  trigger:
    platform: event
    event_type: telegram_text
    event_data:
      text: 'Motion'
  action:
    - service_template: >
      {% if is_state('binary_sensor.sensor', 'off') %}
        - service: notify.notify_tgram
          data:
            message: "No motion detected."
      {% else %}
        - service: notify.notify_tgram
          data:
            message: "Motion detected."
      {% endif %}
##Telegram lock, unlock, and check for motion        
- alias: 'telegram check for motion'
  id: '100'
  trigger:
    platform: event
    event_type: telegram_text
    event_data:
      text: 'Motion'
  action:
    service: notify.notify_tgram
    data_template:
      message: >
        {% if is_state('binary_sensor.sensor', 'off') %} No motion detected.
        {% else %} Motion detected. {% endif %}
1 Like

That works perfectly, thank you!!

1 Like