I wanna use your mqtt script to pass data to mqtt (nodered) when a uservar changes. (for the volume script you just got working
So i changed the variables section with the right uservar.
Questions
1. Does this script uses the mqtt hardware plugin with the mqtt username and password ?
2. Which value do i use for MQTTTopic = "sometopic/somesubtopic"
see my mqtt attachment, do i have to fill this with "domoticz/out" ?
Code: Select all
-- mqqt
-- gebruikt deze domoticz mqtt username en pwd ?
-- welke waarde moet ik intikken bij MQTTTopic? domoticz/in domoticz/out
--
return
{
on =
{
devices =
{
"",
},
variables =
{
"NRvolume",
},
},
logging =
{
level = domoticz.LOG_DEBUG,
},
execute = function(dz, item)
_G.logMarker = _G.moduleLabel
local MQTTTopic = "sometopic/somesubtopic"
local payload
local function osCommand(cmd)
dz.log('Executing Command: ' .. cmd,dz.LOG_DEBUG)
local fileHandle = assert(io.popen(cmd .. ' 2>&1 || echo ::ERROR::', 'r'))
local commandOutput = assert(fileHandle:read('*a'))
local returnTable = {fileHandle:close()}
if commandOutput:find '::ERROR::' then -- something went wrong
dz.log('Error ==>> ' .. tostring(commandOutput:match('^(.*)%s+::ERROR::') or ' ... but no error message ' ) ,dz.LOG_ERROR)
else -- all is fine!!
dz.log('ReturnCode: ' .. returnTable[3] .. '\ncommandOutput:\n' .. commandOutput, dz.LOG_DEBUG)
end
return commandOutput,returnTable[3] -- rc[3] contains returnCode
end
if item.isDevice then payload = item.text
elseif item.isVariable then payload = item.value
end
local mqttCommand = "mosquitto_pub -t " .. MQTTTopic .. " -m '" .. payload .. "'"
osCommand(mqttCommand)
end
}