Smart Plugs

I read with interest the couple of threads about integrating an Amazon Echo (Alexa) into an AMX system, but has anyone successfully integrated a smart plug (those things that an Echo uses to control lighting, etc.) into an AMX system...that is, without an Echo, or similar?
And, which one works best with AMX?

Cheers,

Gerald.

Comments

  • HARMAN_icraigieHARMAN_icraigie Technical Trainer II, Harman Professional University Posts: 483

    There are some interesting things possible through the Samsung SmartThings hub.

  • Am I right in thinking that Harman owns Samsung, or Samsung owns Harman?

    I've been looking at the setup, see what I can find.

    Thank you.

  • John NagyJohn Nagy CineTouch Product Manager Posts: 1,517

    @HARMAN_icraigie said:
    There are some interesting things possible through the Samsung SmartThings hub.

    Are these things that provide a path to communicate bidirectionally with the hub from AMX Netlinx code?
    I didn't see that hinted at before... and it's the context here of course.

  • HARMAN_icraigieHARMAN_icraigie Technical Trainer II, Harman Professional University Posts: 483

    @John Nagy said:

    @HARMAN_icraigie said:
    There are some interesting things possible through the Samsung SmartThings hub.

    Are these things that provide a path to communicate bidirectionally with the hub from AMX Netlinx code?
    I didn't see that hinted at before... and it's the context here of course.

    There was a full day session at last year's developers conference leveraging the open API RESTful protocol of the bridge and then extending the SmartThings functionality with Groovy including NetLinx integration

  • @HARMAN_icraigie said:
    There was a full day session at last year's developers conference leveraging the open API RESTful protocol of the bridge and then extending the SmartThings functionality with Groovy including NetLinx integration

    Is there a copy of the notes from that session, for those that didn't make it along?

    Incidentally, I asked Samsung about this, and got this response from the SmartThings Team:
    "There isn't an official integration between SmartThings and AMX so it's a bit of an odd one getting them to work together. Your best bet at getting these to work together would be to check out the SmartThings Community. I've had a very quick look myself and managed to find this post: https://community.smartthings.com/t/direct-lan-communication-no-longer-working-local-http-port-39500-doesnt-work-anymore/95330. It's not the same query as yours but it could be a good place to start your own research."

  • HARMAN_icraigieHARMAN_icraigie Technical Trainer II, Harman Professional University Posts: 483

    @geraldholdsworth said:

    @HARMAN_icraigie said:
    There was a full day session at last year's developers conference leveraging the open API RESTful protocol of the bridge and then extending the SmartThings functionality with Groovy including NetLinx integration

    Is there a copy of the notes from that session, for those that didn't make it along?

    Incidentally, I asked Samsung about this, and got this response from the SmartThings Team:
    "There isn't an official integration between SmartThings and AMX so it's a bit of an odd one getting them to work together. Your best bet at getting these to work together would be to check out the SmartThings Community. I've had a very quick look myself and managed to find this post: https://community.smartthings.com/t/direct-lan-communication-no-longer-working-local-http-port-39500-doesnt-work-anymore/95330. It's not the same query as yours but it could be a good place to start your own research."

    The OP for that community post is the same Sean Cameron who led the session at the conference. It's all based on the SmarThings open API so ya, no "official" integration - it integrates like any other 3rd party device or service.

  • HARMAN_icraigieHARMAN_icraigie Technical Trainer II, Harman Professional University Posts: 483

    In general data in and out of the SmartThings environment is accomplished through a simple RESTful API through the Hub.

    /*
    POST * HTTP/1.1
    Host: <urlSmartThingsHub>
    Connection: close
    User-Agent: Linux UPnP/1.0 SmartThings
    Content-Type: text/json
    Content-Length: ##
    
    "'{"name":"',deviceName,'","value":"',deviceValue,'"}'"
    */
    

    Up in the SmartThings cloud you create a SmartApp listener to actually handle the integration of all SmartThings Devices & Services, Apps ala NetLinx, Voice Agents, etc. This is the example Groovy code for a NetLinx relay. Access the Web IDE @ https://graph.api.smartthings.com/

    /**
     *  Netlinx Relay
     *
     *  Copyright xxxx yyyyyyyyyyyyyyyyyyy
     *
     *  Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
     *  in compliance with the License. You may obtain a copy of the License at:
     *
     *      http://www.apache.org/licenses/LICENSE-2.0
     *
     *  Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
     *  on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
     *  for the specific language governing permissions and limitations under the License.
     *
     */
    metadata {
        definition (name: "Netlinx Relay", namespace: "zzzzzzzzzzzzz", author: "yyyyyyyyyyyyyyyy") {
            capability "Switch"
    
            command "refresh"
        }
    
    
        simulator {
            // TODO: define status and reply messages here
        }
    
        tiles (scale: 2) {
            // The tile below is like a multi state TP button. 
               // Tiles are well documented on the SmartThings developer web page
            multiAttributeTile(name: "button", type: "generic", width: 6, height: 4, canChangeIcon: true, decoration: "flat") { 
                tileAttribute ("device.switch", key: "PRIMARY_CONTROL") {
                    attributeState "on", label:'${name}', action:"switch.off", icon:"st.switches.switch.on", backgroundColor:"#00a0dc", nextState:"turningOff"
                    attributeState "off", label:'${name}', action:"switch.on", icon:"st.switches,switch.off", backgroundColor:"#ffffff", nextState:"turningOn"
                    attributeState "turningOn", label:'${name}', action:"", icon:"st.switches.switch.on", backgroundColor:"#00a0dc", nextState:""
                    attributeState "turningOff", label:'${name}', action:"", icon:"st.switches.switch.off", backgroundColor:"#ffffff", nextState:""
                }
            }
    
            standardTile("refresh", "device.refresh", width: 2, height: 2, canChangeIcon: false, decoration: "flat") {
                state "off", label: "", action: "refresh", icon: "st.secondary.refresh"
            }
    
            main "button" // Determines which tile to use on main things list page
        }
    }
    
    preferences {   // Let's you enter the IP address and port of the Netlinx master you want to send strings to
        section("Netlinx Info") {
            input "netlinxIp", "text", title: "Netlinx Master IP Address", required: true
            input "netlinxPort", "text", title: "Netlinx Master Port Number", required: true
        }
    }
    
    // parse events into attributes
    def parse(String description) {
        log.debug "Parsing '${description}'"
        def msg = parseLanMessage(description)  // Defining a local scope variable called "msg" and populating it with the return of the parseLanMessage method 
        def json = parseJson(msg.body)
    
        switch (json.message) {
            case ["on","off"]:
                sendEvent(name: "switch", value: "${json.message}")
                break
        }
    }
    
    // handle commands
    def on() {
        log.debug "Executing 'on'"
        sendStringToNetlinx("on")
    }
    
    def off() {
        log.debug "Executing 'off'"
        sendStringToNetlinx("off")
    }
    
    def refresh() {
        log.debug "Executing 'refresh'"
        sendStringToNetlinx("refresh")
    }
    
    def sendStringToNetlinx(String str) {
        def result = new physicalgraph.device.HubAction(
            method: "GET",
            path: "/",
            headers: [
                HOST: "${netlinxIp}:${netlinxPort}"
            ],
            body: "${device.label},${str}"
        )
    
        sendHubCommand(result)
        log.debug "Executing ${str}"
        log.debug result
    }
    

    On the NetLinx side set up a data event on an IP Server to receive the messages from SmartThings

    data_event [dvSmartThingsRx]
    {
        online:
        {
        // Save SmartThings IP address for later use. The hub's address can change and we need to keep track of it. Might need to convert from IPv6 to IPv4!
        _StIpInfo.URL = data.sourceip;
        }
        offline:
        {
        wait 1 'SmartThingsRx Reconect'
        {
            ip_server_open(dvSmartThingsRx.port,2000,IP_TCP);
        }
        }
        string:
        {
        send_string 0,"'STRING from SmartThings: ',data.text";
    
        remove_string(data.text,"13,10,13,10",1)  // For this exercise I don't really care about the header so just get rid of it all.
        send_string 0,"'Body text: ',data.text";
    
        switch (data.text) // Better ways to parse this but quicker for classroom purposes
        {
            case 'relay,on':
            {
            on[dvRelays,1];
            }
            case 'relay,off':
            {
            off[dvRelays,1];
            }
            case 'relay,refresh':
            {
            if ([dvRelays,1])
            {
                fnSendCommandToST('relay','on');
            }
            else
            {
                fnSendCommandToST('relay','off');
            }
            }
        }
        }
    }
    

    And a mechanism to update SmartThings when the device status changes

    channel_event [dvRelays,1]
    {
        on:
        {
        fnSendCommandToST('relay','on');
        }
        off:
        {
        fnSendCommandToST('relay','off');
        }
    }
    

    The fnSendCommandToSt() function builds the http packet and sends it on its way - I would highly recommend the http library in David Vine's (of AVT fame) amx-util-library posted on Git Hub if you don't already have a well established methodology.

    Spoiler alert - this is based on the API that was current last year. The full ramifications of the recently released v3 API https://smartthings.developer.samsung.com/ on what is shown here has not been completely vetted as of yet. Rumor is that the recent update does significantly change some things.

  • Wow, thank you Ian.
    Can't wait to buy some SmartThings now and have a play.

Sign In or Register to comment.