Control Your Apex with Siri

Discussion in 'Neptune Systems' started by blazeby, Sep 17, 2017.

  1. blazeby

    blazeby Member

    Joined:
    Feb 11, 2017
    Messages:
    64
    Likes Received:
    30
    Hi all,

    Thanks to a free framework called Homebridge I've been able to control my tank with Siri voice commands.

    I find this useful for when my hands are wet and the touch screen on my tablet won't work to turn things on and off via my Apex. Now I just say "Hey Siri, turn off the skimmer" or "Hey Siri, turn off the aquarium alarm".

    Homebridge is an open source framework that allows us to add none HomeKit devices to HomeKit and this allow Siri control of those devices.

    First thing you need to do is install Homebridge, it's free and instructions are here: https://github.com/nfarina/homebridge

    In the Mac terminal: npm install -g homebridge

    I used to run it on my Mac but nowadays have it running on a Raspberry Pi - works well on either platform. It also works on Windows machines although I have never tried that.

    Next install a Homebridge plug-in called cmdSwitch2 with npm install -g homebridge-cmdswitch2

    Now you have to edit your Homebridge config file (config.json) to add the control params for your Apex.

    The Apex can be controlled by simple HTTP POST commands and we're going to use them. Your cmdswitch2 entries in your Homebridge config file should look something like this:

    "platform": "cmdSwitch2",
    "name": "CMD Switch",
    "switches": [
    {
    "name" : "Skimmer",
    "on_cmd": "/usr/bin/curl -X POST --user admin:<adminPassword> http://<apexIPaddress>:<apexPortNumber>/status.sht?Skimmer_state=2&Update=Update",
    "off_cmd": "/usr/bin/curl -X POST --user admin:<adminPassword> http://<apexIPaddress>:<apexPortNumber>/status.sht?Skimmer_state=1&Update=Update",
    }

    The state (apexDevice_state) is 0 for Auto, 1 for OFF, and 2 for ON.

    And thats it!

    Thanks to this thread for the HTTP POST info: https://www.reef2reef.com/threads/guide-how-to-control-neptune-apex-using-google-home.319864/

    I may spend sometime to get Siri to be able to report the current state of devices and probes and possibly write a dedicate Apex Homebridge plug-in if time permits.
     
    exactlyobp, Greybeard, Zack K and 5 others like this.
    Tags:

  2. Fishlee

    Fishlee Active Member

    Joined:
    Jan 5, 2014
    Messages:
    297
    Likes Received:
    58
    Location:
    San Jose
    Sounds cool but still too complex for me :)
     
  3. MaddyP

    MaddyP 'Til Reefdom Come... R2R Supporter R2R Excellence Award Build Thread Contributor Partner Member 2018

    Joined:
    Jul 21, 2016
    Messages:
    1,379
    Likes Received:
    3,675
    Location:
    San Pedro, CA
    This is great! Although, it might get more attention in the controller forum than the sponsor forum...

    #mods
     
    Zack K likes this.
  4. blazeby

    blazeby Member

    Joined:
    Feb 11, 2017
    Messages:
    64
    Likes Received:
    30
    That's a very good point!
     
  5. bcpitts

    bcpitts Member

    Joined:
    Oct 3, 2014
    Messages:
    24
    Likes Received:
    3
    Location:
    Atlanta GA
    Very nice. Looking forward to more outbid this feature.
     
  6. Carlosreef

    Carlosreef Member

    Joined:
    Oct 9, 2013
    Messages:
    5
    Likes Received:
    4
    Location:
    Chicago
    Thank you for putting this thread. I just found it so I decided to give it a try. I got it to work correctly using a Raspberry Pi 3 and could not be happier!

     
  7. blazeby

    blazeby Member

    Joined:
    Feb 11, 2017
    Messages:
    64
    Likes Received:
    30
    Awesome!
     
  8. Carlosreef

    Carlosreef Member

    Joined:
    Oct 9, 2013
    Messages:
    5
    Likes Received:
    4
    Location:
    Chicago
    Were you able to ever figure out the HTTP POST for the feed cycles?
     
  9. noahreefer

    noahreefer Active Member

    Joined:
    Dec 11, 2017
    Messages:
    247
    Likes Received:
    164
    Dang!!! That’s sick!!
     
  10. Joe Carioti

    Joe Carioti Active Member

    Joined:
    Aug 18, 2017
    Messages:
    109
    Likes Received:
    50
    This looks great! If Homebridge allows for it, you might be able to get outlets or VDM controllability in the Home app as well as controllable by Siri commands.
     
  11. Carlos@CoralVue

    Carlos@CoralVue Active Member Gold Sponsor

    Joined:
    Dec 2, 2013
    Messages:
    101
    Likes Received:
    107
    Location:
    Chicago, IL
    Yes, that's how I have it set.
     
  12. Joe Carioti

    Joe Carioti Active Member

    Joined:
    Aug 18, 2017
    Messages:
    109
    Likes Received:
    50
    Nice! That's super powerful. Do you mind sharing your Homebridge configuration?
     
  13. Carlos@CoralVue

    Carlos@CoralVue Active Member Gold Sponsor

    Joined:
    Dec 2, 2013
    Messages:
    101
    Likes Received:
    107
    Location:
    Chicago, IL
    Sure thing...

    Code:
    {
        "bridge": {
            "name": "Homebridge",
            "username": "CC:22:3D:E3:CE:30",
            "port": 123456,
            "pin": "031-45-154"
        },
    
        "description": "This is an example configuration file with one fake accessory and one fake platform. You can use this as a template for creating your own configuration file containing devices you actually own.",
    
        "accessory": [],
    
        "platforms": [
        {
            "platform": "cmdSwitch2",
            "name": "CMD Switch",
            "switches": [
            {
                "name": "Water Change",
                "on_cmd": "/usr/bin/curl -X POST --user <<username>>:<<password>> http://<<ip address>>:<<port>>/status.sht?Return_Pump_state=1&Update=Update",
                "off_cmd": "/usr/bin/curl -X POST --user <<username>>:<<password>> http://<<ip address>>:<<port>>/status.sht?Return_Pump_state=0&Update=Update"
            },
            {
                "name": "Lights",
                "on_cmd": "/usr/bin/curl -X POST --user <<username>>:<<password>> http://<<ip address>>:<<port>>/status.sht?Lights_state=0&Update=Update",
                "off_cmd": "/usr/bin/curl -X POST --user <<username>>:<<password>> http://<<ip address>>:<<port>>/status.sht?Lights_state=1&Update=Update"
            },
            {
                "name": "Skimmer",
                "on_cmd": "/usr/bin/curl -X POST --user <<username>>:<<password>> http://<<ip address>>:<<port>>/status.sht?Skimmer_state=0&Update=Update",
                "off_cmd": "/usr/bin/curl -X POST --user <<username>>:<<password>> http://<<ip address>>:<<port>>/status.sht?Skimmer_state=1&Update=Update"
            },
            {
                "name": "Gyre Left",
                "on_cmd": "/usr/bin/curl -X POST --user <<username>>:<<password>> http://<<ip address>>:<<port>>/status.sht?XF280_Left_state=0&Update=Update",
                "off_cmd": "/usr/bin/curl -X POST --user <<username>>:<<password>> http://<<ip address>>:<<port>>/status.sht?XF280_Left_state=1&Update=Update"
            },
            {
                "name": "Gyre Right",
                "on_cmd": "/usr/bin/curl -X POST --user <<username>>:<<password>> http://<<ip address>>:<<port>>/status.sht?XF280_Right_state=0&Update=Update",
                "off_cmd": "/usr/bin/curl -X POST --user <<username>>:<<password>> http://<<ip address>>:<<port>>/status.sht?XF280_Right_state=1&Update=Update"
            },
            {
                "name": "Smart ATO",
                "on_cmd": "/usr/bin/curl -X POST --user <<username>>:<<password>> http://<<ip address>>:<<port>>/status.sht?ATO_state=0&Update=Update",
                "off_cmd": "/usr/bin/curl -X POST --user <<username>>:<<password>> http://<<ip address>>:<<port>>/status.sht?ATO_state=1&Update=Update"
            },
            {
                "name": "Fans",
                "on_cmd": "/usr/bin/curl -X POST --user <<username>>:<<password>> http://<<ip address>>:<<port>>/status.sht?Cooling_Fans_state=0&Update=Update",
                "off_cmd": "/usr/bin/curl -X POST --user <<username>>:<<password>> http://<<ip address>>:<<port>>/status.sht?Cooling_Fans_state=1&Update=Update"
            },
            {
                "name": "Feed",
                "on_cmd": "/usr/bin/curl -X POST --user <<username>>:<<password>> http://<<ip address>>:<<port>>/status.sht?Feed_state=0&Update=Update",
                "off_cmd": "/usr/bin/curl -X POST --user <<username>>:<<password>> http://<<ip address>>:<<port>>/status.sht?Feed_state=1&Update=Update"
            }
            ]
        }]
    }
    
    BTW, I could not figure out the call for FeedX so I ended up creating a virtual outlet that allows me to do the same. The catch is that I have to remember to turn it OFF or the feed will never stop. So if you can figure out the call for FeedA, let me know!
     
    MaddyP and Zack K like this.
  14. Joe Carioti

    Joe Carioti Active Member

    Joined:
    Aug 18, 2017
    Messages:
    109
    Likes Received:
    50

    Awesome! Thanks Carlos. I had the config.json syntax messed up a bit. I just got this working with my system. That was easier than I expected for sure.
     
    Carlos@CoralVue likes this.
  15. Joe Carioti

    Joe Carioti Active Member

    Joined:
    Aug 18, 2017
    Messages:
    109
    Likes Received:
    50
    So, one thing that adds a nice touch here is to populate the "state_cmd" value so Homekit can report back the proper outlet state (on or off). The trick here is how we handle the fact that the cmdSwitch2 library only supports on and off and Apex supports on, off, and auto. Here are the two variations that I can't decide between...

    Config 1
    Use this configuration to report "ON" when the outlet is in either in AUTO or ON mode (If the outlet is in AUTO-OFF mode, it will report "ON" in Homekit):
    Code:
    "state_cmd": "/usr/bin/curl --fail --silent --show-error --user admin:{{YOUR_APEX_PASSWORD}} http://{{YOUR_APEX_IP}}:{{YOUR_APEX_PORT}}/cgi-bin/status.xml | grep -i '<name><{{YOUR_APEX_OUTLET_NAME}}</name>' -A2 | grep -E -i 'AO|ON'"
    I prefer this config because I rarely ever turn my outlets to full ON. I always consider OFF = OFF and ON = AUTO. So when the outlet is in AUTO mode, I want Homekit to tell me that the outlet is turned ON.


    Config 2
    Use this configuration to report "ON" if the outlet is getting electrical power (If the outlet is in AUTO-OFF mode, it will report "OFF" in Homekit):
    Code:
    "state_cmd": "/usr/bin/curl --fail --silent --show-error --user admin:{{YOUR_APEX_PASSWORD}} http://{{YOUR_APEX_IP}}:{{YOUR_APEX_PORT}}/cgi-bin/status.xml | grep -i '<name><{{YOUR_APEX_OUTLET_NAME}}</name>' -A2 | grep -i 'ON'"
    This configuration might be what you guys would expect to see. If your skimmer is turned on by any means (ON, or AUTO-ON), you'll see "ON" in HomeKit. If your skimmer is turned off by any means (OFF, or AUTO-OFF), you'll see "OFF" in HomeKit.
     
    MaddyP likes this.
  16. Carlos@CoralVue

    Carlos@CoralVue Active Member Gold Sponsor

    Joined:
    Dec 2, 2013
    Messages:
    101
    Likes Received:
    107
    Location:
    Chicago, IL
    I think Config 1 makes total sense to me. That is how I have some of my switches set. At the end of the day, this is for me and not someone else. I understand the logic of it and it is something that makes sense.

    The only issue I see is if something is set to OFF automatically. Like the fans... The fans could be set to AUTO but the default state is OFF. That is where this would get a little tricky.
     
    Last edited: Jan 16, 2018
  17. Carlos@CoralVue

    Carlos@CoralVue Active Member Gold Sponsor

    Joined:
    Dec 2, 2013
    Messages:
    101
    Likes Received:
    107
    Location:
    Chicago, IL
    Love it when things come together!!!
    IMG_0285.png
     
    Joe Carioti likes this.
  18. blazeby

    blazeby Member

    Joined:
    Feb 11, 2017
    Messages:
    64
    Likes Received:
    30
    You guys have done a great job! I use a combo of config 1 and config 2 depending on whether or not Auto is set to ON or OFF.

    For the FeedX not turning off problem this is where HomeKit will help you out - you can set a timer to automatically turn a device on or off via the Home app.

    IMG_9D0CD68E8A81-1.jpeg
     
    nemmaninme and Joe Carioti like this.
  19. Joe Carioti

    Joe Carioti Active Member

    Joined:
    Aug 18, 2017
    Messages:
    109
    Likes Received:
    50
    Great idea. I might look into forking that cmd2switch library to allow for on, off, and auto states. It would need a different UI than the standard HomeKit “switch” UI. I’ll report back if I find anything useful.
     
  20. blazeby

    blazeby Member

    Joined:
    Feb 11, 2017
    Messages:
    64
    Likes Received:
    30
    Thinking about forking it myself to provide temperature sensor support so we can retrieve temp, pH, ORP etc via Homebridge.
     
    Joe Carioti likes this.
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...