Code: Select all
hueadm lights | grep -q 'on' && echo 'lights_on'
my question: how i verify if "lights_on" was echoed back in lua? eg can os.execute() be used in a way that it captures the executed shell command's output?
Moderator: leecollings
Code: Select all
hueadm lights | grep -q 'on' && echo 'lights_on'
Code: Select all
hueadm lights | grep -q 'on' && curl 'http://DOMOTICZ-IP:8080/json.htm?type=command¶m=switchlight&idx=SWITCH_ID&switchcmd=On
The attached function returns both the command output and the return code of the command.hendryman wrote: ↑Monday 15 April 2019 12:38 from a lua script, i want to execute this shell command:if any of my hue lights is "on", this command will echo "lights_on".Code: Select all
hueadm lights | grep -q 'on' && echo 'lights_on'
my question: how i verify if "lights_on" was echoed back in lua? eg can os.execute() be used in a way that it captures the executed shell command's output?
Code: Select all
local function osExecute(cmd)
local fileHandle = assert(io.popen(cmd, 'r'))
local commandOutput = assert(fileHandle:read('*a'))
local returnTable = {fileHandle:close()}
return commandOutput,returnTable[3] -- rc[3] contains returnCode
end
Code: Select all
commandArray = {}
local s = os.date('%S')
if (s % 60 == 0) then
local f = assert(io.popen("telnet 192.168.10.110 20108 | strings &" , 'r'))
local Rotel = assert(f:read('*a'))
assert:close()
print(Rotel)
commandArray['UpdateDevice'] = '1376'..'|0|'.. Rotel ..''
end
return commandArray
Not sure what you want to achieve but please understand that the eventsystem in domoticz is single threaded.deve87 wrote: ↑Monday 22 April 2019 21:40 I actually have the same question as you. I'm not any good in scripting. And was hoping someone know how to help with your/my question.
I got a script with io.popen work, but after like 2min. Domoticz lags bad and got error in log that 'Script has been running for more than 10sec'
I want to get a telnet session in Domoticz. And like I said, got it working but the problem.
Code: Select all
commandArray = {} local s = os.date('%S') if (s % 60 == 0) then local f = assert(io.popen("telnet 192.168.10.110 20108 | strings &" , 'r')) local Rotel = assert(f:read('*a')) assert:close() print(Rotel) commandArray['UpdateDevice'] = '1376'..'|0|'.. Rotel ..'' end return commandArray
Happy to help if you can share your Lua script where you want to use this function.hendryman wrote: ↑Tuesday 16 April 2019 9:58 thank you. much appreciated! i'm afraid my lua skills are very limited. could you please give an example on how to call this function and parse its results (three different parameters, if i understand correctly) from the main script? in my case, specifically, i'd like to receive the shell command's "matched" string (or the fact that the shell command did not return a string).
Happy to help if you can share your Lua script where you want to use this function.hendryman wrote: ↑Tuesday 16 April 2019 9:58 thank you. much appreciated! i'm afraid my lua skills are very limited. could you please give an example on how to call this function and parse its results (three different parameters, if i understand correctly) from the main script? in my case, specifically, i'd like to receive the shell command's "matched" string (or the fact that the shell command did not return a string).
Users browsing this forum: No registered users and 1 guest