Can "On/Off Button Tile" be altered to not maintain state?

(Ron) #1

I am using a “On/Off button Tile” as a hack to make another device work with my Harmony Home remote.

I map this “Virtual Button” to my “Real Device On/Off methods” using the smart app “The Big Button”

So when “Virtual Button” is turned on I have "The Big Button " configured to issue the “On” command and vis versa.

The problem is if the “Real Device” state is “On” but the virtual button state is “Off” then issuing a “Off” command to the virtual button doesn’t seem to fire “The Big Button” to switch on off the “Real Device”. I think because the device is seeing it’s state is already “Off” and not changing state therefore the subscription from the Big Button is not issued.

Can I alter “On/Off Button Tile” so it doesn’t know it’s state and always issue the state change ?

I had the idea to add two more states lets call them “off2” and “on2”. Then in my on method I can check the current state and switch to the other.

The problem is then I have to also rewrite the BigSwitch to act on both on/off as well as the on2/off2 states…not even sure that will work ?

Is there a way I can generate the On event for subscribers to see even if the switch is already on ?

A second thought I had was to alter the on/off methods to issue two event changes instead of toggling on/on2 I could just issue event “on” then event “on2”. I could do the same for off…issue off and then off2.

This would leave the device always in the “on2” or “off2” state.
Now any on or off method calls would issue two state changes
on -> on and on2
off -> off and off2

and the subscription would be honored…I think.

Does this make sense or should the subscription always be honored and I am barking up the wrong tree here.

Sorry if this is confusing. Hard to describe what is going on.

BTW: Why does “On/Off Button Tile” have capability “Sensor”, that doesn’t make sense to me.


Can you use a momentary switch instead? This is the kind of switch where you press it, it makes contact, then it pops back to the unpressed state. Not a binary switch that stays on until you turn it off again.

That’s the typical physical world way to solve this kind of issue. But I don’t know if the code you’re using works with momentary switches.

(Scott G) #3

I’ve typically leaned on momentary switches for this reason too, but it typically means more virtual buttons and fewer devices you can affect with the Harmony Home. With on/off virtuals, you could use the Home’s 4 buttons to activate 8 different actions.

I think what you want is for the events that get created by the On/Off button to always be considered a state change. There is a parameter for this isStateChange that can be set in the event statement. So create a new DeviceType from the On/Off Button Tile code and add isStateChange: true to the sendEvent commands (not sure if true needs to be in quotes of some kind).

This may not work if ST is smart enough to know the virtual button is ‘on’ and won’t send the ‘on’ command to it, otherwise it should always send the event regardless of its current state.


Another real world synchronization hack is to have the first switch always send two events, the one you don’t want followed by the one you do.

So if you want On, you send Off then On.

If you want Off, you send On then Off.

This “unsticks” any out of synch devices, but doesn’t affect the ones that ignore a no change event.

Of course it all depends on the use case. But it has the advantage of not requiring additional devices.


(Ron) #5

@Sticks18 I will try the isStateChange that is exactly what I was looking for.

@JDRoberts another good idea but I think this would break the button tile in the ST app. One press would set the state to On/Off next press would do the same so Off is the only result state from the app.

I decided to try my idea and ti worked perfectly. The code is here for what I am calling “Stateless On/Off Button Tile”. It works with the harmony and still displays it’s last known state in the ST app. The trick is to have 4 states but have only two of them toggle for the ST app. So I have On/Off and OnReady/OffReady. The two “Ready” states are the only two that toggle back and forth in the app. Then my on method sends On and OnReady events always issuing on for the subscription listeners to see and resulting in OnReady, Off sends Off and OffReady events for off listeners to see with end state always being OffReady.

It works like a charm. I like the “isStateChange” force better since it is less confusing by if it doesn’t work this solution is fine. If the isStateChange idea works I will post back here with results and include that version of the code as well.
It is easier to understand in code so here is the code to have a look if you are interested.

Thanks guys for the feedback, two great ideas that I can use to continue my efforts.

(Ron) #6

I tried @Sticks18 isStateChange: true attribute and it worked like a charm. I like this solution better than my Stateless On/Off Button Solution but they both work so I decided to keep both in my Repo for future reference.

I also added two more buttons to the new device which allows discrete on or off commands.
This is usefull for when the device gets out of sync with the button. So when my AC is ON but the toggle button still says “Off” I can just press the discrete “Off” to shutoff the AC and the toggle button will remain “Off” Instead of having to toggle to ON and Back to Off.

I decided to rename this version to "Always Notify State On/Off Button"
Code is here if anyone want’s to try it.