Page 1 of 1

Script to disable/enable events

Posted: Saturday 12 November 2016 14:01
by Slinkos
Hi all,

I'm thinking to make a virtual switch named "Vacation" for whenever I will be gone from home for a while. My purpose of this switch that when it's on, it will disable the blocky events that I specify in the script), and enable all those events again when I turn the vacation swithc off.

Offcourse I could also rebuild al this events with the statement that "Vacation" has to be off, but I think this is a more clean solution.

Re: Script to disable/enable events

Posted: Monday 14 November 2016 22:45
by Slinkos
Is there no script to do this?

Re: Script to disable/enable events

Posted: Tuesday 15 November 2016 0:37
by Domosapiens
Did you look for the possibilities of "Timer Plan" under Setup - Other?

Re: Script to disable/enable events

Posted: Tuesday 15 November 2016 19:42
by Slinkos
No... I also can't find the menu you are suggesting.

Re: Script to disable/enable events

Posted: Wednesday 16 November 2016 9:20
by Domosapiens
Update your version?

Re: Script to disable/enable events

Posted: Wednesday 16 November 2016 11:46
by toreandre
One way would be to make your events check for the vacation switch status.

If the vacation switch is OFF then execute events, if its ON do nothing.

Re: Script to disable/enable events

Posted: Wednesday 16 November 2016 18:35
by lukcinek
Slinkos wrote:Hi all,

I'm thinking to make a virtual switch named "Vacation" for whenever I will be gone from home for a while. My purpose of this switch that when it's on, it will disable the blocky events that I specify in the script), and enable all those events again when I turn the vacation swithc off.

Offcourse I could also rebuild al this events with the statement that "Vacation" has to be off, but I think this is a more clean solution.
Hi
You should add uservariable in Settings-->More Options-->User variables

Put some name of Your Variable --> MyScriptRun
Type of Variable --> Integer
Variable --> 1

You must add some LUA code to Your Events.

I paste my code that turns off my lights automatically when some time elapses and no motion is discovered.

Code: Select all

script_time_nomotion.lua

local motion_switch = 'PiR - Kitchen'
local nomotion_uservar = 'nomotionCounter'
local status_switch = 'Lamp - ON'
local noRun = uservariables["MyScriptRun"]
local no_motion_minutes = tonumber(uservariables[nomotion_uservar])

commandArray = {}
          if (otherdevices[motion_switch] == 'Off') then
               no_motion_minutes = no_motion_minutes + 1
               --print('<font color="red">No motion has been detected for: ' ..no_motion_minutes.. ' minutes</font>')
          else 
               no_motion_minutes = 0 
          end 
          
          if tonumber(noRun) == 1 then
               if otherdevices[status_switch] == 'On' and no_motion_minutes > 10 then --change the 30 to the amount of minutes you prefer
                    nomotion_uservar= "0"
                    commandArray[status_switch]='Off'
               end
          end 
commandArray['Variable:' .. nomotion_uservar] = tostring(no_motion_minutes)
return commandArray
You must modify this script...sorry I don't know nothing about programming:(

You should make virtual switch (Vacation) and in field:

--> Enable action put something like this:

Code: Select all

 http://192.168.0.15:8080/json.htm?type=command&param=updateuservariable&vname=MyScriptRun&vtype=integer&vvalue=1
--> Disable action put something like this:

Code: Select all

 http://192.168.0.15:8080/json.htm?type=command&param=updateuservariable&vname=MyScriptRun&vtype=integer&vvalue=0 
Change 192.168.0.15:8080 to Your ip and port.

In my case when I turn On my Virtual switch --> My Lua script works and my lights in kitchen Turns off when some time elapses and no motion is discovered.

When i turn Off my Virtual switch --> My lua script doesn't work and my kitchen light are turned on all the time.

Sorry for my English.

Best regards

Re: Script to disable/enable events

Posted: Wednesday 16 November 2016 20:51
by Slinkos
Domosapiens wrote:Update your version?
I am on the latest stable