Page 1 of 1

Need advice for Mqtt pub

Posted: Monday 01 December 2025 0:16
by TiXav
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

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	,
})
and on the "Raspi side" a sh script service (I adapted it) to start the script I want to run

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)
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 ...

Re: Need advice for Mqtt pub

Posted: Monday 01 December 2025 9:31
by waltervl
What if you give the Chromecast a fixed IP on your router? Then the script does not need to discover it and it should also work from the container....