RegisterMessage for creation of child link object

I am building a module and it would be nice if the module could notice the creation of child link objects. I have used RegisterMessage and MessageSink methods before in other modules to receive VM_UPDATE messages (variable update). Browsing through the list of messages I thought LM_CREATE („Link wurde erstellt“) might be useful, however since you need to set a SenderID when registering a message I assume it only works when you already know the id of the object. Since I want the module to respond to the creation of new objects, the object Id is not known beforehand.

Is there any way a module can receive messages about the creation of new (link) objects?

You are totally right, that at the moment the *_CREATE messages are not very useful. I don’t not know for a workaround yet. I would probably call it a missing feature.

Can you give me a little bit of insight what you want to accomplish?

paresy

I was working on a simple module that duplicates its status to other instances. One example of its usage is a room temperature controller that has one output instance for the heating valve or electrical heating device. Sometimes a room is heated by multiple loops with independently controllable valves. Instead of having to deal with the possibility that I might need to control multiple instances in every module I build (the same problem applies to lighting and other applications), I can just have the duplicator module in between to duplicate the status to multiple instances.

I started out with a configuration form to select the target instances, but then I thought it would be nice to see which instances are controlled by the module in the tree view of the management console. Then I thought it would be nice to be able to add instances to the module by simply adding them as a child link object of the module. In that case it would be nice if the module could be noticed about the creation of a child link object.

In this case it is not really necessary because I could just loop through child link objects every time the status variable of the module changes. I am about the build another module that calculates the average value of multiple variables (used for example to calculate the average temperature in a room with multiple temperature sensors). If I would use the same principle (use child links as the source variables) it would be ideal to be able to notice the creation of a new link so the module can register a VM_UPDATE / 10603 message on the target variable of the link.

I use the OM_CHILDADDED and OM_CHILDREMOVED on my module to get the messages when a link (object) is created.

Take a look at
IPSNoTrigger/module.php at master · Nall-chan/IPSNoTrigger · GitHub


    public function ApplyChanges()
    {
        $this->RegisterMessage(0, IPS_KERNELMESSAGE); // for startup
        parent::ApplyChanges();
//....
//....
        $this->RegisterMessage($this->InstanceID, OM_CHILDADDED);
        $this->RegisterMessage($this->InstanceID, OM_CHILDREMOVED);
    }

    public function MessageSink($TimeStamp, $SenderID, $Message, $Data)
    {
        switch ($Message)
        {
            case IPS_KERNELMESSAGE:
                switch ($Data[0])
                {
                    case KR_READY:
                        $this->GetAllTargets(); //register variables for VM_UPDATE & VM_DELETE and register links for LM_CHANGETARGET
                        break;
                }
                break;
            case VM_UPDATE:
//
//
//
                break;
            case VM_DELETE: // unregister $SenderID for VM_UPDATE & VM_DELETE
//
//
//
                break;
            case LM_CHANGETARGET: // unregister old target and register for new target VM_UPDATE & VM_DELETE
//
//
//
                break;
            case OM_CHILDADDED: // register target for VM_UPDATE & VM_DELETE and register $Data[0] for LM_CHANGETARGET
                $IPSObjekt = IPS_GetObject($Data[0]);
                if ($IPSObjekt['ObjectType'] <> otLink) //no link
                    return;
//
//
//
                break;
            case OM_CHILDREMOVED: // unregister old target for VM_UPDATE & VM_DELETE and unregister $Data[0] for LM_CHANGETARGET
//
//
//
                break;
        }
    }


Michael