Need advice for Mqtt pub
Posted: Monday 01 December 2025 0:16
I use domoticz on docker. I need to start script outside of docker, mainly python scripts with pychromcast (it cannot be use in docker due to broadcast on a different ip of docker container ) to control Google speaker
Today I used dzvents script to ask to run a script from "docker side" via mosquito
and on the "Raspi side" a sh script service (I adapted it) to start the script I want to run
That is working well for at leat a month but I would like to know if there is easier way to do this as existing MQTT client plugin or other to do the MQTT pub in dzvent
Thanks in advance for answers ...
Today I used dzvents script to ask to run a script from "docker side" via mosquito
Code: Select all
function RunScript(DZ,s)
-- s : command to execute
-- add " on each side !
local CmdStr ='mosquitto_pub -h 192.168.1.4 -t xGate/cmd -m "'..s..'"'
DZ.executeShellCommand({
command = CmdStr,
callback = 'Retour_MqttScript',
timeout = 3 ,
})Code: Select all
#!/bin/sh
# https://gist.github.com/David-Lor/63fb0be80b67359c8de6230c6b1dafa2
while true # Keep an infinite loop to reconnect when connection lost/broker unavailable
do
mosquitto_sub -h localhost -t xGate/cmd/\# -F "%t %p" | while read -r payload
do
echo "$payload"
# Here is the callback to execute whenever you receive a message:
topic=$(echo "$payload" | cut -d ' ' -f 1)
msg=$(echo "$payload" | cut -d ' ' -f 2-)
# echo "Rx MQTT: $topic: ${payload}"
echo "${msg}"
# p=$(echo "$msg" | jq '.property')
# echo "Extracted property: $p for $topic"
eval "$msg" &
done
sleep 10 # Wait 10 seconds until reconnection
done # & # Discomment the & to run in background (but you should rather run THIS script in background)
Thanks in advance for answers ...