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

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

Moderator: leecollings

Post Reply
Gravityz
Posts: 652
Joined: Wednesday 16 December 2015 19:13
Target OS: NAS (Synology & others)
Domoticz version: 2025.1
Location: Netherlands
Contact:

what is wrong with this os.execute statement

Post 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:~#

User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: what is wrong with this os.execute statement

Post 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
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Gravityz
Posts: 652
Joined: Wednesday 16 December 2015 19:13
Target OS: NAS (Synology & others)
Domoticz version: 2025.1
Location: Netherlands
Contact:

Re: what is wrong with this os.execute statement

Post 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)
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: what is wrong with this os.execute statement

Post 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
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Gravityz
Posts: 652
Joined: Wednesday 16 December 2015 19:13
Target OS: NAS (Synology & others)
Domoticz version: 2025.1
Location: Netherlands
Contact:

Re: what is wrong with this os.execute statement

Post 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
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: what is wrong with this os.execute statement

Post 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 ?
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
User avatar
jvdz
Posts: 2445
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

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

Post 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
Gravityz
Posts: 652
Joined: Wednesday 16 December 2015 19:13
Target OS: NAS (Synology & others)
Domoticz version: 2025.1
Location: Netherlands
Contact:

Re: what is wrong with this os.execute statement

Post by Gravityz »

Thanks Jos.

your example is easier to read for my brain(probably because i think a bit old school)
Gravityz
Posts: 652
Joined: Wednesday 16 December 2015 19:13
Target OS: NAS (Synology & others)
Domoticz version: 2025.1
Location: Netherlands
Contact:

Re: what is wrong with this os.execute statement

Post 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
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest