Gmail Notification Not Working

Hope someone can help with this this.

I need to send out an email if a state of a sensor changes from on to off. I setup a Gmail SMTP and a automaton script, but it doesn’t work. When I call the service in the developer tools I don’t get any emails or errors in the log. I tried changing to port 485 with SSL encryption, but that didn’t help either. When I change the service in the automation to notify.notify and trigger it then I get notifications on my iPhone, but no emails.

notify.gmail
title: “test”
message: “test”

# Gmail SMTP
notify:
  - name: gmail
    platform: smtp
    server: smtp.gmail.com
    port: 587
    timeout: 15
    sender: [email protected]
    encryption: starttls
    username: [email protected]
    password: xxx
    recipient: [email protected]
    sender_name: Leak Alert
# Leak Alert
- id: 'leak_detected'
  alias: Email notificaton if leak is detected
  trigger: 
    - platform: state
      entity_id: binary_sensor.fortrezz_mimolite_sensor
  condition:
  - condition: state
    entity_id: input_boolean.leak_detected
    state: 'off'
  action:
  - alias: 'Send an email'
    service: notify.gmail
    data: 
      title: 'Leak Detected in AC #1'
      message: 'There is a leak detected. Please check AC #1 as soon as possible!'

What errors related to this are you getting in your home assistant log?

Have you enabled less secure apps for your gmail account?

https://myaccount.google.com/lesssecureapps

I am not seeing any errors in home assistant logs, unless I am looking in the wrong place.

I did enable use less secure apps.

unless I am looking in the wrong place.

Where are you looking?

Development Tools / Logs is the place.

Also set your logging level to at least ‘warn’.

This is very strange. I set the log level to warn, restarted home assistant, fired up the service and got the email. I did restart home assistant before. Did I miss something?

However, the automation does not work. I put the leak sensor in the water, the binary_sensor.fortrezz_mimolite_sensor does go off, but I don’t get the emails.

I had enabled less secure apps but found that after a while it stopped working, like Google was reminding me again this was a bad idea. I changed the account to 2FA and created an app password and haven’t had problems since.

the binary_sensor.fortrezz_mimolite_sensor does go off, but I don’t get the emails.

You also have a condition there that has to be true. input_boolean.leak_detected must be off as well - which seems strange, shouldn’t it be on?

Nice catch. I modified it and it works now. Thanks!

- id: leak_detected
  alias: Leak Detection
  description: ''
  trigger:
  - entity_id: binary_sensor.fortrezz_mimolite_sensor
    from: 'on'
    platform: state
    to: 'off'
  condition: []
  action:
  - data:
      title: 'Leak Detected in AC #1'
      message: 'There is a leak detected. Please check AC #1 as soon as possible!'
    service: notify.gmail

Thanks for posting this issue. I solved mine with:

- alias: Waterontharder leak
  trigger:
      platform: state
      entity_id: binary_sensor.0x00158d00047c4cbf_water_leak
      to: 'on'
  action:
     - service: notify.alexa_media
       data:
         target: media_player.echo
         data:
           type: tts
         message: "Hey Doublet, Big alarm, the water softener is leaking"  
     - service: notify.gmail
       data:
         title: "Hassio"
         message: "The water softener is leaking"