Python skill-trouble accessing slot data

Am a newbie so please excuse…
I am trying to create a simple voice-controlled shopping list
Rhasspy can correctly recognize the intent [AddToShop] from this sentence

add ($groceries){name} to the (shopping list)

$groceries is a slot ( a list of grocery items)

and with this python code I can read the intentName and get the out put of the slots…

import json
import paho.mqtt.client as mqtt

def on_connect(client, userdata, flags, rc):
	print("Connected. Waiting for intents.")
def on_disconnect(client, userdata, flags, rc):
    """Called when disconnected from MQTT broker."""
def on_message(client, userdata, msg):
    nlu_payload = json.loads(msg.payload)
    if msg.topic == 'hermes/intent/AddToShop':
        payload = json.loads(msg.payload)
        name = payload["intent"]["intentName"]
        slots = payload["slots"]   
        print("Intent {0} detected with slots {1}"\
            .format(name, slots))

client = mqtt.Client()
client.on_connect = on_connect
client.on_disconnect = on_disconnect
client.on_message = on_message

The output from this command" print(“Intent {0} detected with slots {1}”
.format(name, slots))"


Intent AddToShop detected with slots [{'entity': 'groceries', 'value': {'kind': 'Unknown', 'value': 'eggs'}, 'slotName': 'name', 'rawValue': 'eggs', 'confidence': 1.0, 'range': {'start': 4, 'end': 8, 'rawStart': 4, 'rawEnd': 8}}]

How can I access a slot value? For example, using the output above, how can I capture the value “eggs” and store it in a variable for further python processing?

Thanks for any help

slots is an array

        for slot in payload["slots"]:
          print(slot["slotName"] + ": " + slot["value"]["value"])

Greetings, Jens

1 Like

sorry for the delay
thanks very much
problem solved