Guide: How to control Neptune Apex using Google Home

afhtan

New Member
View Badges
Joined
Jul 15, 2017
Messages
4
Reaction score
15
Rating - 0%
0   0   0
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:
35706927793_cfc86fc32c_n.jpg"


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
35706927673_11e0dc387c_n.jpg


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.
36515570045_5bfc0833ac_n.jpg


Enter the URL to trigger the home assistant switch and set the action to POST.
35706927213_fe6ec80489_n.jpg


Set the content type to "application/json " and paste in the JSON that specifies the home assistant switch to trigger.
36515569865_a1a19d77ee_n.jpg


Step 5: Test it out

Say "OK Google.." and your phrase and enjoy your new Reef Tank Assistant!
 

badstraw

Community Member
View Badges
Joined
Mar 1, 2016
Messages
34
Reaction score
5
Rating - 0%
0   0   0
Wow this is awesome!!

Is it possible to make it work with homebridge?
 

amps

Active Member
View Badges
Joined
Jul 12, 2016
Messages
311
Reaction score
285
Location
Ontario
Rating - 0%
0   0   0
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.
 

nero0762

Community Member
View Badges
Joined
Nov 16, 2016
Messages
61
Reaction score
30
Rating - 0%
0   0   0
This is really helpful!
Any idea how to query the apex for information, like the current temp or pH level?
 

Acorral

Active Member
View Badges
Joined
Feb 1, 2017
Messages
114
Reaction score
332
Location
Mexico City
Rating - 0%
0   0   0
This is really helpful!
Any idea how to query the apex for information, like the current temp or pH level?

On the same line... Would be great to be able to query and also to not need the direct IP access...

Would be great to have Apex integrated to ifttt indeed!

I guess the Apex is pushing it's it's s constantly to apexfusion.com, there must be a way of intercepting that communication and acting upon it... I guess
 

Cruz Mc5

Active Member
View Badges
Joined
Nov 7, 2018
Messages
120
Reaction score
205
Rating - 0%
0   0   0
This is great. I’m just getting ready to set up my Apex. Thanks!
 

Gary Grise

New Member
View Badges
Joined
Aug 11, 2017
Messages
8
Reaction score
5
Rating - 0%
0   0   0
This sounds great, I have a tank and APEX on battery backup. However if there is a power failure or comcast goes down, is it possible to put a google home on the battery backup as well and continue to control the apex? Sounds like I need the google assistant server also on battery backup as well perhaps an additional cascaded router also on battery backup? Thanks
 

wshinji

New Member
View Badges
Joined
Oct 29, 2018
Messages
10
Reaction score
0
Rating - 0%
0   0   0
Hello,

Can anyone confirm if this is still currently working with latest AOS? I cannot seem to get apex to access curl POST http requests anymore. Coming back with 401 Unauthorized Error even when the correct --user details has been defined. Works directly in a browser but not from curl. Any ideas?
 

Jeff Collins

Community Member
View Badges
Joined
Jan 12, 2018
Messages
26
Reaction score
17
Rating - 0%
0   0   0
Hey guys,

I spent some time on it this week and generally speaking this does still work but several pieces have changed. For example, when using home assistant if you are running a new version (not sure which one the switch was made in) you should be using webhooks.

Your updated IFTT call would then look like:
https://YOURURL/api/webhook/REALLYLONGSTRINGFORYOURAPIKEY
The body command would then be something like: {"action": "call_service", "service": "switch.turn_on", "entity_id": "switch.fish_tank_feedmode_a"}
 

blitzkragz

Active Member
View Badges
Joined
Dec 31, 2018
Messages
262
Reaction score
709
Location
Chapel Hill, NC
Rating - 0%
0   0   0
Hello,

Can anyone confirm if this is still currently working with latest AOS? I cannot seem to get apex to access curl POST http requests anymore. Coming back with 401 Unauthorized Error even when the correct --user details has been defined. Works directly in a browser but not from curl. Any ideas?
It looks like AOS no longer uses basic authentication. You can get around that by sniffing the authentication cookie, and including that in the curl request instead.

Login to your local Apex dashboard, then launch Chrome Developer Tools. In Developer Tools, click "Network", then in the Apex dashboard click something on or off. That will appear as an entry in developer tools. Click on that and in the "Headers" tab in Request Headers it will show a Cookie in the form of connect.sid=whatever. In your curl request you would include that as --cookie "connect.sid=whatever".
apex.jpg
 

rtoris288

New Member
View Badges
Joined
May 29, 2019
Messages
13
Reaction score
3
Rating - 0%
0   0   0
It looks like AOS no longer uses basic authentication. You can get around that by sniffing the authentication cookie, and including that in the curl request instead.

Login to your local Apex dashboard, then launch Chrome Developer Tools. In Developer Tools, click "Network", then in the Apex dashboard click something on or off. That will appear as an entry in developer tools. Click on that and in the "Headers" tab in Request Headers it will show a Cookie in the form of connect.sid=whatever. In your curl request you would include that as --cookie "connect.sid=whatever".
apex.jpg

Do you know if there you need to be able to refresh the token periodically?
 

Haubfather07

Active Member
View Badges
Joined
Dec 30, 2017
Messages
121
Reaction score
105
Location
Wilder, KY
Rating - 0%
0   0   0
I've been eyeing this post for a long time, trying to find the time to implement. Thanks in advance for not only the post and sharing but documenting and making the path to success easy for the rest of us! PS, if you're ever looking for a Network Engineering position, my company is hiring!
 

firebladeRR1k

New Member
View Badges
Joined
Apr 23, 2014
Messages
10
Reaction score
3
Rating - 0%
0   0   0
I have tried this but am getting a 401 error. Is anyone still able to use this? I’m trying to use this interface for additional automation.
 
Back
Top