I'm trying to get some values (among other things my thermostat) from domoticz to some labels (for example: domoticz/ButtonPlus/1LValue) of my button plus by MQTT.
For inspiration I have a script that I am trying to get working, but Domoticz keeps giving an error and I don't see what is missing. Even with a syntax checker I can't get any further.
Error:
'2024-02-04 10:18:37.546 ...ents/generated_scripts/buttonplusscriptupdatedevices.lua:53: 'end' expected (to close 'function' at line 15) near <eof>'
Code: Select all
return
{
on =
{
timer = { 'every minute',},
devices = {363},
customEvents = {'ButtonplusUit'},
},
logging =
{
level = domoticz.LOG_DEBUG, -- change to LOG_ERROR when ok
},
execute = function(domoticz)
local buttonscreenSwitch = domoticz.devices(541)
local function osCommand(cmd)
domoticz.log('Executing Command: ' .. cmd,domoticz.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
domoticz.log('Error ==>> ' .. tostring(commandOutput:match('^(.*)%s+::ERROR::') or ' ... but no error message ' ) ,domoticz.LOG_DEBUG)
else -- all is fine!!
domoticz.log('ReturnCode: ' .. returnTable[3] .. '\ncommandOutput:\n' .. commandOutput, domoticz.LOG_DEBUG)
end
return commandOutput,returnTable[3] -- rc[3] contains returnCode
end
local function sendMQTT(message, topic)
local MQTTTopic = topic or 'domoticz/out'
osCommand ( 'mosquitto_pub -u user -P fireport68 ' .. ' -t ' .. MQTTTopic .. " -m '" .. message .. "'")
end
------------Deel voor thermostaat-----------
if buttonscreenSwitch.levelName == 'Thermostaat' then
--woonkamer huidge temperature IDX 349
sendMQTT(tostring(domoticz.round(domoticz.devices(349).temperature,1)), 'domoticz/ButtonPlus/1LValue')
--woonkamer termostaat temp IDX 317
sendMQTT(tostring(domoticz.devices(317).setPoint), 'domoticz/ButtonPlus/1RValue')
end