Trigger-state: report other value in custom output

I am trying to use Node-Red’s trigger-state node to send an alert, whenever the state of one of my connected UPSes changes. This works in a fashion, bit it only copies the actual state value (OL,OB, RB etc) into the msg.payload, so that it does not also carry the identity of which UPS triggered this, nor the battery runtime value

My two UPSes are named ‘UPS’ and ‘UPS-Living’ so the related entities are

  • sensor.ups_status_data
  • sensor.ups_battery_runtime
  • sensor.ups_living_status_data
  • sensor.ups_living_battery_runtime

I have defined a trigger-state node as follows:

which only fills in the sensor.ups_status_data. into the payload. So subsequent nodes have no info on which UPS triggered, nor what the remaining runtime is

I have tried working around this, by defining a custom output, that should emit a string
“remaining runtime: x.xxx”
and triggers (always) [ ie, whenever the ups_status_data changes ]

but it all it sends is ‘undefined: undefined’

How can I habe this look up the related entity and it value and interpolate it into teh custom output (or into the normal payload)?

Do you have your debug nodes set to complete message object?

Yes, it is said to show the complete msg
I have now split that into 3 debug nodes:
This shows the ‘undefined’ output from ‘debug 3’:

and the definition of the trigger state is

How to I get the actual value of that entity into the custom output?

Can you fully expand the message that is going to debug 1. In that message you should be able to see the value you are looking for.

I’m not sure what debug1 has to do with it, as that gets the positive output. I am interested in how to get another entity reported in the ’ custom output’ which goes to debug3

But here goes:

16/10/2024, 09:19:11node: debug 1
sensor.ups_status_data : msg : Object
object
topic: "sensor.ups_status_data"
payload: "OL"
data: object
event_type: "state_changed"
entity_id: "sensor.ups_status_data"
event: object
entity_id: "sensor.ups_status_data"
old_state: object
entity_id: "sensor.ups_status_data"
state: "OL"
attributes: object
context: object
last_changed: "2024-10-14T15:10:59.588Z"
last_updated: "2024-10-14T15:10:59.588Z"
timeSinceChangedMs: 122896244
new_state: object
entity_id: "sensor.ups_status_data"
state: "OL"
attributes: object
context: object
last_changed: "2024-10-14T15:10:59.588Z"
last_updated: "2024-10-14T15:10:59.588Z"
timeSinceChangedMs: 122896244

while debug3 (fed by the custom output) gets:


16/10/2024, 09:19:11node: debug 3
msg : Object
object
payload: undefined
_msgid: "28844278a1449501

I am intrigued by the fact that the message id seems to be the same?

thx

The entity that triggers the flow is not the same as the entity that you need to pass the data from?

Where it says attributes: object that expands and contains additional information. It would have the entity_id of the entity that triggered the node along with attributes like battery etc.

entity_id: "sensor.ups_status_data"
state: "OL"
attributes: object

If it is a completely different entity from what triggered the node, you would use

$entities('sensor.ups_xyz').attributes.battery

Correct, I want to include the sensor.ups_battery_runtime entity when the sensor.ups_battery_state changes. I have found no way to look that up and add it to the actual msg.payload, and hence thought I could trigger a second custom output and include it there, but cannot find out how to interpolate that there

In short, any time the state changes, i want to have the remaining runtime transmitted.

alternatively, if i could include this into the standard msg.payload somehow? Again, I have no idea how to reference it

I misunderstood your first post, since it is a separate entity use:

$entities('sensor.ups_battery_runtime').state

Here is a short explanation of $entity() and $entities()

And a more detailed explanation.