Output Messages
Updated February 28, 2022 by crxporter, Shaquu and GogoVegaWhich Output to choose?
Below is a table with the Output description for the Service Node:
Order | Output | Description |
---|---|---|
Top | onChange |
Outputs a message only if a value changes, this is the most recommended Output in most cases. |
Bottom | onSet |
Outputs a message at each set value (even if the value has not changed), it is used to capture repeated inputs like TV remote buttons. |
Third* | camera snapshot |
Is displayed only for Camera Control service and is used to retrieve camera snapshot data. |
Differentiate between passthrough or “from HomeKit” messages
In some cases, it may be useful, even essential, to differentiate a command from the previous node or Home.app to avoid a loop problem. There are two possible cases:
Disable messages passthrough
The first solution is to disable passthrough messages, which will cause your HomeKit node to no longer send messages from your previous nodes. If you need to keep passthrough messages, used the second solution.
Use hap.session characteristics
The second solution is to use the hap.session
feature, which is generated when the command comes from the Home.app:
Starting with version 1.3.0
, there are some changes in the hap
part of the messages coming from this node.
Previous versions would have msg.hap.newValue
and msg.hap.oldValue
only if the message originated from the Home.app. Additionally, there was a message part msg.hap.context
with some information that nobody knows what it means, but it was there.
From version 1.3.0
on, the parts of the message will always include msg.hap.newValue
and msg.hap.oldValue
. If the message originated from the Home.app (iPhone, iPad, Mac, or Home Hub automation) then the message will contain msg.hap.context
(deprecated, will be empty object {}
), and the new part msg.hap.session
.
Note, msg.hap.context
is left for compatibility with previous versions of the plugin but is considered deprecated and will be removed in version 2.0.0
. Please transfer your flows to use msg.hap.session
instead.
The new message part msg.hap.session
will exist only if the message is initiated from the Home.app. This object will include the following:
msg.hap.session.sessionID
: UUID unique to each HAP connectionmsg.hap.session.username
: A unique identifier for each user, essentially a random string that will be different for each Apple ID your home is shared withmsg.hap.session.remoteAddress
: the IP address where the message came from (iPhone, iPad, computer, Apple TV, HomePod, etc)msg.hap.session.localAddress
: the IP where your HomeKit Bridge lives, will match wherever you host Node-RED
The msg.hap.session
object can therefore be used to determine who or which device is initiating changes to your setup.
To do this, nothing could be simpler, add to the output of your HomeKit node a
function node
in which you insert this:
if (msg.hap.session) {
// Do stuff if it's from HomeKit
return msg;
} else {
// Do different stuff if it's not from HomeKit
return;
}