Page 1 of 1

dzvents to get value thermostat with button plus by mqtt

Posted: Sunday 04 February 2024 9:48
by remko2000
I've a display (button plus https://button.plus/) which works by MQTT.
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
I've been trying for a while, but does anyone see what the problem is?

Re: dzvents to get value thermostat with button plus by mqtt

Posted: Sunday 04 February 2024 10:37
by waltervl
You are missing an end and a } on the end as indicated by the message....

Better not use you is command function but the built in domoticz.executeShellCommand() function. See wiki https://www.domoticz.com/wiki/DzVents:_ ... _execution

Alternative to a script would perhaps be the mqttmapper plugin that can map non supported MQTT protocols to Domoticz devices. See forum topic https://www.domoticz.com/forum/viewtopic.php?t=39279