#How to pick out a message field from an object with a random name?

1 messages · Page 1 of 1 (latest)

quaint rose
#

I have an mqtt message coming in from Valetudo where I need to get the message field from it, but the object name in the payload is a random uuid representing the event, so how do I extract the message when I can't know the object name beforehand?

woeful vector
#
{% set key = value_json.keys() | first %}
{{ value_json.get(key, {}).get('message', 'No Message') }}
#

making assumptions here though

quaint rose
#

the mqtt message looks like this

valetudo/basement_dreame_x40_ultra/ValetudoEvents/valetudo_events {"a561f288-0944-423c-b698-cce7d63b44ef":{"__class":"ErrorStateValetudoEvent","metaData":{},"id":"a561f288-0944-423c-b698-cce7d63b44ef","timestamp":"2026-01-05T11:00:17.440Z","processed":false,"message":"Mop Dock Clean Water Tank empty"}}
woeful vector
#

As a sensor

#

If you’re using an mqtt trigger, it’ll be different

quaint rose
#

I'm not sure what you're referring to exactly, I'm trying to this in node-red, not as a HA automation

woeful vector
#

Oh, good luck, it's pretty easy in HA. No idea how to access it in NR

#

Missed the Node-Red tag

quaint rose
#

I found a way, it's quite easy with JSONata:

$contains(*.*.message, "Clean Water Tank empty")