Hubitat Safety Monitor API


#1

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?


#2

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”)


#3

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".


App and driver porting to Hubitat
HelloHome code in Smarttiles replaced for HSM?
Patched webCoRE for Hubitat (2018/09/09)
Hubitat Safety Monitor - Arm with button hold?
webCoRE for Hubitat Updates
HSM/Rule Machine Feature Request
Hubitat Safety Monitor App Migration
Patched webCoRE for Hubitat (2018/09/09)
Mode Change Alerts - RM system variables?
HSM & Location coding questions
#4

@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?


#5

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


#6

Tried that and new error:

Cannot invoke method currentState() on null object


#7

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


#8

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


#9

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


#10

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.


#11

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


#12

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


#13

That worked. Thanks!


#14

@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.


#15

When trying to save the app?


#16

Yup


#17

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


Compiler error
#18

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")
}

#19

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.


#20

Yes, something detestable about Discourse, for sure!