if anyone needs it i lashed up a quick Switch aggregator, basically if one of multiple switches are on it will switch on a virtual switch (if all off virtual switch will be off).
Use case motion and mode app, i have a tv and a projector in a room if either of these are on i didn't want the lighting automations to run, but with the built in app i could only have one or the other.
definition(
name: "Switch aggregator",
namespace: "Mark-C-UK",
author: "Mark-C",
description: "agrate switches many to 1",
category: "Convenience",
iconUrl: " ",
iconX2Url: "",
pausable: true
)
preferences {
section("Set you input and output devices for ${app.label}"){
input "InDevs", "capability.switch", title: "input devices to average", required: true, multiple: true
input "OutDev", "capability.switch", title: "output device - create a hubitat vitrual switch 1st", required: true, multiple: false
input "logEnable", "bool", title: "Enable debug logging", defaultValue: false
}
}
def installed() {
installer()
}
def updated() {
installer()
}
def initialize() { // Runs on startup
def randomSixty = Math.abs(new Random().nextInt() % 60)
log.info "Initialize running ${app.label} installer in ${randomSixty} seconds"
runIn(randomSixty,installer)
}
def installer(){
log.info "${app.label} installer"
if (InDevs && OutDev) {
subscribe(InDevs, "switch", change)
log.info "${app.label} installer subscribing"
change()
}
}
def change(evt){
if (logEnable) log.info "${app.label} change, device '${evt?.device}', event '${evt?.value}'"
String onoff = "off"
if (evt?.value == "on"){
//log.debug "on"
onoff = "on"
}
else for (dev in settings.InDevs) {
if (logEnable) log.info "${dev} ${dev.currentSwitch}"
if (dev.currentSwitch == "on"){
onoff = "on"
}
}
if (logEnable) log.trace "${app.label} sending value '${onoff}' to '${settings.OutDev}'"
settings.OutDev.(onoff)
}