Page 1 of 1
Blocky to lua
Posted: Tuesday 24 February 2015 20:07
by Varazir
Hello
I have 2 blocky event that works as I like them to do but I like to execute a shell script when this event is triggered and what I can understand can't be done with blocky
I have never worked with LUA, done some bash scripting that is all.
I guess I can learn LUA but what I have read feels nothing that I'm looking for.
Re: Blocky to lua
Posted: Wednesday 25 February 2015 6:45
by compuman
Hallo Varazir
i would it write it in LUA :
ComputerConsumption = tonumber(otherdevices_svalues['ComputerConsumption'])
if ComputerConsumption < '13' and ComputerConsumption > '1' then
wait 60000
commandArray['Variable:Computer'] = 'Off'
end
OnkyoConsumtion = tonumber(otherdevices_svalues['Onkyo Consumtion'])
OpenelecConsumption = tonumber(otherdevices_svalues['Openelec Consumption'])
If OnkyoConsumtion < '5' and OnkyoConsumtion > '0' and OpenelecConsumption < '1' and OpenelecConsumption > '0' then
commandArray['TV'] = 'Off'
end
the command "Wait 60000" are not avaibele in Lua. I would it do with a "delay Funktion " in the Switch Propperties.
I think, the TV is never go Off because, there is no value between >0 and <1.
Re: Blocky to lua
Posted: Wednesday 25 February 2015 9:48
by Varazir
compuman wrote:Hallo Varazir
i would it write it in LUA :
ComputerConsumption = tonumber(otherdevices_svalues['ComputerConsumption'])
if ComputerConsumption < '13' and ComputerConsumption > '1' then
wait 60000
commandArray['Variable:Computer'] = 'Off'
end
OnkyoConsumtion = tonumber(otherdevices_svalues['Onkyo Consumtion'])
OpenelecConsumption = tonumber(otherdevices_svalues['Openelec Consumption'])
If OnkyoConsumtion < '5' and OnkyoConsumtion > '0' and OpenelecConsumption < '1' and OpenelecConsumption > '0' then
commandArray['TV'] = 'Off'
end
Thanks
compuman wrote:
the command "Wait 60000" are not avaibele in Lua. I would it do with a "delay Funktion " in the Switch Propperties.
Found this
http://stackoverflow.com/a/13263109
Code: Select all
local clock = os.clock
function sleep(n) -- seconds
local t0 = clock()
while clock() - t0 <= n do
end
end
compuman wrote:
I think, the TV is never go Off because, there is no value between >0 and <1.
Hmm, It's due to the raspberry PI consumes 2.2W when running and about 0.4 W when it's turned off
I'm using non standard notification system, going to call a bash script that pushes out a msg to my phone.
Code: Select all
If ComputerConsumption < 15 and ComputerConsumption > 0; then
execute scrip/notification.sh "Computer" "#Domoticz" "Computer is shutdown, powering down in 20 seconds" &
sleep 20
If ComputerConsumption < 15 and ComputerConsumption > 0; then
sleep 5
set computer = off
else
execute scrip/notification.sh "Computer" "#Domoticz" "Computer is online again"
exit
fi
fi
Re: Blocky to lua
Posted: Tuesday 01 March 2016 14:25
by jackfagner
You could actually execute scripts from blocky using this hack:
Add an OpenURL action with URL:
Code: Select all
127.0.0.1:8080/json.htm?type=command¶m=execute_script&direct=true&scriptname=myscript.sh&scriptparams=123
The script
~/domoticz/scripts/myscript.sh will then be executed with parameters
123
Happy coding!
Re: Blocky to lua
Posted: Friday 04 March 2016 21:40
by Varazir
jackfagner wrote:You could actually execute scripts from blocky using this hack:
Add an OpenURL action with URL:
Code: Select all
127.0.0.1:8080/json.htm?type=command¶m=execute_script&direct=true&scriptname=myscript.sh&scriptparams=123
The script
~/domoticz/scripts/myscript.sh will then be executed with parameters
123
Happy coding!
How can I add space to the parameters?
Code: Select all
2016-03-04 21:40:00.466 Error: Error opening url: 127.0.0.1:8080/json.htm?type=command¶m=execute_script&direct=true&scriptname=irssinotifier.sh&scriptparams=""Computer" "#Domoticz_inet" "Turning off the Computer""
Re: Blocky to lua
Posted: Friday 04 March 2016 23:01
by niceandeasy
compuman wrote:...
ComputerConsumption = tonumber(otherdevices_svalues['ComputerConsumption'])
if ComputerConsumption < '13' and ComputerConsumption > '1' then
wait 60000
commandArray['Variable:Computer'] = 'Off'
end
...
...
the command "Wait 60000" are not avaibele in Lua. I would it do with a "delay Funktion " in the Switch Propperties.
...
If you would introduce a delay in a LUA script, Domoticz will freeze untili that delay has past. So don't do it. Don't use that os.clock delay trick.
The switch delay function might be an option.
You may also issue command['Computer']='Off AFTER 60'
Take a look at the domoticz wiki page 'Events'.
Re: Blocky to lua
Posted: Saturday 05 March 2016 9:04
by Varazir
Hmm, honestly I can't remember why I needed this.
I guess I can do a workaround with OpenURL. creating a "script" that calls my other script so I don't need any parameters.
or simpler with just one parameter "computer" "tv" etc and then the full command line in the file.
Re: Blocky to lua
Posted: Monday 07 March 2016 12:00
by jackfagner
Varazir wrote:jackfagner wrote:You could actually execute scripts from blocky using this hack:
Add an OpenURL action with URL:
Code: Select all
127.0.0.1:8080/json.htm?type=command¶m=execute_script&direct=true&scriptname=myscript.sh&scriptparams=123
The script
~/domoticz/scripts/myscript.sh will then be executed with parameters
123
Happy coding!
How can I add space to the parameters?
Code: Select all
2016-03-04 21:40:00.466 Error: Error opening url: 127.0.0.1:8080/json.htm?type=command¶m=execute_script&direct=true&scriptname=irssinotifier.sh&scriptparams=""Computer" "#Domoticz_inet" "Turning off the Computer""
Code: Select all
127.0.0.1:8080/json.htm?type=command¶m=execute_script&direct=true&scriptname=irssinotifier.sh&scriptparams=Computer%20%23Domoticz_inet%20%22Turning%20off%20the%20Computer%22