Question about condition

hi guys i have this automation to send notification if a switch is turned ON…

- alias: Notification - SWITCH IS ON 
  trigger:
    platform: state
    entity_id: switch.switch_5
    from: 'off'
    to: 'on'
  action:
    - service: notify.notify
      data:
        message: 'SWITCH IS ON'

this one works fine but i get multiple notifications every time this switch is turn ON even from ON position (i used automation to turn it on when my phone is connected on my network). I would like to only send notification if the switch is actually toggled to ON from OFF. I tried this code but it gives HA an ERROR and not able to start HA (fully im not confusing you guys)

- alias: Notification - SWITCH IS ON
  trigger:
    platform: state
    entity_id: switch.switch_5
    from: 'off'
    to: 'on'
  condition: state
    entity_id: 'switch.switch_5'
    from: 'off'
    to: 'on'
  action:
    - service: notify.notify
      data:
        message: 'SWITCH ON'

can please someone point me to the right direction

Try:

- alias: Notification - SWITCH IS ON
  trigger:
    platform: state
    entity_id: switch.switch_5
    from: 'off'
    to: 'on'
  condition: 
    condition: state
    entity_id: 'switch.switch_5'
    from: 'off'
    to: 'on'
  action:
    - service: notify.notify
      data:
        message: 'SWITCH ON'

I think conditions check the state of a entity while trigger are caused by a change of state. I don’t think you can have from / to on a condition as its can only check the state, not a change.

1 Like

If the switch is already on then that automation shouldn’t even trigger as it has to move from off to on for that to happen.

Good point.