Counting 1 - 2 - 3- 0 - 1 -2 (cyclic) to control scenes

Posted on
Wed Nov 15, 2017 1:15 pm
indigo2200 offline
Posts: 57
Joined: Apr 16, 2015

Counting 1 - 2 - 3- 0 - 1 -2 (cyclic) to control scenes

One click on my left Fibaro dimmer executes a "scene 26", I would like to use this "scene 26" to initiate an incremental change to a variable each time the I press the button (scene 26).

More specifically ... one click sets a variable to one. Next click sets it to two. Next click to three. Next click resets the variable to zero again. Like a cycle. I am talking about single-clicks.

A trigger will monitor the variable and execute different ligtning scenes (by each click a bit lighter and with some more lamps added etc). The last part I am sure I can figure out, but the cyclic counting I am not able to figure out. Maybe it requires a small script or plug-in.

Posted on
Wed Nov 15, 2017 1:39 pm
Different Computers offline
User avatar
Posts: 1908
Joined: Jan 02, 2016
Location: East Coast

Re: Counting 1 - 2 - 3- 0 - 1 -2 (cyclic) to control scenes

While there's certainly some scriptable way of doing this that I don't know how to do, this is what occurs to me.

2 Triggers. Both "on button press"
Different conditions: One: if variable WhatEver <3, increment Variable WhatEver +1
Two: If Variable WhatEver=3, set Whatever to 0.

SmartThings refugee, so happy to be on Indigo. 10.13.6 on an i5 MBP w/Harmony Hub, Hue, DomoPad, Dynamic URL, Device Extensions, HomeKit Bridge, MatplotLib, Plex, uniFAP, Wunderground, Nanoleaf, LED Simple Effects, Airfoil Pro, Grafana.

Posted on
Sun Nov 19, 2017 10:00 am
indigo2200 offline
Posts: 57
Joined: Apr 16, 2015

Re: Counting 1 - 2 - 3- 0 - 1 -2 (cyclic) to control scenes

Ok, thanks. While this might work, I am still interested if anyone knows on a counting scrips.

Posted on
Sun Nov 19, 2017 10:43 am
jay (support) offline
Site Admin
User avatar
Posts: 15692
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Counting 1 - 2 - 3- 0 - 1 -2 (cyclic) to control scenes

Code: Select all
var = indigo.variables[VARIDHERE]
var_value = var.getValue(int)
if var_value in range(0,3):
    var_value+=1
else:
    var_value=0
indigo.variable.updateValue(var, value=str(var_value))

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Sun Nov 19, 2017 10:43 am
autolog offline
Posts: 2958
Joined: Sep 10, 2013
Location: West Sussex, UK [GMT+1]

Re: Counting 1 - 2 - 3- 0 - 1 -2 (cyclic) to control scenes

Try this script:
Code: Select all
cyclicCount = int(indigo.variables[123456789].value) # "cyclicCount" - change 123456789 to your variables ID
cyclicLimit = int(indigo.variables[987654321].value) # "cyclicLimit" - change 987654321 to your variables ID

cyclicCount = 0 if cyclicCount >= cyclicLimit else cyclicCount + 1

indigo.variable.updateValue(748746289, value=str(cyclicCount))
Setup two variables:
  1. cyclicCount - the cyclic counter
  2. cyclicLimit - the limit, once cyclicCount hits this value it will reset to zero

Set this up as an Action: Server Actions > Script and File Actions > Execute Script > Embedded Python

You can then invoke it on the Scene 26 button press. :)

Posted on
Sun Nov 19, 2017 10:55 am
jalves offline
Posts: 529
Joined: Jun 16, 2013

Re: Counting 1 - 2 - 3- 0 - 1 -2 (cyclic) to control scenes

jay (support) wrote:
Code: Select all
var = indigo.variables[VARIDHERE]
var_value = var.getValue(int)
if var_value in range(0,3):
    var_value+=1
else:
    var_value=0
indigo.variable.updateValue(var, value=str(var_value))

Not conversant in Python, but wouldn't this result in var_value returning 4 in cases where the original var_value was 3?

Running Indigo 7.4 on a 27" iMac (mid-2017), 40G memory, 1T Fusion Drive, OS X 10.15.1
Jeff

Posted on
Sun Nov 19, 2017 11:37 am
jay (support) offline
Site Admin
User avatar
Posts: 15692
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Counting 1 - 2 - 3- 0 - 1 -2 (cyclic) to control scenes

jalves wrote:
jay (support) wrote:
Code: Select all
var = indigo.variables[VARIDHERE]
var_value = var.getValue(int)
if var_value in range(0,3):
    var_value+=1
else:
    var_value=0
indigo.variable.updateValue(var, value=str(var_value))

Not conversant in Python, but wouldn't this result in var_value returning 4 in cases where the original var_value was 3?


No, range (0,3) returns [0, 1, 2]. The first number is the starting value, the second is the total count, so if you do len(range(0,3)) you get 3 because there are 3 total elements in the list.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Sun Nov 19, 2017 3:37 pm
indigo2200 offline
Posts: 57
Joined: Apr 16, 2015

Re: Counting 1 - 2 - 3- 0 - 1 -2 (cyclic) to control scenes

This is whats so great about the Indigo community. Will try it out. Thanks.

Posted on
Sun Nov 19, 2017 4:55 pm
indigo2200 offline
Posts: 57
Joined: Apr 16, 2015

Re: Counting 1 - 2 - 3- 0 - 1 -2 (cyclic) to control scenes

Thanks, autolog!!

I just implemented your script and it works. Thanks a lot

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 1 guest