dzvents to get value thermostat with button plus by mqtt

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Post Reply
remko2000
Posts: 167
Joined: Thursday 28 December 2017 14:38
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Broek op Langedijk
Contact:

dzvents to get value thermostat with button plus by mqtt

Post 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?
User avatar
waltervl
Posts: 5859
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

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

Post 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
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest