Virtual Switch, Alexa and Ifttt

I basically see the same things, 2 locations, one named Casa and the other Home
Now I have in the Casa

  • samsung hub
  • 5 simulated switch
  • My mobile phone
  • the aqara sensor

In the Home

  • 1 simulated switch

IFTTT see what I have in the Casa location, not in the Home, Alexa see what I have in the Home location not in the casa location

Here is what I would do. You will have to change your default location to casa if it isn’t already. I would unlink Alexa with ST. I would then delete the home location. I would then relink Alexa to ST.

It looks like things are confused because a second location was added when you accessed the wrong shard for your account.

It really looks like some kind of Odissey for me
This is what I did:

I deleted the Home location, unlink smartthings from Alexa then link again, Search for devices and …
They did appear! I was thrilled.
So I started to create the alexa routine but those new devices doesn’t show up in the when condition. Strange as in the home they do appear no matter what. It does appear another test device that I configured as Simulated Alexa Switch using a custom handler that I found online. Then I try selecting this and it tells me “Device not supported at the moment”. Damn!
Everything was working smothly when I tested it in the Home location.

I am going to try and help with the Alexa but, honestly, I’m a Google user and have not had any experience with Alexa devices within ST. If I ask stupid questions, that’s why.

Can you point me to the device handler you found?

Also, what are you trying to do? If I knew that I might be able to offer other (maybe simpler) ways to fo what you want.

If I can do it with google it’s the same for me.
What I’m trying to do is:

I have a shelly relay that turn on the main light of the room if I click a button. In the shelly app I can add a call to a url when a button is turned on or off. As I have other lights in that room I would love to turn them on when I click on the button to turn on the main light.

pretty simple

the code is this

I’m in the US so I’m not real familiar with your devices so I’m going to ask a couple questions here. BTW, Google won’t do what you want.

Do you actually have the Alexa assistant device or are you just using the app because it has routines?

You have the Shelly relay and Smartthings sees that, what are you using to control the other lights and is Smartthings seeing the other lights?

What’s the aqara sensor used for?

What are you using the simulated switches for? FWIW, I would create virtual switches instead of simulated switches. There have been reports of issues with virtual switches.

Do you have the new Smartthings app or the classic app loaded on your phone?

Answer these questions and we will go from there.

Thanks a lot for your patience, I’m going to try to answer all tour questions:

I do use 5 echo in my home so it’s not just the app

No, smartthings doesn’t see anything of my devices, if It would I should have solved all my Issues. Unfortunately shelly As Well As xiaomi for example or meros are not compatible with smartthing

Just to measure temp and humidity but it’s not strictly related to my issue

The flow is this one: i turn on the light of the room clicking on the button, shelly calls a Url configured As webhook in ifttt. When that Url is called ifttt open the virtual switch. When that switch is open alexa should trigger a routine that turn on other lights (that was my main problem I was trying to address, turn other lights on when i click on a button)

The one included in my Samsung phone

Try using the Classic App! Be sure to authorize the devices in the Classic App IFTTT section of Apps. Be sure to press save. Also make sure you are in the correct location.

Locations:

So your just using smart things for the virtual switches? Correct?

I am assuming that IFTTT can’t see whatever device is controlling your other lights.

At the Moment yes, i’m trying to use It just for that and maybe some Door sensor i would like to install It the work

At the Moment my problem is with alexa not seeing my simulated switch or seeing them but not usable to fire routines, why changing the app should help me on that? I’m going to try It anyay

I know in the forums I’ve seen references to some cloud interaction with Shelly and smart things. People are also using xiomi in smartthings too. Is your other device meros or meross?

Can you list model #'s of devices

Alexa is not seeing switches as triggers for routines because Alexa cannot use a switch as a trigger for a routine to do what you want, you need a specific type of virtual switch that shows up as BOTH a switch and a contact sensor because Alexa CAN trigger on a contact sensor.

Now that you have your location issues sorted (good job BTW) Search the forums - there’s a post that details exactly how to setup the kind of virtual device you’re going to need.

1 Like

Thanks for jumping in. I was hoping that someone with some Alexa insight would.

