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.
# 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!'
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.
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"