sendPush() not working

I have a custom device handler (classic SmartThings developer tools - written in groovy). Everything is working but I can’t seem to get “sendPush(message)” to do anything at all. It doesn’t send push messages to my iOS device (old app or new app). Notifications are definitely turned on as I do get notification for other actions setup with the new app UI it self (automations). I’m a bit new to all of this, so maybe a silly mistake on my part. Any ideas?

Hello @mikescopa1992

Would you please share with me a description of your device handler or a snippet? This way I can see what you are trying to achieve and try to help you find an alternative.

Sure. Here is a section of code. Everything works - except the sendPush doesn’t do anything… I know it is getting there because I get the traceevent text right before it.

// Scopa - Check if single room too warm when cooling
traceEvent(settings.logFilter,“JudithE Mode {currentMode} {thermName}”, true, GLOBAL_LOG_INFO, true)
if (currentMode == ‘cool’) {
Calendar cal = Calendar.getInstance()
def currentHour = cal.get(Calendar.HOUR_OF_DAY) - 4
if (currentHour < 0) {
currentHour = 24 + currentHour
traceEvent(settings.logFilter,“JudithE Init {currentCoolingSetpoint} {actualTemp} {tooWarmTemp} {thermName}”, true, GLOBAL_LOG_INFO, true)
// Only cool TV room between 10am and 10pm
if (thermostatId == ‘411946300936’ && currentHour >= 10 && currentHour <= 21 && actualTemp >= tooWarmTemp) {
if (currentCoolingSetpoint != holdCoolTemp) {
// Hold TV Room at holdCoolTemp and others higher
// TV Room
// Second Floor
traceEvent(settings.logFilter,“JudithE Held at {holdCoolTemp} {thermName}”, true, GLOBAL_LOG_INFO, true)
sendPush(“Family Room Thermostat adjustment complete”)
else {
traceEvent(settings.logFilter,“JudithE Already Held at {holdCoolTemp} {thermName}”, true, GLOBAL_LOG_INFO, true)
else {
traceEvent(settings.logFilter,“JudithE OK at {actualTemp} {thermName}”, true, GLOBAL_LOG_INFO, true)

Hi @mikescopa1992,

Instead of sending a push notification, you could send a command to a virtual device, for example, a Dimmer using the SwitchLevel capability and, in the mobile app, create an automation to send the notification based on the value change. You can use one device for many events and later, the migration of your SmartApp from groovy will be smoother.
For example:

//preferences configuration
preferences {
	section("Title") {
		input "dimmerswitch", "capability.switchLevel"
//send the command

Note: I recommend you to start using the non groovy-based tools such as SmartApp SDK, Rules API because of the upcoming changes.

1 Like

Thank you. I will definitely try this. Sorry for silly question, but I’m new to this. I created the virtual device (simulated switch). Where do I put the code you included? In a device controller for the new virtual switch or in the device controller for my thermostat?

Hi @mikescopa1992,
The sample I shared with you belongs to the SmartApp as well as the sendPush() command.
Also, please note that the Virtual Switch doesn’t have the switchLevel capability, for this you should choose Virtual Dimmer Switch.

If this answers your question, can you mark it as Solved, please? If not, let me know what’s going on and we can dig in further

1 Like

I believe sendPush() only works in a SmartApp, not a Device Handler.

Also, no need to add another virtual device. You could simply modify your existing custom DTH to include additional Capabilities that could be used to trigger an Automation or other SmartApp to send the push notification.

1 Like

Thank you! Got it working - appreciate the help

Yeah that was probably the problem. Got it working. Thanks everyone.