MQTT messages via python snippets

Hello, everybody,
I’m new here and just making my first steps with snips.
The installation on a Raspberry 3 worked well. I can create assistants on the snips console and transfer them to the Raspberry via SAM. I want to send MQTT messages to different devices. Mosquitto is running on the Raspberry and paho-mqtt has been installed. In the first step I wrote short Python scripts in which I send the MQTT messages.

#!/usr/bin/env python

import paho.mqtt.publish

Publish values via MQTT:

paho.mqtt.publish.single(topic=“top/stube/borduere”, payload=str(“ON”), port=1883, hostname=“localhost”)

When called from the console of the Raspberry, it works very well and the message arrives at the target device.

python light_on.py

I try to use the Python code that worked in the script in a snippet as action code but it doesn’t work. SAM watch returns these messages:

[17:50:48] [AudioServer] finished playing wav with id ‘c7c07d1e-0762-43fe-9f7d-a88f852f8db7’
[17:50:48] [Nlu] was asked to parse input “licht ein”
[17:50:48] [Nlu] detected intent Erwin:LampenAnSchaltenCopy with confidence score 0.805 for input “licht ein”
[17:50:48] [Dialogue] New intent detected Erwin:LampenAnSchaltenCopy with confidence 0.805
[17:50:54] [Dialogue] session with id ‘85e06052-e692-42e7-a4a9-81921cb4a811’ was ended on site default. The session was ended because one of the component didn’t respond in a timely manner
[17:50:54] [Asr] was asked to stop listening on site default
[17:50:54] [Hotword] was asked to toggle itself ‘on’ on site default

As a test I used an example with speech output for confirmation in a snippet. This works.

Can someone tell me what I’m doing wrong?

Many thanks in advance and many greetings,
Erwin

I don’t quite understand the question.

You talk about posting data to other devices via MQTT.

Then you show a log from Snips receiving a voice command without any MQTT client doing anything with it (or at least without responding to Snips, so it times out).

These are two very different things.

Thank you for the answer!
Here are again the responses from “sam watch”:

[19:04:48] Watching on localhost:1883 (MQTT)
[19:04:50] [Hotword] detected on site default, for model hey_snips
[19:04:51] [Asr] was asked to stop listening on site default
[19:04:51] [Hotword] was asked to toggle itself ‘off’ on site default
[19:04:51] [Dialogue] session with id ‘952f9f6c-3f44-49f5-bb90-1d3d7bad0c03’ was started on site default
[19:04:51] [Asr] was asked to listen on site default
[19:04:54] [Asr] captured text “licht an” in 3.0s
[19:04:54] [Asr] was asked to stop listening on site default
[19:04:54] [Nlu] was asked to parse input “licht an”
[19:04:54] [Nlu] detected intent Erwin:LampenAnSchaltenCopy with confidence score 1.000 for input “licht an”
[19:04:54] [Dialogue] New intent detected Erwin:LampenAnSchaltenCopy with confidence 1.000
[19:05:00] [Dialogue] session with id ‘952f9f6c-3f44-49f5-bb90-1d3d7bad0c03’ was ended on site default. The session was ended because one of the component didn’t respond in a timely manner
[19:05:00] [Asr] was asked to stop listening on site default
[19:05:00] [Hotword] was asked to toggle itself ‘on’ on site default

I have extended an example snippet by the MQTT-publish calls. The snippet now looks like this:

#!/usr/bin/env python
import paho.mqtt.publish
if len(intentMessage.slots.deviceLocation) > 0:
deviceLocation = intentMessage.slots.deviceLocation.first().value # We extract the value from the slot “deviceLocation”
result_sentence = “Ich schalte das Licht an in : {}”.format(str(house_room)) # The response that will be said out loud by the TTS engine.

 paho.mqtt.publish(topic="oben/stube/borduere", payload=str("ON"), port=1883, hostname="localhost")

else:
result_sentence = “Ich schalte das Licht an”

 paho.mqtt.publish(topic="oben/stube/borduere", payload=str("ON"), port=1883, hostname="localhost")

current_session_id = intentMessage.session_id
hermes.publish_end_session(current_session_id, result_sentence)

New in the script are only this lines:
import paho.mqtt.publish
paho.mqtt.publish(topic=“oben/stube/borduere”, payload=str(“ON”), port=1883, hostname=“localhost”)

The speech inputs are therefore correctly understood. The problem is probably in the (new) Python lines where I try to publish the MQTT messages.