Getting your house to ask you for help: Setting up Email Notification using GMail

 < Previous                                                                                           Next >


We left off with my wife saying, "I hope I remember to check (batteries) often enough"

Well, what if the lock just told us when it needed new batteries?

"Hey Mike and his awesome wife, this is the house - the batteries in the Scottish Room are getting low, they need to get changed soon."

WARNING! Incoming System Design thoughts!  Skip this if only interested in the tech details!

"I hope I remember to check often enough" - this is the human equivalent of something called 'polling'.  Basically it is similar to a child in the back seat:

child: "Are we there yet?"

driver: "No"

child: "Are we there yet?"

driver: "No!"

child: "Are we there yet?"

driver: "NO!!"

child: "Are we there yet?"

driver: <drives into a tree>

It is a lot more efficient to just wait until you get there, and have the driver tell you "We're here!".  It uses less resources (the child could sleep), and is less taxing on the system that has to answer the question (long suffering driver).

Ok.  Moving on...

I bet this can be done, I mean it is automation, it is a sensor.  Hum...time to research.

So the question became, how do I best tell the users (my wife and myself) that we need to change the batteries?  Well, I guess I need to decide how low the batteries need to be before we change them.  I think 0% is probably too low.  Ok..research that.

After some research, it looks like people are saying that at 30% of the batteries, the locks may start to misbehave.  Ok, I got a number (that I may tweak in the future if I find it was wrong).

So now, how do I let my wife know about things?  Well, we text (SMS), email, use facebook messenger, do video calls, facetime, voice calls...eek.  Well, how important is it that we know the batteries are low?  Because we host a Bed and Breakfast, it can be important, but if we get told a little before the battery is no longer useful, then we have time make sure we have the batteries on hand for replacement.  Not critical, but important.  Ok, for my wife and I, this sounds like an email will work.

So, what I want is; 

Tell me when batteries need to be changed on the door locks

Tell me (Send an email to my wife and I) when batteries need to be changed on the door locks (any of the door locks batteries drops below 30%).

In Home Assistant, you can 'notify' (tell somebody something somehow) using email (and a bunch of other ways, but I am focused on email right now).

The page that explains how to send email 'notifications' from Home Assistant is the "SMTP" page.  SMTP is another of those acronyms techy people love because saying "Simple Mail Transport Protocol" is a mouthful.

I decided to set up a new gmail account just for my Home Assistant.  It was easy, and means that I will have a dedicated email address just for my HA (acronym!).

There is an example on the page that shows how to write "A sample configuration entry for Google Mail." in your "configuration.yaml".

What is this "configuration.yaml" thing you speak of?

We saw 'yaml' before when we were writing a script, it is used in HA for 'Configuration'. Home Assistant has a huge ability to do stuff, but as I said when first introducing it: "Like most free things, the cost is in learning how to make use of it.".  Sometimes using it means you have to get a little under the covers.  When computer folks talk about using a system, and changing it to make it do what you want, they say "Configuration".  It is a very general term, that covers any type of system use.

In order to change the "configuration.yaml", you need to be able to get to it and change it.  There is more than one way to do this, but I will show you the way I do it, with the "File Editor" add-on.

Get The File Editor

Go to the "Supervisor" Dashboard.
Go to the "Add-on Store"

In the "Official add-ons" section, find the "File editor"

Select it and install it.
Now select "Start"

Now you can use this "Add-on" from this point forward.  You do not have to re-install it, you can just go to the "Supervisor" dashboard, select it, and you are ready to "Open Web UI". 

"Open Web UI"

 


Select the "Browse Filesystem" icon in the upper left , and select the "configuration.yaml



then click in the grayed out area to the right.

Be very careful right now!!!!
If you muck up changes to this file, it can make your HA totally...well, mucked up.  I have already made changes to this file, that you may see.  You will not need these exact changes, we can walk through the ones you do need

Now we are ready to follow those directions we saw up above at the page that explains how to send email 'notifications' from Home Assistant.

I used my new google account gmail account to set up the smtp notifications.  Here is the text (cause I hate typing too).  You will need to change the values to be correct for your email account.  The 'name' you use will be how you use this later, so it is good to remember what it is.  Formme I used the name "mrh_gmail".

notify:
  - name: mrh_gmail
    platform: smtp
    sender: xxxxxxxxxxx+ha@gmail.com
    recipient: 
      - mikes_awesome_wife_xxxxxxxxxxx@gmail.com
      - mike_xxxxxxxxxxx@gmail.com
    server: smtp.gmail.com
    port: 587
    timeout: 15
    encryption: starttls
    username: xxxxxxxxxxx@gmail.com
    password: a_very_long_secure_password
    sender_name: xxxxxxxxxxx+ha@gmail.com
    debug: true

In the "configuration.yaml

Then "Save" the configuration
Because this is a pretty big configuration change, I suggest you "Restart HASS" (basically this will re-boot your Home Assistant - make it act like it just started over with the new configuration).

While restarting, you will see the page tell you it lost connection...

This may take a few minutes - time to get a drink, or relieve yourself of a few.

Gmail - "allow less secure apps"

When I set this up for the first time, I had to allow less secure apps for my new gmail.  I got an email from google that said:


So I had to follow the directions here: https://support.google.com/accounts/answer/6010255.

When you follow that link, you need to make sure you go to the proper address.  I have several gmail/google accounts I stay logged into, so I had to make sure I changed the right one.
And then enabled the setting...
I am a cautious individual, so after doing this, I rebooted my HA...again.  I knew that if Google had told me it did not let something talk to the system, it was likely that HA (the only thing that had that email address) was not happy, so...reboot.

I checked the logs (Configuration > Logs)

To see if there were any errors, 


it looks ok...

Ok.  Now I want to try sending my wife and I an email.  How do I try that?






 < Previous                                                                                           Next >

Comments

Popular posts from this blog

Get the Hardware

Home Automation