1 Like

Yep you guys got him to fix the location issues which honestly was the harder issue to work through. I’m mobile or I’d link straight to the post with the DTH you need. If we’re lucky someone will jump on with that link.

1 Like

Change the device type in IDE from a virtual switch to a simulated garage door opener. Open for on, closed for off. Discover devices. Create your routines. One for on, one for off. This is how I use my roborock with Alexa routines.

1 Like

Thanks a lot for your support,

first of all I finally was able to do it. How? Really don’t know. I was out from home for some hours and the only thing I did was to install the SmartThings classic app. When I got back home I tried again to make a routine and it worked. So what’s the problem now? It’s that when I turn on the main light with the phisical button, the event that turn on the other lights fire in about 10 seconds. A little bit too much. I don’t know if it’s alexa or iftt or the shelly url call that is taking so much time but it’s a huge time.

Excellent! I found them! In particoular I found this post

and I was able to configure the shelly in smartthings. Unfortunately I’m not able to use those as alexa routine trigger so I’m still stuck. I was trying to change the handler code to set those switch as sensor as well but the problem is that it works if I turn it on/off via the app but not using the phisical button, in this case it doesn’t change the status of the simulated sensor. This is the modified code but I think I’m missing something

    /**
 *  Shelly as Switch Device Handler
 *
 *  Copyright 2018 DUCCIO GASPARRI
 *
 *  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.
 *
 *
 *
 * Shelly http POST at http://IP/relay/0 ( can be 0/1 for shelly 2) with body form-urlencoded:
 *   turn=on
 *   turn=off
 *   ison=boolean
 *
 */
 
 

metadata {
	definition (name: "Shelly as Switch or Sensor", namespace: "decarlim", author: "Mario De carli") {
		capability "Actuator"
		capability "Sensor"
        capability "Refresh" // refresh command
        capability "Health Check"
        capability "Switch"
        capability "Contact Sensor"	 
	}

    simulator {
		status "open": "contact:open"
		status "closed": "contact:closed"
	}

    tiles(scale: 2) {
        multiAttributeTile(name:"switch", type: "lighting", width: 6, height: 4, canChangeIcon: true){
            tileAttribute ("device.switch", key: "PRIMARY_CONTROL") {
                attributeState "on", label:'${name}', action:"switch.off", icon:"st.Home.home30", backgroundColor:"#00A0DC", nextState:"turningOff"
                attributeState "off", label:'${name}', action:"switch.on", icon:"st.Home.home30", backgroundColor:"#FFFFFF", nextState:"turningOn", defaultState: true
                attributeState "turningOn", label:'Turning On', action:"switch.off", icon:"st.Home.home30", backgroundColor:"#00A0DC", nextState:"turningOn"
                attributeState "turningOff", label:'Turning Off', action:"switch.on", icon:"st.Home.home30", backgroundColor:"#FFFFFF", nextState:"turningOff"
            }
        }

        standardTile("explicitOn", "device.switch", width: 2, height: 2, decoration: "flat") {
            state "default", label: "On", action: "switch.on", icon: "st.Home.home30", backgroundColor: "#ffffff"
        }
        standardTile("explicitOff", "device.switch", width: 2, height: 2, decoration: "flat") {
            state "default", label: "Off", action: "switch.off", icon: "st.Home.home30", backgroundColor: "#ffffff"
        }

        standardTile("refresh", "device.refresh", width: 2, height: 2, inactiveLabel: false, decoration: "flat") {
            state "default", label:'', action:"refresh.refresh", icon:"st.secondary.refresh", nextState: "disabled"
            state "disabled", label:'', action:"", icon:"st.secondary.refresh"
        }


        main(["switch"])
        details(["switch", "explicitOn", "explicitOff","refresh"])

    }


    preferences {
        input("ip", "string", title:"IP", description:"Shelly IP Address", defaultValue:"" , required: false, displayDuringSetup: true)
        input("channel", "string", title:"Channel", description:"Channel (only for Shelly2):", defaultValue:"0" , required: false, displayDuringSetup: true)
    }

}


def getCheckInterval() {
    // These are battery-powered devices, and it's not very critical
    // to know whether they're online or not – 12 hrs
    log.debug "getCheckInterval"
    return 4 * 60 * 60
}

def installed() {
    log.debug "Installed"
    sendEvent(name: "checkInterval", value: checkInterval, displayed: false)
    refresh()
}

def updated() {
    log.debug "Updated"
    if (device.latestValue("checkInterval") != checkInterval) {
        sendEvent(name: "checkInterval", value: checkInterval, displayed: false)
    }
    refresh()
}


def parse(description) {
    log.debug "Parsing result $description"
    
    def msg = parseLanMessage(description)

    // log.debug "Lan message $msg"
    // headers:[content-length:172, http/1.1 200 ok:null, connection:close, content-type:application/json, server:Mongoose/6.11], 
    // body:{"state":"close","power":0.00,"is_valid":true,"safety_switch":false,"stop_reason":"normal",
    //    "last_direction":"close","current_pos":46,"calibrating":false,"positioning":true}, 
    // header:HTTP/1.1 200 OK 
    
 
    def headersAsString = msg.header // => headers as a string
    def headerMap = msg.headers      // => headers as a Map
    def body = msg.body              // => request body as a string
    def status = msg.status          // => http status code of the response
    def data = msg.data              // => either JSON or XML in response body (whichever is specified by content-type header in response)
    
    log.debug "Data"
    log.debug data
    
    def evt1 = null
    if ( data.ison == true ) {
        log.debug "CreateEvent ison=true"
        evt1 = createEvent(name: "switch", value: "on", displayed: false)
        sendEvent(name: "contact", value: "open")
    } else  {
        log.debug "CreateEvent ison=false"
        evt1 = createEvent(name: "switch", value: "off", displayed: false)
        sendEvent(name: "contact", value: "closed")
    }

    return evt1
}


//switch.on
def on() {
    log.debug "Executing switch.on"
    sendSwitchCommand "turn=on"
    sendEvent(name: "contact", value: "open")
}

//switch.off
def off() {
    log.debug "Executing switch.off"
    sendSwitchCommand "turn=off"
    sendEvent(name: "contact", value: "closed")
}



def ping() {
    log.debug "Ping"
    refresh()
}

def refresh() {
    log.debug "Refresh - Getting Status"
    sendHubCommand(new physicalgraph.device.HubAction(
      method: "GET",
      path: "/relay/" + channel,
      headers: [
        HOST: getShellyAddress(),
        "Content-Type": "application/x-www-form-urlencoded"
      ]
    ))
}

def sendSwitchCommand(action) {
    log.debug "Calling /relay/ with $action"
    sendHubCommand(new physicalgraph.device.HubAction(
      method: "POST",
      path: "/relay/" + channel,
      body: action,
      headers: [
        HOST: getShellyAddress(),
        "Content-Type": "application/x-www-form-urlencoded"
      ]
    ))
    runIn(25, refresh)
}


private getShellyAddress() {
    def port = 80
    def iphex = ip.tokenize( '.' ).collect { String.format( '%02x', it.toInteger() ) }.join().toUpperCase()
    def porthex = String.format('%04x', port.toInteger())
    def shellyAddress = iphex + ":" + porthex
    device.deviceNetworkId = shellyAddress.toUpperCase()
    log.debug "Using IP " + ip + ", PORT 80 and HEX ADDRESS " + shellyAddress + " for device: ${device.id}"
    return device.deviceNetworkId
}

What I found is this one:

That also need to install something on my synology NAS. I will try to see if I can do something with that

The problem is that I have different devices by different manufacturers (meross, tplink, xiaomi, yeelight, some smart life devices, etc…) and the only software that can handle all of these is Alexa

I know that and that is in fact the handler I’m using right now, before I tried with this one but it wasn’t working. Don’t know why

© 2019 SmartThings, Inc. All Rights Reserved. Terms of Use | Privacy Policy

SmartThings; SmartApps®; Physical Graph; Hello, Home; and Hello, Smart Home are all trademarks of the SmartThings, Inc.