Guide: How to control Neptune Apex using Google Home

Discussion in 'Aquarium Controllers' started by afhtan, Aug 12, 2017.

  1. afhtan

    afhtan New Member

    Joined:
    Jul 15, 2017
    Messages:
    4
    Likes Received:
    10
    I am controlling my Reef Tank using an APEX and often have to turn off something when working on the tank.

    This can be a pain as wet hands and touch screen phones don't work well together. I thought. Wouldn't it be awesome if you could use google home to control your tank? For example, when you start doing a water change and the ATO starts screaming you could say "OK Google.. Turn off tank ATO".

    I searched around and there didn't seem to be a way to do it. Then, I realised the APEX Android app uses HTTP to communicate with your local APEX Web Server.

    After firing up Wire shark I found that you can control your apex by sending simple HTTP POST commands to the APEX. For example to turn off your ATO you can issue the following command on your local network:

    Code:
    curl -X POST --user admin:PASSWORD http://APEX_LOCAL_IP:APEX_PORT/status.sht?ATO_state=1&Update=Update
    
    The state is a enumeration where 0 = AUTO, 1 = OFF and 2 = ON.

    Now I can issue commands to the APEX. But how do you hook it up with Google Home? This is where the following combination of tools does the magic:
    Google Home + IFTTT + Home Assistant + Command Line Curl

    Here is a demo with my Neptune Apex Controlled Reef Tank:


    Step 1: Install Home Assistant

    Home Assistant (https://home-assistant.io) is a home automation server that you run on your local network. Home Assistant allows you to centralise command and control of multiple home automation devices in one location. Once a device is connected to home assistant you can control those devices remotely via a REST web API.

    Install Home Assistant by following the guides on the website and ensure you enable port forwarding to your home assistant server.

    Important: Ensure you setup home assistant with a password, dynamic dns and enable SSL by following the guides. You are about to open a public interface to your Reef Tank!

    Step 2: Add a command line switch for each Apex Connected Device

    Home automation has many modules (platforms) to control devices. An extremely useful and flexible platform is the "command_line" platform (https://home-assistant.io/components/switch.command_line/). Using the command_line platform we can program a switch that runs a curl command to interact with your APEX as described above.

    Add the following to your configuration.yaml file:

    Code:
    switch:
      - platform: command_line
        switches:
          fish_tank_ato:
            command_on: curl -X POST --user admin:PASSWORD http://APEX_LOCAL_IP:APEX_PORT/status.sht?ATO_state=0&Update=Update
            command_off: curl -X POST --user admin:PASSWORD http://APEX_LOCAL_IP:APEX_PORT/status.sht?ATO_state=1&Update=Update
    
    Restart your home assistant and you should now see a switch on the Home assistant UI:
    [​IMG]

    Step 3: Test the Home Assistant Switch

    Switches in home assistant can be called via a REST API (https://home-assistant.io/developers/rest_api/). The REST API requires you to POST the name of the switch in JSON and your home assistant password in the url request.

    Here is an example in curl:
    Code:
    curl -X POST -H "Content-Type: application/json" -d '{"entity_id" : "switch.fish_tank_ato"}' https://YOUR_DYNAMIC_DNS_HOSTNAME:HOME_ASSISTANT_PORT_ON_ROUTER/api/services/script/turn_on?api_password=HOME_ASSISTANT_PASSWORD
    Step 4: Connect everything using IFTTT (If This Than That)

    IFFT (https://ifttt.com/discover) allows you to connect input from one device (If This) to an action (Than That). We will be using IFTTT to make Google Assistant (This) perform web request to home assistant (Than That).

    Sign up to IFTTT and setup a new Applet. For the (This) select Google Assistant
    [​IMG]

    Select the "Say a simple phrase" option and enter in the phrase to activate the command. For example "turn off tank ato".

    For the "That" select the "Web Hooks" service.
    [​IMG]

    Enter the URL to trigger the home assistant switch and set the action to POST.
    [​IMG]

    Set the content type to "application/json " and paste in the JSON that specifies the home assistant switch to trigger.
    [​IMG]

    Step 5: Test it out

    Say "OK Google.." and your phrase and enjoy your new Reef Tank Assistant!
     
    exactlyobp, VR28man, badstraw and 5 others like this.

  2. psiclone

    psiclone Member

    Joined:
    Mar 11, 2017
    Messages:
    40
    Likes Received:
    14
    Very intriguing!
     
  3. Orly20

    Orly20 Active Member

    Joined:
    Jul 9, 2012
    Messages:
    459
    Likes Received:
    82
    Location:
    Miami,Florida
    Wow good job
     
  4. radiata

    radiata Active Member NJRC Member

    Joined:
    Nov 2, 2015
    Messages:
    376
    Likes Received:
    168
    Wow indeed!
     
  5. badstraw

    badstraw Member

    Joined:
    Mar 1, 2016
    Messages:
    29
    Likes Received:
    5
    Wow this is awesome!!

    Is it possible to make it work with homebridge?
     
  6. blazeby

    blazeby Member

    Joined:
    Feb 11, 2017
    Messages:
    64
    Likes Received:
    30
  7. amps

    amps Active Member

    Joined:
    Jul 12, 2016
    Messages:
    159
    Likes Received:
    106
    Location:
    Buffalo
    Just wanted to say thanks for the guide. I found a few issues as I was following along but after a few hours, my whole apex is controllable through Google Home. I even bought a Home Mini to have next to the tank on Black Friday.

    The issues I had were:

    Code:
    https://YOUR_DYNAMIC_DNS_HOSTNAME:HOME_ASSISTANT_PORT_ON_ROUTER/api/services/script/turn_on?api_password=HOME_ASSISTANT_PASSWORD
    Should be:

    Code:
    https://YOUR_DYNAMIC_DNS_HOSTNAME:HOME_ASSISTANT_PORT_ON_ROUTER/api/services/SWITCH/turn_on?api_password=HOME_ASSISTANT_PASSWORD
    Notice the change from SCRIPT to SWITCH.


    And any commands you send via Home Assistant should have the HTTP code blocked in quotes or it'll throw errors and get stuck. ie..

    Code:
    command_on: curl -X POST --user admin:password "http://YOUR_APEX_IP:80/status.sht?powerheads_state=0&Update=Update"
    I love being able to say "Hey Google, feed my corals" and have it enter a dedicated feed mode. Super awesome.
     
  8. nero0762

    nero0762 Member

    Joined:
    Nov 16, 2016
    Messages:
    57
    Likes Received:
    24
    This is really helpful!
    Any idea how to query the apex for information, like the current temp or pH level?
     
    Tristren likes this.
  9. bcpitts

    bcpitts Member

    Joined:
    Oct 3, 2014
    Messages:
    24
    Likes Received:
    3
    Location:
    Atlanta GA
    Any chance this could work with Alexa?
     
  10. Joe Carioti

    Joe Carioti Active Member

    Joined:
    Aug 18, 2017
    Messages:
    106
    Likes Received:
    46
Draft saved Draft deleted

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice
Loading...