Blocky to lua

Moderator: leecollings

Post Reply
User avatar
Varazir
Posts: 451
Joined: Friday 20 February 2015 22:23
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Contact:

Blocky to lua

Post 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.
Attachments
blocky_event_computer.PNG
blocky_event_computer.PNG (11.74 KiB) Viewed 3502 times
blocky_event_tv.PNG
blocky_event_tv.PNG (21.25 KiB) Viewed 3502 times
Last edited by Varazir on Tuesday 03 March 2015 14:29, edited 1 time in total.
Raspberry PI 2 with RaZberry Controller 2016 ZWave+ and CC2531(zigbee)
Several IKEA devices/z-wave devices
compuman
Posts: 4
Joined: Monday 28 April 2014 6:41
Target OS: Raspberry Pi / ODroid
Domoticz version: V4.9700
Location: Germany
Contact:

Re: Blocky to lua

Post 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.
User avatar
Varazir
Posts: 451
Joined: Friday 20 February 2015 22:23
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Contact:

Re: Blocky to lua

Post 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
Raspberry PI 2 with RaZberry Controller 2016 ZWave+ and CC2531(zigbee)
Several IKEA devices/z-wave devices
jackfagner
Posts: 7
Joined: Saturday 06 February 2016 22:28
Target OS: Linux
Domoticz version:
Contact:

Re: Blocky to lua

Post 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&param=execute_script&direct=true&scriptname=myscript.sh&scriptparams=123
The script ~/domoticz/scripts/myscript.sh will then be executed with parameters 123

Happy coding!
User avatar
Varazir
Posts: 451
Joined: Friday 20 February 2015 22:23
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Contact:

Re: Blocky to lua

Post 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&param=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""
Raspberry PI 2 with RaZberry Controller 2016 ZWave+ and CC2531(zigbee)
Several IKEA devices/z-wave devices
niceandeasy
Posts: 102
Joined: Thursday 28 January 2016 22:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.8153
Location: NL
Contact:

Re: Blocky to lua

Post 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'.
User avatar
Varazir
Posts: 451
Joined: Friday 20 February 2015 22:23
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Contact:

Re: Blocky to lua

Post 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.
Raspberry PI 2 with RaZberry Controller 2016 ZWave+ and CC2531(zigbee)
Several IKEA devices/z-wave devices
jackfagner
Posts: 7
Joined: Saturday 06 February 2016 22:28
Target OS: Linux
Domoticz version:
Contact:

Re: Blocky to lua

Post 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&param=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&param=execute_script&direct=true&scriptname=irssinotifier.sh&scriptparams=Computer%20%23Domoticz_inet%20%22Turning%20off%20the%20Computer%22
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest