Hubitat Safety Monitor API

I am migrating a SmartThings custom application that automatically set SHM to Armed (away), Armed (home), and Disarmed. I would like for this application to do the same in Hubitat.

Is there an API call to set the HSM state? If so could you please provide examples of each state?

Bump…
@bravenel @patrick any suggestions on an API call I can execute from an app to set Hubitat Safety Monitor to a certain state?

In SmartThings I was using:
sendLocationEvent(name: “alarmSystemStatus”, value: “Value-Name”)

HubitatÂŽ Safety Monitor

Guide for Apps to Interface

Hubitat™ Safety Monitor (HSM) uses Hubitat Location Events to communicate with other apps.
It reports its state using an event named “hsmStatus”, and custom monitoring rule arming/disarming with “hsmRules”. It reports alert events with an event named “hsmAlert”. Apps can set the arm/disarm state of HSM with an event named “hsmSetArm”. These events and their values are summarized below.

hsmStatus
	armedAway		intrusion alerts for Away are armed
    armingAway      intrusion Away arming pending exit delay
	armedHome		intrusion alerts for Home are armed
    armingHome      intrusion Home arming pending exit delay
    armedNight      intrusion alerts for Night are armed
    armingNight     intrusion Night arming pending exit delay
	disarmed		intrusion alerts are disarmed
    allDisarmed     intrusion, smoke, water and custom alerts are disarmed

hsmRules
	armedRule 		descriptionText = name of HSM Monitoring Rule armed
	disarmedRule	descriptionText = name of HSM Monitoring Rule disarmed

hsmAlert
	intrusion		intrusion away alert
    intrusion-home  intrusion home alert
    intrusion-night intrusion night alert
	smoke			smoke alert
	water			water alert
	rule			descriptionText = name of HSM Monitoring Rule alert
    cancel          alerts cancelled
    arming          failed to arm due to open contact

hsmSetArm
	armAway		    arm intrusion alerts for Away
	armHome		    arm intrusion alerts for Home
    armNight        arm intrusion alerts for Night
	disarm			disarm intrusion alerts
	armRules		arm all HSM Monitoring Rules alerts
	disarmRules		disarm all HSM Monitoring Rules alerts
	disarmAll		disarm all alerts and all HSM Monitoring Rules alerts
	armAll			arm smoke, water and all HSM Monitoring Rules alerts
	cancelAlerts	stop all in progress alerts


Examples:

For app to subscribe to HSM status:
	subscribe(location, “hsmStatus”, statusHandler)

For app to subscribe to HSM alerts:
	subscribe(location, “hsmAlerts”, alertHandler)

For app to arm HSM:
	sendLocationEvent(name: “hsmSetArm”, value: “armAway”)

Handler example for HSM alerts:

def alertHandler(evt) {
	log.info “HSM Alert: $evt.value“ + (evt.value == “rule” ? ”,  $evt.descriptionText” : “”)
//    only has descriptionText for rule alert
}

Note: For armingAway, the number of seconds of exit delay is in the event data map as "seconds".

10 Likes

@bravenel Thank you very much for this. One followup question, how can I get the latest value for hsmStatus? In ST I used location.currentState() but that is throwing an error in Hubitat:
No signature of method: com.hubitat.hub.domain.Location.currentState() is applicable for argument types: (java.lang.String) values: [hsmStatus]

My code is:
location.currentState("hsmStatus")?.value

Should I be using currentValue() instead?

Case problem? You’ve got Location not location in your error code.

1 Like

Tried that and new error:

Cannot invoke method currentState() on null object

I’m having the exact same issue with location.currentState("hsmStatus").value

Simple answer is that we have not implemented currentState for HSM values yet. It's on our to do list...

As a temporary work around I subscribe to the events and put them into a state variable.
You need a state change to make it work but it does work

Andy

Thanks, my app does this, but I am trying to prevent a looping situation and need the actual value. I will see if I can work around this.

Hi Bruce. Any updates on implementing currentState for HSM/Location?

I think it's implemented. It would be location.hsmStatus. I believe it was in the most recent release.

1 Like

That worked. Thanks!

1 Like

@bravenel
I added this command to a method but when trying to save changes I get the following:

Invalid variable name. Must start with a letter but was: “hsmSetArm” . At [579:29] @ line 579, column 29.

Please advise.

When trying to save the app?

Yup

If you copied/pasted there's something weird going on with the quotes. Try replacing manually.

2 Likes

This works just fine, and the comment about quotes is no doubt your problem.

definition(
		name: "test app",
		namespace: "hubitat",
		author: "Bruce Ravenel",
		description: "test app",
		category: "Convenience",
		iconUrl: "",
		iconX2Url: ""
)

preferences {
    section {
    }
}

def installed() {
    initialize()
}

def updated() {
    initialize()
}

def initialize() {
	sendLocationEvent(name: "hsmSetArm", value: "blahblah")
}
1 Like

Indeed it was the problem. This is the 3rd time these quotations have got me. You'd think I would have learned by now. Thank you sir.

1 Like

Yes, something detestable about Discourse, for sure!