Results 1 to 3 of 3

Thread: Push Notifications

  1. #1
    Automated Home Sr Member cliffwright's Avatar
    Join Date
    Mar 2007
    Posts
    86

    Default Push Notifications

    Hi Folks,

    Off the back of https://www.automatedhome.co.uk/vbul...nding-requests and In case anyone finds this interesting, I've recently tackled a couple of use-cases I couldn't achieve before to give me Push Notifications to my phone.

    Given we humans are now practically part-cyborg in the way our mobile phones are attached to our pocket or hand at all times, I wanted to use this to better warn me about certain situations in the house.

    My most obvious use cases center around;

    1) Wanting to know when a side gate has been left opened for more than a set period of time (by the kids generally)
    2) Wanting to be reminded before I go to bed if a door / lock needs to be closed / locked because someone has forgotten to shut it and lock up earlier in the day (mostly the garage doors).

    I need to be "Alerted", so wanted something more 'demanding' than an email, so decided I wanted a Push Notification to my phone.

    I investigated 2 ways of achieving this. 1 was using IFTTT, and whilst this worked, I have 2 issues with IFTTT;

    a) It relies upon their service which "could" change at any time.
    b) They've decided to succumb to Corporate greed and have begun charging a subscription fee for their service if you have anything other than a tiny need. Call me what you will, but I really don't like this trend for "Monthly subscriptions" in almost every simple bit of tech these days, so where possible would rather keep things 'in house' and self-served.

    With this, I've chosen a 2nd option of using an open-source Home Automation platform called "Home Assistant" (https://www.home-assistant.io/) in a simple form to act as little more than a messaging service.

    I won't go into too low a level detail (I can if anyone wants more detail) of how it is all installed as this info is available on the home-assistant website - but effectively I've got the basic Home Assistant application running on a Raspberry Pi4 and installed the iOS app on my phone. This then gives 2 integration options;

    1) You can call what HA refers to as a "Service" - where you can hit a REST endpoint and pass in a JSON body to stipulate the Push notification Title and message.
    2) You can setup what HA refers to as a webhook - which is a fixed URL that you can hit to trigger what HA refers to as an "Automation", which in my simple case is then calling the same notification service as in the above where the Push notification message and title is specified (as YAML) in the "Automation".


    I've gone with option 1 above so that I can keep the control within Cortex and specify the message at source. Setup basics are;

    On the home assistant side of things:

    1) Install HA on the Pi4
    2) Install the iOS app on your phone
    3) Optionally, if you're wanting to access this app outside of your network, setup suitable port forwarding on your Router / any DDNS you might need to hit this from the outside world.
    4) Setup a Long-Lived Access token in HA (Details here https://developers.home-assistant.io/docs/api/rest/ )

    This allows you to hit the HA "Notify" service using the URL http://192.<yourIP>:8123/api/services/notify/<your device name>, including the long-lived token as an Authorization header "Bearer <your token>" and a simple JSON body of;

    {
    "message": "A message",
    "title": "Push notification Title"
    }

    You can test the above setup using Postman etc to start with to fire at the service and check it's setup correctly.


    On the Cortex side, there's clearly several ways to achieve this, but for my Garage door use-case I then setup;

    1) A Web API Client Object, and within this a POST request as follows;



    Note: It's critical to tick the "Parameter list embeded in header" check box. Not doing so means that the request body is incorrectly appended to the Authorization Bearer Header by Cortex making the request fail.

    2) A general logic object that combines the state of the Door and it's lock into one variable (so less things to check later)

    3) A Macro object that has some simple If, Else, End if, conditions to check the state of several garage doors and their lock states and call the Web API setup in step 1 if it finds anything is still open / unlocked.



    4) A scheduled event to call the above macro at a set time each night which is just before "bedtime".

    With this, if I managed leave the garage door unlocked by accident, I'm sent a Notification such as the following to remind me to go lock up.




    There's a few other use cases I intend to explore too soon ... using HA as an integration method to offer a work-around to the fact that I can't get cables to some subjects I want to automate and so some wireless options would be usable if there's an integration method for Cortext to fire at.

    Hope this is useful to someone else - it certainly is to me
    Attached Images Attached Images

  2. #2
    Automated Home Legend chris_j_hunter's Avatar
    Join Date
    Dec 2007
    Location
    North Lancashire
    Posts
    1,680

    Default

    Cliff -

    many thanks for posting ... will soon have a go here, too ...

    Chris

  3. #3
    Automated Home Sr Member cliffwright's Avatar
    Join Date
    Mar 2007
    Posts
    86

    Default

    Quote Originally Posted by chris_j_hunter View Post
    Cliff -

    many thanks for posting ... will soon have a go here, too ...

    Chris
    Great - hope it helps.

    FYI - I just had the mis-pleasure of upgrading my phone (iOS) and through this had to do some fiddling to make HA provide the notify service to my new phone. Whilst it recognised that there was another phone, I think it was generally getting confused at the fact that both phones were "Named" the same thing. After a small amount of fiddling, renaming the devices in HA, I got things back up and running, but the main thing I noted in this was that it stated there is a limit of 300 push notifications per day (It wasn't that clear whether this was per-device (which I assume it is), or across an install of HA).

    I can't imagine me personally using anywhere near 300 per day, but just in case it does matter to you ..

    (Note - It wasn't too hard ... but just another thing to bear in mind. It was easier than getting several of my banking apps to play nice on my new phone mind you!)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •