Setting up a notification for when a switch changes state

Hi,

I’m hoping someone might be able to point out where I’m going wrong with a small automation I’m trying to do.

Basically, all I want is for a notification to be sent to my phone when a particular switch is turned from ‘off’ to ‘on’.

I have tested the ‘notify’ via the Services tool and it works fine (I can recieve the notification). However, when I add it to an automation, I don’t recieve anything. Here is my Automation Yaml

  alias: Test Notification
  description: 'Test'
  trigger:
  - platform: state
    from: 'off'
    to: 'on'
    entity_id: switch.switch_3
  action:
    service: notify.mobile_app_dave_s_phone
    data:
      message: 'Test Success'
      title: 'Test'


Everything seems ok when I check the config so am slightly confused as to what I’m missing.

For a little more information, the switch is actually a relay that is controlled via Tasmota. Essentially, its setup like a Sonnof basic. This powers my Boiler and so would like a notification everytime the boiler is turned on.

Thanks in advance for any help you can offer

Does it show under Automations that this one is triggering? You don’t need to have the “from” you can just use to. Not sure if this is related but the indentation looks a little different:

- id: notify_garage_door_open
  alias: "Notify Garage Door Opened"
  trigger:
    platform: state
    entity_id: cover.garage_door_1, cover.garage_door_2
    to: 'open'
  action:
    - service: notify.notify_angelo_devices
      data_template:
        title: "{{ trigger.from_state.attributes.friendly_name }} Opened"
        message: "{{ trigger.from_state.attributes.friendly_name }} was opened"

Though if you do define a from: it will prevent messages being sent from unavailable/unknown/none to on. Which can filter out unwanted messages.

The indentation is fine.

Does the automation appear in developer tools / states?

Is the automation state “on” (= automation is enabled)?

What happens when you trigger the automation manually?

Hi All,

Thanks for all the replies. I removed the ‘from: off’ statement and its working now!

I would be interested to know why this is, just for a learning for me. But my original problem has been solved.

Thanks

Does your switch report only off and on state or something more? Like idle etc …
You can check the states in tools services

Hi Makis, I think its just On or Off. How do I check in Tools / States?

When I go to developer tools / states I can select the entity and it just shows me the current state of the device (not all available states)

Probably it’s just on-off. I don’t know why from - to is not working though.