Sending events from one Device to another

Ive built a custom device handler for managing my alarm system, but I now was to have separate simulated sensors for each of the alarm zones. Ive seen a few cases on these forums about how to do it, but they are quite different in use case and seem to involve tons of complexity which I can’t believe is required…

Basically I have a web enabled device which is sending and receiving JSON strings to a custom device handler (identified by MAC address as its DNI in ST), this is then updating several tiles using various sendEvents. I would like to forward these events to a separate device in order to use more easily with things like CoRE (I have a simulated contact sensor that I have built to support open/close and active/inactive). If you could help with a few questions I feel like I can get back to making some progress myself again, thanks very much in advance!

  1. As I understand it one device cannot communicate with another, unless a SmartApp is involved? I would know the DNI of these sub devices as I would create them, but I cant find a method to search for a device based on a DNI.

  2. Assuming I need a SmartApp, are there any simple examples to show how I can pass a ‘send event style map’ to a custom SmartApp, and then the SmartApp will call the relevant device function (such as open()/close()…)

  3. In order to do the SmartApp based solution I believe I need to select connected devices in the preferences? If there is another option Id be happy to look at that too. I can see creation of childDevices, perhaps the SmartApp can be called with a ‘Setup’ procedure which searches for devices with a certain DNI, and if they do not exist then it creates them? Would that help since then they are childDevices?

  4. Or another options is that I have to subscribe the SmartApp to various events in the Alarm DTH, Im not sure how to do this since each of the tiles is a fairly custom file (I dont know how to specify a tile as a switch/sensor., which can be subscribed to)

Sorry for the basic questions but I find the documentation really hard to understand (partially as my Java skills are limited and Im more used to simple C style code, and partially as I think the documentation is quite spread out and I struggle to follow it).

Thanks again in advance :slight_smile:

For anybody looking to do something similar, I eventually sussed it with the subscribe process.

 *  Visonic alarm integration to give simulated zones

    name: "Visonic Zone Manager",
    namespace: "cjcharles0",
    author: "Chris Charles <cjcharles(at)gmail(dot)com>",
    description: "SmartApp to update each of the simulated devices based on Visonic zone information",
    category: "My Apps",
    iconUrl: "",
    iconX2Url: "",
    oauth: false

import groovy.json.JsonBuilder

preferences {
	section("Alarm Panel:") {
		input "paneldevice", "capability.polling", title: "Alarm Panel Device", multiple: false, required: true
		section("Zone Devices:") {
		input "zonedevices", "capability.sensor", title: "Visonic Zone Devices", multiple: true, required: false

def installed() {
	log.debug "Installed with settings: ${settings}"
	//Subscribe to relevant events from the paneldevice
def initialize() {
	//Cycle through a max of 31 zones (which is Visonic limit)
	for (def curzone = 1; curzone <= 31; curzone++) {
    	//Try and find a selected device with the correct DeviceID
    	def curzonedevice = zonedevices.find { it.deviceNetworkId == "visoniczone${curzone}" }
		if (curzonedevice) {
        	//We have a device that matches the name so subscribe to the relevant tile on the alarm device
        	log.debug "Zone " + curzone + ": " + curzonedevice
    		subscribe(paneldevice, "visonic"+curzone, rsmHandler)

def updated() {
    log.debug "Updated with settings: ${settings}"
    //Remove all subscribed devices
    //Now add them again

def rsmHandler(evt) {
    //First correct the tile name (visonic#) to the simulated device name (visoniczone#)
    def zoneText ='visonic','visoniczone')
    //Now try to find a device matching the simulated device name
	def zonedevice = zonedevices.find { it.deviceNetworkId == zoneText }
    log.debug "${} is now ${evt.value} (sending to ${zonedevice})"
    if (zonedevice) {
    	log.debug "Found a valid device so updating status"
		//Was True... Zone Device: Front Door Sensor at zone1 is closed
        //If the command was 'active' then automatically send an 'inactive' after 5 seconds
        if (evt.value == "active") {
        	//First to the Visonic Alarm tile (need to run command sendInactive(zone))
            //Secondly we also need to update the Simulated device