Write to activity feed from SmartApp

I have seen code examples for sendPush(msg) but I want to just write to the activity feed and not send a push message. How do I do this?

log.debug nope
log.trace nope
log.info ?
log.warn ?

1 Like

sendNotificationEvent( String )


As far as I can tell, sendNotificationEvent writes to the main activity feed, but what about to a particular device’s activity log?

Does not work in Device Types:

12:41:14 AM: error groovy.lang.MissingMethodException: No signature of method: script1415684285914308354464.sendNotificationEvent() is applicable for argument types: (org.codehaus.groovy.runtime.GStringImpl) values: [Set Heating point to 61.0] @ line 341

c45dc2e0-2f12-48ba-89ab-2cb845a687a1 12:46:45 AM: error groovy.lang.MissingMethodException: No signature of method: script14156848054681329331708.sendNotificationEvent() is applicable for argument types: (java.lang.String) values: [Set Heating point to] @ line 341

I can confirm the same, so how does one write the activity feed for the device?

pulled this from the z-wave motion device

example 1

createEvent(name: "motion", value: "active", descriptionText: "$device.displayName detected motion")

example 2

def zwaveEvent(physicalgraph.zwave.Command cmd) {
	createEvent(descriptionText: "$device.displayName: $cmd", displayed: false)

example 3

createEvent(descriptionText: "$device.displayName covering was removed", isStateChange: true)

Thank you, is this also the same way to log events from a smart app incase you know?

BTW does this post the main activity feed or the device activity feed?

Interestingly I tried all of the above and some combination but I don’t see anything reported in the main event activity log or device event activity log. I guess this doesn’t work in Smart apps.

@docwisdom were you able to figure out if you can get the log to show up in the activity?

@tslagle13, @minollo @bflorian - wondering if you guys could shed some light on how SmartApps can post to the activity log of a device?

Wondering if a smartapp can do this. They may be walled off from the activity feed. What do you see in the logs when you run a createEvent command?

Why would an app post to the activity log of a device? A device can/should do that, not the app. In my own device types, I do that using sendEvent() - or createEvent(), depending on the context where it’s used.

1 Like

That’s correct. createEvent() should be used to construct the event object returned by the parse method. It only works from inside parse. Use sendEvent() from other contexts, such as a command method.

1 Like

Thanks @bflorian so is that the right way to send a message from a SmartApp to a device activity feed using sendEvent()?

@minollo Here’s what happening, I have a thermostat program. When it changes the temperature for a device I want it to write to the device feed that it changed the current temperature to XXX AND also write when the next temperature change is scheduled.

Apps don’t do sendEvent(); devices do.

Apps can invoke device methods freely, I believe; so, I suppose you could add an advanced version of the device setHeatingSetpoint() method, make it handle both a requested temperature change and a timestamp setting, and create an event (setEvent()) for the timestamp setting.

Of course that also implies that you need to add a custom “attribute” to your device, something like:
attribute “nextScheduledTemperatureChange” “date” (or “string”, if “date” is not supported) in the metadata/definition section.

That’s right – a custom command actually.

There is no way to explicitly send an event from a smart app to a device’s activity feed. When you change the temperature you should see an event like “Good Morning sent setHeatingSetpoint command to Dining Room Thermostat”, but there is currently no way for you to customize that message or create an additional one.

If you are writing the device type as well as the smart app, you could create a custom command to generate an event with the message you want and call that command from the smart app, but that wouldn’t work with any thermostat.

I do understand your scenario and we’ll take a look at how we might make these app-to-device messages more useful. The default ones are admittedly not very user-friendly in some cases.

Thanks, BTW so I write a custom device type for thermostat (which I"ve also submitted to ST for publishing, more features).

I put this statement in the setHeatingPoint function:

sendEvent(name: $device.displayName, value: “Set heating point to $degrees”)

and it errors out:

c45dc2e0-2f12-48ba-89ab-2cb845a687a1 1:23:26 PM: error java.lang.NullPointerException: Cannot get property ‘name’ on null object @ line 341

The same thing happens with label and name. This is on a live thermostat (not simulator) so I’m guessing there’s a bug in there which is returning null for name and label

You need to omit the $ character in the value of the name field. It’s only needed inside a string. In other words:

sendEvent(name: device.displayName, value: "Set heating point to $degrees")

However, the name of the event shouldn’t really be name of the device, it should be the name of the property. So I would do something like this:

sendEvent(name: "heatingSetpoint", value: degrees, descriptionText: "Set heating setpoint to $degrees")
1 Like