Page 1 of 1

what is wrong with this os.execute statement

Posted: Friday 28 June 2019 16:03
by Gravityz
domoticz is complaining about this os statement.

Code: Select all

2019-06-28 15:56:32.024 Error: dzVents: Error: (2.4.23) error loading module 'habridge' from file '/usr/local/domoticz/var/scripts/dzVents/generated_scripts/habridge.lua':
2019-06-28 15:56:32.024 ...oticz/var/scripts/dzVents/generated_scripts/habridge.lua:22: ')' expected near '{'

i really ccan not see where the problem lies

Code: Select all

return {
    active = true,
    on = {
 -- de devices die dit script triggeren 
        devices = {
            'Vitrinekast',
            'Plafondspots'
        }
    },
    execute = function(domoticz, device)
    local devicename = device.name
    local devicestatus = device.state
    local devicelevel = device.level
    
        if devicestatus == 'On' then devicestatus ='true'
        end
            
        if devicestatus == 'Off' then devicestatus ='false'
        end
 
        if (devicename == 'Vitrinekast') then
        os.execute('curl -X PUT -d '{"on": true}' "http://192.168.1.50:8082/api/8d84b9c378c94dd6afbf0180b73ecba9/lights/106/bridgeupdatestate"')
        end
     end
}
the thing is when i execute this complete command from ash it works
also when i comment out the os.execute rule the script does not generate errors

Code: Select all

root@DISKSTATION:~# curl -X PUT -d '{"on": true}' http://192.168.1.50:8082/api/8d84b9c378c94dd6afbf0180b73ecba9/lights/106/bridgeupdatestate
[{"success":{"/lights/106/state/on":true}}]root@DISKSTATION:~#


Re: what is wrong with this os.execute statement

Posted: Friday 28 June 2019 16:35
by waaren
Gravityz wrote: Friday 28 June 2019 16:03 domoticz is complaining about this os statement.

Code: Select all

2019-06-28 15:56:32.024 Error: dzVents: Error: (2.4.23) error loading module 'habridge' from file '/usr/local/domoticz/var/scripts/dzVents/generated_scripts/habridge.lua':
2019-06-28 15:56:32.024 ...oticz/var/scripts/dzVents/generated_scripts/habridge.lua:22: ')' expected near '{'
DzVents does encounter an unmatched quote and therefor cannot continue

Can you try this ?

Code: Select all

return {
    active = true,
    on = {
 -- de devices die dit script triggeren 
        devices = {
            'Vitrinekast',
            'Plafondspots'
        }
    },
    execute = function(domoticz, device)
    local devicename = device.name
    local devicestatus = device.state
    local devicelevel = device.level
    
        if devicestatus == 'On' then devicestatus ='true'
        end
            
        if devicestatus == 'Off' then devicestatus ='false'
        end
 
        if (devicename == 'Vitrinekast') then
            curlString = 'curl -m5 -X PUT -d \'{"on": true}\' "http://192.168.1.50:8082/api/8d84b9c378c94dd6afbf0180b73ecba9/lights/106/bridgeupdatestate"'
            domoticz.log("processing " .. curlString)
            os.execute(curlString)
        end
     end
}

Re: what is wrong with this os.execute statement

Posted: Friday 28 June 2019 16:46
by Gravityz
yes,

that works. so what was wrong with my example?

also have you an idea how to replace the true status with the variable devicestatus

i got this working in another script without the backslashes but is seems when the \ is used al things change (do not understand the logic.

i want to use this script to update habridge status so it needs to pass true/false and briightness(bri)

Re: what is wrong with this os.execute statement

Posted: Friday 28 June 2019 17:08
by waaren
Gravityz wrote: Friday 28 June 2019 16:46 that works. so what was wrong with my example?

Code: Select all

os.execute('curl -X PUT -d '{"on": true}' "http://192.168.1.50:8082/api/8d84b9c378c94dd6afbf0180b73ecba9/lights/106/bridgeupdatestate"')
The 2nd ' in this line close the string. dzVents (Lua) then expect either a ) to close the function parameter to os.execute() or .. to concatenate with another string but is does get a { .
By putting a \ in front of a quote you tell Lua to take that quote literal and do not interpret it (it's called escaping).
i got this working in another script without the backslashes but is seems when the \ is used al things change (do not understand the logic.
Probably a double quote following a single quote or vice versa.
also have you an idea how to replace the true status with the variable devicestatus
Like this ?

Code: Select all

return {
    active = true,
    on = {
 -- de devices die dit script triggeren 
        devices = {
            'Vitrinekast',
            'Plafondspots'
        }
    },
    execute = function(domoticz, device)
    local devicename = device.name
    local devicelevel = device.level
    
        if (devicename == 'Vitrinekast') then
            curlString = 'curl -m5 -X PUT -d \'{"on": ' .. tostring( device.state == 'On' ) ..' }\' "http://192.168.1.50:8082/api/8d84b9c378c94dd6afbf0180b73ecba9/lights/106/bridgeupdatestate"'
            domoticz.log("processing " .. curlString)
            os.execute(curlString)
        end
     end
}

i want to use this script to update habridge status so it needs to pass true/false and briightness(bri)
Don't understand this question

Re: what is wrong with this os.execute statement

Posted: Friday 28 June 2019 17:13
by Gravityz
no i mean i want to replace the statement true with a variable.

curlString = 'curl -m5 -X PUT -d \'{"on": $devicestatus}\' "http://192.168.1.50:8082/api/8d84b9c378 ... pdatestate"'

when variable devicestatus is true it switches the lightstate to true
when variable is false it switches the lightstate to false

of course i know i can not use $devicestatus but because of al those \\\ i do not know what to put there to get it working

Re: what is wrong with this os.execute statement

Posted: Friday 28 June 2019 17:24
by waaren
Gravityz wrote: Friday 28 June 2019 17:13 no i mean i want to replace the statement true with a variable.
tostring( device.state == 'On' ) should evaluate to either 'true' or 'false'
What do you see in the log ?

Re: what is wrong with this os.execute statement  [Solved]

Posted: Friday 28 June 2019 17:32
by jvdz
Gravityz wrote: Friday 28 June 2019 17:13 no i mean i want to replace the statement true with a variable.
curlString = 'curl -m5 -X PUT -d \'{"on": $devicestatus}\' "http://192.168.1.50:8082/api/8d84b9c378 ... pdatestate"'
Something like this?:

Code: Select all

curlString = 'curl -m5 -X PUT -d \'{"on": ' .. devicestatus .. '}\' "http://192.168.1.50:8082/api/8d84b9c378 ... pdatestate"'
Jos

Re: what is wrong with this os.execute statement

Posted: Friday 28 June 2019 17:43
by Gravityz
Thanks Jos.

your example is easier to read for my brain(probably because i think a bit old school)

Re: what is wrong with this os.execute statement

Posted: Friday 28 June 2019 18:11
by Gravityz
thanks Jos and waaren.

got it working with both on/off and brightness.
need to convert it to other levels but that should not be that hard.

fyi, i recently implemented habridge and openhab so that i could control domoticz through google home.
working very nice but it only suncs from openhab to domoticz, not the other way around.
i am going to use this script to update the openhab device status