PLUGIN: Virtual Alarm Panel (UI7) - V0.1

Only compatible with UI7

Introduction

This plugin allows to manage a virtual panel of alarms.
It’s designed to present, add, sort easily the alarms and mainly to handle acknowledgement for active alarms.

Installation

This is the beta version and is still in development.
You will find the plugin here : MiOS Apps

Usage

  • Dashboard : just shows the active alarms (and acknowledgement).
  • Plugin panel : shows all the alarms and allows to manage them (add, delete, move, acknowledge, …).

Activation and deactivation of alarms are done by luup.

Alarm status

local myPanelId = 123               -- Device ID of Virtual Alarm Panel
local myAlarmName = "Porte garage"  -- Name of the alarm

-- Activate alarm
luup.call_action("urn:upnp-org:serviceId:VirtualAlarmPanel1", "SetAlarmStatus", { alarmName = myAlarmName, newStatus = 1 }, myPanelId)

-- Deactivate alarm
luup.call_action("urn:upnp-org:serviceId:VirtualAlarmPanel1", "SetAlarmStatus", { alarmName = myAlarmName, newStatus = 0 }, myPanelId)

Watch alarm status
For the moment it’s just possible by luup code.

local myPanelId = 123               -- Device ID of Virtual Alarm Panel
local myAlarmName = "Porte garage"  -- Name of the alarm

function onAlarmIsActivated (lul_device, lul_service, lul_variable, lul_value_old, lul_value_new)
	if (lul_value_new == alarmName) then
		-- The alarm has just been activated
		-- *** Your code here ***
	end
end

luup.variable_watch("onAlarmIsActivated", "urn:upnp-org:serviceId:VirtualAlarmPanel1", "LastActiveAlarmName", myPanelId)

Alarm acknowledgement
For scalability reasons, the alarm informations are not stored individually in variables, but in a JSON array.
That’s why the acknowledgement information can not be retrieved in a variable, but has to be computed.

Here is an example of code you can put in a scene to decide if something has to be done according to the alarm acknowledgement.

-------------------------------------------
-- Helpers
-------------------------------------------

DeviceHelper = {
	-- Get device id by its description (or id)
	getIdByName = function (deviceName)
		local id = nil
		if (type(deviceName) == "number") then
			id = ((luup.devices[deviceName] ~= nil) and deviceName or nil)
		elseif (type(deviceName) == "string") then
			for deviceId, device in pairs(luup.devices) do
				if (device.description == deviceName) then
					id = deviceId
				end
			end
		end
		if (id == nil) then
			luup.log("[DeviceHelper.getIdByName] " .. tostring(deviceName) .. " doesn't exist", 1)
		end
		return id
	end
}

VirtualAlarmPanel = {
	isAlarmAcknowledged= function (panelName, alarmName)
		local panelId = DeviceHelper.getIdByName(panelName)
		if (panelId == nil) then
			return nil
		end
		local lul_resultcode, lul_resultstring, lul_job, lul_returnarguments = luup.call_action(
			"urn:upnp-org:serviceId:VirtualAlarmPanel1",
			"GetAlarmAcknowledge",
			{ alarmName = alarmName },
			panelId
		)
		if (lul_resultcode == 0) then
			if (lul_returnarguments.retAcknowledge == "1") then
				-- Alarm is acknowledged
				return true
			elseif (lul_returnarguments.retAcknowledge == "0") then
				return false
			end
		end
		-- Can't retrieve acknowledgement
		luup.log("[VirtualAlarmPanel.isAlarmAcknowledge] Can't retrieve acknowledgement for panel " .. tostring(panelName) .. " and alarm " .. tostring(alarmName), 1)
		return nil
	end
}
if (VirtualAlarmPanel.isAlarmAcknowledged("My alarms", "Garage door opened"))
	-- *** Your code here ***
end

or

if (VirtualAlarmPanel.isAlarmAcknowledged(123, "Garage door opened"))
	-- *** Your code here ***
end

Sources

The v0.1 is available on the store :
http://apps.mios.com/plugin.php?id=8236

Is there user documentation?

Just the plugin description.
There’s a version (not on apps.mios.com) which can work with RulesEngine (http://forum.micasaverde.com/index.php?topic=34489.0) without need of LUA script.
Tell me if you want to test it.

I know this is old but I am picking up interest in running this on openLuup to have an alarm device which could be a notification center for various alarm events. Right now after installing it, I am not able to add/delete any alarm. I am not quite sure why yet. I could add them by lua code by adding the Json array as a variable?