Page 1 of 1

Hoe to disable/enable a timer in a scene from another ??

Posted: Tuesday 04 August 2015 21:19
by cyberbob
I have a virtual switch in domoticz.. which goes on and off through an json command and with an ios app.
This to tell the system if im home or not.

Now I also have a couple of scenes with an timer in it. (Trigger a bunch of lights 30 minutes before sunset).

How can I create a blocky script or something, that will do the following:

When I am home.. the timer of scene "A" needs to be active.
When I am away, the timer of scene "A" needs to be inactive.

I already have the home and away switch working.. but how to disable/enable a timer within a scene from another switch...

Re: Hoe to disable/enable a timer in a scene from another ??

Posted: Tuesday 04 August 2015 22:59
by RayAmsterdam
Why not use a the timer on a virtual switch and use this switch in your blockly to run the scenes?

Re: Hoe to disable/enable a timer in a scene from another ??

Posted: Wednesday 05 August 2015 9:53
by mrf68
The manual shows how to "add a timer to a scene" using json. https://www.domoticz.com/wiki/Domoticz_ ... .2F_Groups
You could use this in combination with your home/away switch. When you're home, you set the timer being "true" and when you're away you set it to "false". I haven't tested this, but I'm just thinking out loud.

Re: Hoe to disable/enable a timer in a scene from another ??

Posted: Saturday 08 August 2015 3:42
by cyberbob
RayAmsterdam wrote:Why not use a the timer on a virtual switch and use this switch in your blockly to run the scenes?
cause the scene allows me easier access to 30 minutes before sunset instead of @ sunset.

Re: Hoe to disable/enable a timer in a scene from another ??

Posted: Saturday 08 August 2015 3:43
by cyberbob
mrf68 wrote:The manual shows how to "add a timer to a scene" using json. https://www.domoticz.com/wiki/Domoticz_ ... .2F_Groups
You could use this in combination with your home/away switch. When you're home, you set the timer being "true" and when you're away you set it to "false". I haven't tested this, but I'm just thinking out loud.

Nice thanks, ill try this one this weekend; This can work in more than 1 way :)

Re: Hoe to disable/enable a timer in a scene from another ??

Posted: Monday 22 February 2016 12:58
by gjdv
I stumbled upon this thread when searching for a solution of the problem described. By browsing through the sourcecode, I found this simple solution of doing json calls to enable/disable the scenetimer (where you simply provide the scenetimer identifier which you can find e.g., by checking the action linked to the 'update' button after selecting the scenetimer in the domoticz gui (it says javascript:UpdateTimer(<scenetimeridx>)):
http://server:port/json.htm?type=command&param=enablescenetimer&idx=scenetimeridx
http://server:port/json.htm?type=command&param=disablescenetimer&idx=scenetimeridx
This can be done via any script that can be called on the appropriate event.
It's not listed on https://www.domoticz.com/wiki/Domoticz_ ... of_a_scene, but does work like a charm.

Re: Hoe to disable/enable a timer in a scene from another ??

Posted: Sunday 06 March 2016 21:18
by Number8
For the "regular timers" I use this command is a bash script that works as well

Code: Select all

curl --silent $IPADDRESS:$PORT'/json.htm?type=command&param=enabletimer&idx=idxvalue' > /dev/null

Re: Hoe to disable/enable a timer in a scene from another ??

Posted: Monday 07 March 2016 9:18
by bluepi
You could use a variable as part of a script to check if home = true or false

Re: Hoe to disable/enable a timer in a scene from another ??

Posted: Sunday 17 September 2017 15:46
by Ouate
Hi,
does someone know how to disable/enable ALL times of a scene/group in the same time ?
With the index of the scene.
I am able to disable/enable a timer from a scene but I want to disable/enable all in the same time with only one http command. (to write in a NFC tag)

Is it possible?
thanks.

Re: Hoe to disable/enable a timer in a scene from another ??

Posted: Monday 18 September 2017 0:07
by philchillbill
I use the following perl script which is run when the virtual home/away dummy switch is set, using the script://timers.pl construct. It bulk enables/disables all the timers it finds (except those on an ignore list) but you might be able to modify it to just do the idx'es in your scene:

Code: Select all

#!/usr/bin/perl
use JSON::XS;
use LWP::UserAgent;
no warnings 'uninitialized';

# Queries timers within Domoticz and bulk-enables/disables them depending on whether 0 or 1 is passed when executing
# Any idx values in the hash '%ignore' are skipped. If $debug is set to 1 the script provides feedback when run from command line 

$what=$ARGV[0];
unless (defined ($what)) { print "No parameter supplied, exiting. ($what)\n"; sleep 2; exit 0 };
if ($what == 1) { $action = 'enabletimer' } else { $action = 'disabletimer' };

$debug=0;
 
# get the list of scheduled timers into a hash
$domo_url='http://192.168.178.12:8080';
$ua=LWP::UserAgent->new; $ua->timeout(5);
$scheds=$domo_url.'/json.htm?type=schedules';
$response=$ua->get($scheds);
unless ($response->is_success) { warn "Error getting schedule data from Domoticz $response->status_line" };
$schedules=$response->decoded_content;
$jdata=decode_json $schedules;

%ignore = ( '38' => 1, '39' => 1 );

# loop through the timers and enable/disable them. Only idx is strictly needed, the others are for feedback
foreach $entry (@{$$jdata{result}}) {
 $name=$$entry{DevName};
 $time=$$entry{Time};
 $type=$$entry{TimerTypeStr};
 $idx=$$entry{TimerID}; 
 $cmd=$$entry{TimerCmd};  
 
 if ($ignore{$idx}) { next };

 $c++; $c=sprintf("%02d", $c);
 print "\[$c\] $name -- $type -- $time -- $cmd -- idx: $idx\n" if ($debug);
 $set_schedule=$domo_url."/json.htm?type=command&param=$action&idx=$idx";
 $response=$ua->get($set_schedule);
 unless ($response->is_success) { warn "Error performing '$action' $response->status_line" };


Re: Hoe to disable/enable a timer in a scene from another ??

Posted: Monday 18 September 2017 9:33
by Ouate
thank you philchillbill :)
I will try your script later

Re: Hoe to disable/enable a timer in a scene from another ??

Posted: Thursday 05 July 2018 12:06
by gemminiss
SOLVED

hello everyone.

I'll would like to share with you have I solved in my system (Raspbian+domoticz v4.97).

I have very low programmings skills, so probably I'm missing something, so all comments are welcomed :)

Before start playing with physical devices, I tried with Virtual devices for testing:
  • I've created 2 dummy switches, and 1 Scene and 1 Blockly Event.
  • For the trigger, I've created a dummy switch called: Fuera de Casa (Out of home)
  • The device to be controlled by the scene: I've created a second dummy switch called: Deteccion Jardin (Garden's Detector)
  • I've created a scene called: test, I have added the device/swicth 'Deteccion Jardin', and I've added a Timmer: type 'On' & 'On time' & 'everyday'. For the time, in order to see if the script works, I've just taken the current time and I've added +4 minutes.
  • Then I have added the witches and scene in the Dashboard to see better the interaction between them.
  • Finally I did à simple Blockly script which I named it Test, and i said:
Image

After a couple of tests, it worked!!