Hello, i am using an MQTT trigger and am trying to access nested values in the below example MQTT message. Apologies if i don’t get the terms quite right.
within ‘Slots’ there are 2 entities. ‘Lights’ and ‘Light_State’. in the example message I wish to access the nested values e.g ‘landing’ for ‘lights’ and the value ‘on’ for ‘light_state’
I can access the values ‘sometimes’ using the following code snippets:-
{% set var2 = trigger.payload_json.slots[0].value.value %}
{% if trigger.payload_json.slots[1].value.value == "on" %}
The problem, is that in the message Lights and Light_state can swap position within Slots. So Light_State may be at position [0] or position [1]
So the question is whether there another way i access these entities’ values without using the [0] or [1] index?
Thanks!
Example MQTT message:-
{
"input": "turn the landing on",
"intent":
{
"intentName": "ChangeLightState",
"confidenceScore": 0.75},
"siteId": "prometheus",
"id": null,
"slots": [
{
"entity": "lights",
"value":
{
"kind": "Unknown",
"value": "landing"
},
"slotName": "light_name",
"rawValue": "landing",
"confidence": 1.0,
"range":
{
"start": 9,
"end": 16,
"rawStart": 9,
"rawEnd": 16
}
},
{
"entity": "light_state",
"value":
{
"kind": "Unknown",
"value": "on"
},
"slotName": "light_state",
"rawValue": "on",
"confidence": 1.0,
"range":
{
"start": 17,
"end": 19,
"rawStart": 17,
"rawEnd": 19
}
}
],