Send message on state change with binary sensor

I have set up the following binary sensor. It is checking to see if I am importing from the grid or not

template:
  - binary_sensor:
      - name: On Grid
        state: "{{ states('sensor.lux_power_from_grid_to_house_live') | int(-1) > 0 }}"

I then wrote this automation to send me a message, but it is not triggering. What have I missed?

alias: Grid Status
description: Grid Status
trigger:
  - platform: template
    value_template: "{{ states('On Grid')| int(0) > 0 }}"
condition:
  - condition: time
    after: "08:00:00"
    before: "21:00:00"
action:
  - service: notify.notify
    data:
      message: |
        {% if is_state('sensor.lux_power_from_grid_to_house_live', 'off' ) %}
          Off Grid
        {% else %}
          On grid using {{ states("sensor.lux_power_from_grid_to_house_live") }} watts
        {% endif %}
      title: Grid Status
mode: single

I’m not sure if your logic to check a binary sensor will work or not, however I use something like below in my automations for binary sensors:

- alias: International Space Station 10 Minute Pass Warning
  trigger:
  - platform: state
    entity_id: binary_sensor.international_space_station_iss_10_minute_pass_warning
    to: 'on'

Good hunting!

That is not a sensor.

states('binary_sensor.on_grid')

Developer tools are your friend. You should use them first to write your templates:

alias: Grid Status
description: Grid Status
trigger:
  - platform: state
    entity_id: binary_sensor.on_grid
condition:
  - condition: time
    after: "08:00:00"
    before: "21:00:00"
action:
  - service: notify.notify
    data:
      message: |
        {% if trigger.to_state.state == 'off' %}
          Off Grid
        {% else %}
          On grid using {{ states("sensor.lux_power_from_grid_to_house_live") }} watts
        {% endif %}
      title: Grid Status
mode: single

That is a very good tip. Thank you. I used Developer Tools to write the template and used states to check it, but never thought to use the Developer Tools for the automation syntax

Thank you. I have added that. I will see if it triggers today. Not sure if the battery will drain enough.