Allow rule status as dashboard items


The dashboard allows the addition of devices. But I'd like to display the status of the rules I've created. This would be especially useful for complex, multi-sensor rules. For example, "Any window is open" could be created with a rule and displayed on the dashboard with its truth value.


This is simple to do. You just create a virtual device with the code I pasted below and call it "Any Window" for example. Then in a RM Rule, you select all your contact sensors for the RM Condition. The action for True is to turn on the virtual device "Any Window".

In Dashboard, you assign the Window attribute to the "Any Window" virtual device. So when any window contact sensor is open, your dashboard icon will turn Red and show the status for Any Window as Open

 *  Virtual Contact Sensor as Switch
 *  Based on original code by Chris Wilson
 *	Copyright 2018 Chris Wilson
 *  Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
 *  in compliance with the License. You may obtain a copy of the License at:
 *  Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
 *  on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
 *  for the specific language governing permissions and limitations under the License.
 *  Change History:
 *    Date        Who            What
 *    ----        ---            ----
 *    2018-10-01  Chris Wilson 	Original Motion Sensor as Switch
 *    2019-04-15  Doug Krug  	Modified for Contact Sensor as Switch

metadata {
	definition (name: "Virtual Contact Sensor as Switch", namespace: "smarthomeprimer", author: "Doug Krug") {
		capability "Sensor"
		capability "Contact Sensor"
        capability "Switch"

def on() {
    sendEvent(name: "contact", value: "open")
    sendEvent(name: "switch", value: "on")
    runIn(12, off)

def off() {
    sendEvent(name: "contact", value: "closed")
    sendEvent(name: "switch", value: "off")

def installed() {