Page 1 of 1
On/Off action script trigger
Posted: Wednesday 05 March 2014 19:39
by bizziebis
I don't know how long I've been searching and trying, but I can't get the on/off action to trigger a script.
I really don't know what format I have to use. script://(but what now?). Nothing in the manual, nothing in the wiki.
Maybe I missed it reading so much pages.
I want to trigger a script at /home/pi/domoticz/scripts/lua/internet_radio_on.lua
Re: On/Off action script trigger
Posted: Wednesday 05 March 2014 19:53
by RobDob
Doesn't the name of the script have to follow this pattern:
script_device_doorbell.lua
So you should rename yours to:
script_device_internet_radio_on.lua
Not sure if the extra _ will cause a problem so maybe:
script_device_internetradioon.lua
Re: On/Off action script trigger
Posted: Wednesday 05 March 2014 20:04
by bizziebis
Yeah, script_device_internetradio.lua is working.
But I want to keep the flexibility of changing the name of the switch without having to edit the lua script.
If I can trigger the script wit a on/off action the name in not important anymore.
On/Off action script trigger
Posted: Thursday 06 March 2014 12:22
by simon_rb
I'm also trying out this on action by triggering a script however I cannot seem to get one working.. My script is in the default scripts folder, whats the correct path to run the script.
script://(now what)
Regards
Simon
Edit:- I'd hazard a guess its script://home/pi/domoticz/scripts/
Re: On/Off action script trigger
Posted: Thursday 06 March 2014 22:03
by Keptenkurk
Code: Select all
script://home/pi/domoticz/scripts/onkyo_webradio.sh
works for a bash script. Can have any name then...
/paul
Re: On/Off action script trigger
Posted: Thursday 06 March 2014 22:12
by simon_rb
Thanks for confirming this. I was trying to run a python script. Done it via a LUA switch.
Re: On/Off action script trigger
Posted: Friday 07 March 2014 6:53
by bizziebis
Then I have to convert my script to bash from lua. Not that hard. Or I call the lua script from the bash script, but thats dirty.
Re: On/Off action script trigger
Posted: Friday 07 March 2014 8:03
by simonrg
It appears that script:// is only able to call scripts external to Domoticz, if you call Lua from Bash then you won't have access to devicechanged, otherdevices or CommandArray, as you will running Lua directly on your platform not inside Domoticz, as I don't think you can call a Lua script by a Json command to Domoticz.
While I can see the logic of wanting to call internal Lua scripts from the on/off action, it just appears not to have been set up in this way. I guess the clue is in the naming of the Lua incorporation as an event system not as a scripting system.
You could ask for this functionality to be added as an extra feature in Domoticz, but I guess it would add extra complexity to the programming even if possible and I am also wondering whether it makes fault finding more difficult for end users. I could see, it would give another route for a wrongly functioning script to put Lua into an infinite loop.
Currently, I have found that I can do everything I need to using the event system to either detect changes using a device script or a time script to monitor for changes in devices and respond accordingly. I have a few general purpose scripts which monitor for a class of device names i.e. script_energy_log.lua which responds to any device with Energy as the initial part of the name, means I can change the rest of the name or create new devices without modifying scripts.
Re: On/Off action script trigger
Posted: Monday 14 December 2015 14:49
by shkaff
Folks, what's the point to name scripts like script_device_%subject% if I have to specify the name manually anyway?
It works even if I name it player_on.sh under the folder /home/pi/domoticz/scripts
And if I specify On Action: script://player_on.sh then it is executed every time when I switch it on!
I am just facing the topic of configuring my virtual switch to manage network video player and trying to guess many things due to lack of documentation
Yes I see that this topic was posted previous year last time
Re: On/Off action script trigger
Posted: Monday 14 December 2015 16:26
by alfred_j_kwak
shkaff wrote:Folks, what's the point to name scripts like script_device_%subject% if I have to specify the name manually anyway?
...due to lack of documentation...
from /domoticz/scripts/lua/script_device_demo.lua:
"- demo device script
-- script names have three name components: script_trigger_name.lua
-- trigger can be 'time' or 'device', name can be any string
-- domoticz will execute all time and device triggers when the relevant trigger occurs
--
-- copy this script and change the "name" part, all scripts named "demo" are ignored. "
About the documentation - please feel free to add necessary parts into documentation. This is open source project as far as I know. I suppose that there also exists commercial solutions with complete documentation and even with technical support.
Re: On/Off action script trigger
Posted: Monday 14 December 2015 22:22
by shkaff
That's fantastic idea to offer people looking for documentation to write one instead! Right! If I cannot figure out how it works then I should be just the best contributor to the knowledge base
Re: On/Off action script trigger
Posted: Tuesday 15 December 2015 16:53
by dannybloe
bizziebis wrote:I don't know how long I've been searching and trying, but I can't get the on/off action to trigger a script.
I really don't know what format I have to use. script://(but what now?). Nothing in the manual, nothing in the wiki.
Maybe I missed it reading so much pages.
I want to trigger a script at /home/pi/domoticz/scripts/lua/internet_radio_on.lua
I had almost the same topic earlier:
http://www.domoticz.com/forum/viewtopic.php?f=4&t=9319
Re: On/Off action script trigger
Posted: Tuesday 15 December 2015 18:48
by malarcy
shkaff wrote:That's fantastic idea to offer people looking for documentation to write one instead! Right! If I cannot figure out how it works then I should be just the best contributor to the knowledge base
There's a little more help here
https://www.domoticz.com/wiki/Domoticz_and_Scripting
From what I have learned - all lua scripts with the script_device_whatever name are run every time a deice changes state - and variables are made available to the LUA script to work out which device has changed. The whatever part is so you can remember what the script does.
lua scripts called script_time_whatever are called every minute - and similarly - you can access information about the state of devices in the system is available
The syntax script:// allows you to specify a specific non lua script - if you do that - you need to go get the values for things (if you need them ) by doing a call to the web service (see the JSON api details on the WIKI).
there are some examples here
https://www.domoticz.com/wiki/Scripts
..... one other thing - speaking of "fantastic ideas" - people on here who take the time to reply are typically trying to help - if what they give you doesn't work or help or suit your needs, then throwing it back at them tends to put others off from adding their contributions. The point is valid, if its not well documented, and you figure it out, then contributing that information back helps the next guy along. A bit like I am trying to do now.
Hope this helps.