Need to write a virtual switch to turn on/off AC from harmony, is it possible?


(Ron) #1

I am trying to make the buttons on my Harmony control my AC On/Off. I tried adding Capability “Switch” to my thermostat and it worked…sort of…

When I linked it to my Harmony it was listed for authorization as both a thermostat and a switch. So I selected the switch and did NOT select thermostat.

But unfortunately once harmony recognizes it as a thermostat is assigned the following

  1. Button press = Select Thermostat (No idea what this does)
  2. Button hold = Thermostat off (This calls the off method of the thermostat which works since I only have one off method.
  3. Toggle up - temp up (not interested since there is not feedback to know what temp is set)
  4. Toggle down - temp down (not interested since there is not feedback to know what temp is set)

So I just want the Harmon to see the Switch but not the Thermostat.

Can I write a device which takes a thermostat as a preference and acts only as a switch passing On/Off calls to the thermostat “Cool” and “Off” methods ?

Is so any examples I can see to figure out how to have a preference which lets you select a thermostat ?

Or is this a smart app, if so how does it add capabilities so it looks like a device ?


(ActionTiles.com co-founder Terry @ActionTiles; GitHub: @cosmicpuppy) #2

Well… wish I could be actually helpful, but I’m offering moral support – i.e., I’m optimistic. If the Devices are in SmartThings, then there should be lots of ways for SmartApps to interconnect their Events.

Is the Harmony partially implemented by a Service Manager SmartApp? Do we have the source code for this SmartApp? If so, then it can be hacked to take additional Devices like Virtual Switches, or AC Controls as Preferences


(Kevin Tierney) #3

This shouldn’t be too difficult to do by modifying the “big switch” code that is in the IDE. Instead of calling a switch.on() you’d be calling the thermostat.cool() or whatever it’s called. What is the name of the method your device type uses for cool?


(Eric R) #4

You definitely don’t need to make a new device type to make this work. Harmony can turn on/off any switches. So, the first thing you need is a simulated switch. There is a nice service manager here for creating simulated switches:

Make it so Harmony can see that switch by adding it in the Harmony App. Then you just need a SmartApp that sees if the virtual switch gets turned on or off and turns your thermostat to cool/heat (which ever one you pick in the preferences) or off. This didn’t take me long to write:

/**
 *  Switch state to thermostat mode
 *
 *  Copyright 2015 Eric Roberts
 *
 *  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.
 *
 */
definition(
    name: "Switch state to thermostat mode",
    namespace: "baldeagle072",
    author: "Eric Roberts",
    description: "If the switch turns on - sets the thermostat mode to desired mode. If the switch turns off - sets the thermostat mode to off",
    category: "",
    iconUrl: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience.png",
    iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png",
    iconX3Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png")


preferences {
	section("Devices") {
		input "masterSwitch", "capability.switch", title: "Master Switch", required: true, multiple: false
        input "slaveTstat", "capability.thermostat", title: "Slave Thermostat", required: true
	}
    
    section("Preferences") {
		input "setMode", "enum", title: "Thermostat Mode when On", options:["cool", "heat"], required: true, multiple: false
	}
}

def installed() {
	log.debug "Installed with settings: ${settings}"

	initialize()
}

def updated() {
	log.debug "Updated with settings: ${settings}"

	unsubscribe()
	initialize()
}

def initialize() {
	subscribe(masterSwitch, "switch", "switchHandler")
}

def switchHandler(evt) {
	if (evt.value == "on") {
    	slaveTstat.setThermostatMode(setMode)
    } else {
    	slaveTstat.setThermostatMode("off")
    }
}

Hopefully this works for you! Enjoy!


(Ron) #5

@kevintierney Thanks ! Actually big switch will do the trick. I have already hacked my AC device code so it turns on the AC when On() is called and Off() is already a part of the api for thermostat.

So I can use big switch with only one switch to get this done. Should do the trick…

I can’t seem to find Big Switch…is it a device or a smart app ?

If the later what section is it in. If the former I didn’t see it there.


(Ron) #6

@baldeagle072 Combo of Big Switch and your virtual switch should do the trick.

I need to read more about “addChildDevice” that looks powerful…


(Ron) #7

Working ! Thanks everyone for the help.

To make my Harmony Remote assign a button to turn on/off AC I not have

  1. Virtual Switch - Required Device and Smart App
  2. AC IR control Hacked to act like a switch - Added on/off capability for Switch
  3. The Big Button Smart App - Assign Virtual switch to turn on/off AC IR switch.
  4. Harmony assigned to Virtual Switch quick press -> On, Long Press -> Off

Finally Done :smile:

All because Harmony didn’t allow me to assigned the AC IR as a switch. It sees that it is a Thermostat and assumes I want to control that :frowning:


(Scott G) #8

I wish Harmony was more flexible in how you assign the those home controls buttons. I want to use some of those buttons for scenes, so I’d like to have the short press and long press trigger different momentary switches that would then trigger the scenes. Harmony sees switch and expects me to want to turn it on with short press, off with long…

Still a great remote, but pretty terrible for home automation integration.


(Ron) #9

@Sticks18 You could write a smart app which watches for On/Off for a virtual switch and issues momentary trigger A for On and Momentary trigger B for Off. It would be an easy tweak of “The Big Switch”, taking a list of Momentary Switches when the main switch is turned on, and another list of momentary switches when the switch is turned off. Do you use actual momentary switches or virtual ? I could try to write this for you if you do not know how. I would need momentary switch to be virtual since I don’t have any.


(Scott G) #10

Thanks for the offer Ron! I can put it together. I’m just loathe to add even more clutter and virtual switches. I already have the virtual momentary switches that I use to trigger scenes via a smartapp; so this would add another virtual switch, plus another smartapp instance. All together, I’m up to 20 items just to provide some lighting scene controls for my basement.


(Ron) #11

Yea I can see how this could grow quickly. I am also finding it really difficult to remember how this stuff is set up. It is so rube goldberg that you forget. Virtual Switch Device, Smart App to create the switch, another smart app to control the switch, an IFTTT configuration on the switch, Harmony setup to configure activity…All that so I can play music when an event happens like motion in room or arrival home. Something in this chain is likely to fail anyway.

BTW: How do you implement scenes in ST ? I know the term from when I had a VeraLite but in ST they don’t really have to concept, unless you use modes to do the same I guess. But that seems different since only one can be active at a time.

I think the Harmony integration is dead unless they fix it in a way that lets me issue commands to my harmony from ST Hub.

I also wish the ST could launch a Harmony command and not just launch activities. Then I could use the Harmony hub as an IR sender. Learn individual IR commands, assign them to a device, include that device in all activities and now I can use my Harmony to control any IR device in it’s range. Fans, AC, Lights, Shades, etc. They are missing out on the potential power of this hub and ST.


(Scott G) #12

They’re not true scenes in the typical HA definition, but I’m using a modified version of a lighting control app by @aimc. I changed the trigger to use a virtual momentary switch, so the I don’t have to worry about its state. It then turns some lights off, some on, dims some to one level, and dims others to a different level. I only have lights as part of the “scene”, and I typically just have most turn off with a small group going dim.

definition(
    name: "Virtual Switch Control Lights",
    namespace: "aimc",
    author: "cbd@deyoungproperties.com",
    description: "Set a group of your light switches to specific levels, or turn them off, with the press of a single 'virtual switch'.",
    category: "My Apps",
    iconUrl: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience.png",
    iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience%402x.png"
)

preferences {
    section("Select momentary switch to monitor"){
        input "theSwitch", "capability.momentary"
    }
    section("Which light(s) to dim to Level 1:") {
        input "switches1", "capability.switchLevel", multiple: true, required: false
    }
    section("Level 1"){
        input "lvl1", "number", required: false
    }
    section("Which light(s) to dim to Level 2:") {
        input "switches2", "capability.switchLevel", multiple: true, required: false
    }
    section("Level 2"){
        input "lvl2", "number", required: false
    }
    section("Turn ON these lights..."){
        input "switch1", "capability.switch", multiple: true, required: false
    }
    section("Turn OFF these lights..."){
        input "switch2", "capability.switch", multiple: true, required: false
    }
}

def installed()
{
    subscribe(app, appTouch)
    initialize()
}

def updated()
{
    unsubscribe()
    subscribe(app, appTouch)
    initialize()
}


def appTouch(evt) {
    log.info evt.value
    if (lvl1){
        switches1.setLevel(lvl1.value)
    }
    if (lvl2){
        switches2.setLevel(lvl2.value)
    }
    if(switch1){
        switch1.on()
    }
    if(switch2){
        switch2.off()
    }

}

def onHandler(evt) {
    log.info evt.value
    if (lvl1){
        switches1.setLevel(lvl1.value)
    }
    if (lvl2){
        switches2.setLevel(lvl2.value)
    }
    if(switch1){
        switch1.on()
    }
    if(switch2){
        switch2.off()
    }
   
}

def initialize() {
    subscribe(theSwitch, "momentary.pushed", onHandler)
}

I’m one of the lucky few who got two Harmony hubs set up before the integration broke, so I can have ST control Harmony. I wish it was easier to have ST send individual commands, but there is a work-around for that too. I have a virtual switch that when I turn it on, it pauses the movie and brings up some lights by triggering a scene, then when I turn it off, it turns off lights again and resumes movie. It only took adding two new Harmony activities that were identical to my “Play Movie” activity with the added command at the end. I have ST trigger the right activity based on the virtual switch. More clutter and complexity, but it does work!


#13

Technically SmartThings’ Hello Home actions are limited options scenes, because they do allow you to have devices of different device classes take different action from the same trigger. So you could have one contact sensor for example, trigger A zigbee light to come on, the zwave coffee maker switch to come on, a different light to go off, The door to unlock, etc.

But it’s not the same as a fullfeatured rules engine, or scheduler. Nor does it give you any good way of viewing what you currently have set up from multiple schedulers. I literally have spread sheet taped to the door just so I can keep track of what turns on when. :scream:


(Andrew Cockburn) #14

Just for the record, that wasn’t my app, I left the original author’s detail in the author field although I changed the namespace. Can’t remember if I might have tweaked it slightly but I don’t want to steal any credit!