On/Off action script trigger

Moderator: leecollings

Post Reply
User avatar
bizziebis
Posts: 182
Joined: Saturday 19 October 2013 14:00
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.8805
Location: The Netherlands
Contact:

On/Off action script trigger

Post 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
RobDob
Posts: 28
Joined: Wednesday 29 January 2014 9:59
Target OS: Windows
Domoticz version: v2.2563
Location: Wiltshire, UK
Contact:

Re: On/Off action script trigger

Post 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
User avatar
bizziebis
Posts: 182
Joined: Saturday 19 October 2013 14:00
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.8805
Location: The Netherlands
Contact:

Re: On/Off action script trigger

Post 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.
simon_rb
Posts: 612
Joined: Wednesday 07 August 2013 19:09
Target OS: -
Domoticz version:
Location: UK
Contact:

On/Off action script trigger

Post 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/
User avatar
Keptenkurk
Posts: 103
Joined: Wednesday 21 August 2013 17:24
Target OS: -
Domoticz version:
Location: Waalre, The Netherlands
Contact:

Re: On/Off action script trigger

Post by Keptenkurk »

Code: Select all

script://home/pi/domoticz/scripts/onkyo_webradio.sh
works for a bash script. Can have any name then...
/paul
simon_rb
Posts: 612
Joined: Wednesday 07 August 2013 19:09
Target OS: -
Domoticz version:
Location: UK
Contact:

Re: On/Off action script trigger

Post by simon_rb »

Thanks for confirming this. I was trying to run a python script. Done it via a LUA switch.
User avatar
bizziebis
Posts: 182
Joined: Saturday 19 October 2013 14:00
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.8805
Location: The Netherlands
Contact:

Re: On/Off action script trigger

Post 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.
simonrg
Posts: 329
Joined: Tuesday 16 July 2013 22:54
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.8807
Location: North East England
Contact:

Re: On/Off action script trigger

Post 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.
Raspberry Pi 2 B - 2A@5V PSU - Raspbian + Domoticz + RFXtrx(89), LightwaveRF House(dimmers, sockets, wireless/mood switches), Owl CM113, 4 LaCross Temp / Humidity Sensors, 4 Siemens PIR, Smappee, Solaredge, ESP8266
shkaff
Posts: 16
Joined: Friday 11 December 2015 10:29
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Contact:

Re: On/Off action script trigger

Post 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
alfred_j_kwak
Posts: 110
Joined: Friday 20 September 2013 18:49
Target OS: Raspberry Pi / ODroid
Domoticz version: 2.3530
Location: Finland
Contact:

Re: On/Off action script trigger

Post 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.
shkaff
Posts: 16
Joined: Friday 11 December 2015 10:29
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Contact:

Re: On/Off action script trigger

Post 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
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: On/Off action script trigger

Post 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
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
malarcy
Posts: 50
Joined: Sunday 15 November 2015 13:36
Target OS: Linux
Domoticz version:
Contact:

Re: On/Off action script trigger

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

Who is online

Users browsing this forum: No registered users and 1 guest