Save state then set saved state back to devices

Posted on
Sat Nov 02, 2019 11:50 am
haavarda offline
User avatar
Posts: 702
Joined: Aug 18, 2012
Location: Norway

Save state then set saved state back to devices

I am working on some logic that controls the light in my kitchen.
In that case I want to run a script that saves the state of the 4 lights in the kitchen in variables. Then a new script that reads the states stored in the variables and set the status accordingly.
Can this be done?
If someone can help me with this, it would be much appreciated :D

Script 1
Read state dimmer 1 and set variable A
Read state dimmer 2 and set variable B
Read state dimmer 3 and set variable C
Read state switch 1 and set variable D

Script 2
Set dimmer 1 from state in variable A
Set dimmer 2 from state in variable B
Set dimmer 3 from state in variable C
Set switch 1 from state in variable D

Håvard

Posted on
Sat Nov 02, 2019 3:56 pm
howartp offline
Posts: 4559
Joined: Jan 09, 2014
Location: West Yorkshire, UK

Re: Save state then set saved state back to devices

I’d need to check the documentation, but I think you could do this with the Virtual Device Group plug-in natively. (Name probably not accurate, can never remember it)

Add the four lights to a virtual device, ignoring what state they are on.

Have an action to “Update device states” to record the states.

An an action to Turn On the device to recall their states.


Sent from my iPhone using Tapatalk Pro

Posted on
Sat Nov 02, 2019 4:23 pm
jay (support) offline
Site Admin
User avatar
Posts: 18220
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Save state then set saved state back to devices

Use the Match On State and Match Brightness actions, along with the Insert Device State into Variable actions. No scripts are needed.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Sun Nov 03, 2019 2:36 am
howartp offline
Posts: 4559
Joined: Jan 09, 2014
Location: West Yorkshire, UK

Re: Save state then set saved state back to devices

Or you could do what Jay suggests....!


Sent from my iPhone using Tapatalk Pro

Posted on
Sun Nov 03, 2019 5:35 am
haavarda offline
User avatar
Posts: 702
Joined: Aug 18, 2012
Location: Norway

Re: Save state then set saved state back to devices

Thanks Jay and Howartp.
I am familiar with the state to variable function, and had already started to play with that one. But I have actually never used the function that goes in the opposite direction. I am now closing in on my holy grail in my house. The perfect light control! Tanks again.


Sent from my iPhone using Tapatalk

Håvard

Posted on
Tue Nov 05, 2019 11:22 am
haavarda offline
User avatar
Posts: 702
Joined: Aug 18, 2012
Location: Norway

Re: Save state then set saved state back to devices

I am following up on this as I think it might be useful to implement a small script in one of the triggers.

I a trigger that saves states to variables as described above. But in the same logic I have another trigger with several actions. And in one of this actions I want to turn of the dimmer only if it is on. I guess this is pretty straight forward, but I only get syntax error. Anyone with a tips?

So I am looking for something like if on then turn off...


Sent from my iPhone using Tapatalk

Håvard

Posted on
Tue Nov 05, 2019 11:28 am
jay (support) offline
Site Admin
User avatar
Posts: 18220
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Save state then set saved state back to devices

haavarda wrote:
I guess this is pretty straight forward, but I only get syntax error. Anyone with a tips?


Post your script.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Tue Nov 05, 2019 11:32 am
haavarda offline
User avatar
Posts: 702
Joined: Aug 18, 2012
Location: Norway

Re: Save state then set saved state back to devices

Trying to get better at Python, to thats why I am trying :D .
This is what I have. And it is based on some searching on the forum, and some from the documentation.

Code: Select all
light = indigo.devices[413621741]
if light.onState = true
        indigo.device.turnOff(413621741)

Håvard

Posted on
Tue Nov 05, 2019 12:14 pm
jay (support) offline
Site Admin
User avatar
Posts: 18220
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Save state then set saved state back to devices

Very close:

Code: Select all
light = indigo.devices[413621741]
# the Python booleans start with caps
# = is assignment, == is comparison
if light.onState == True
    # you can use either the ID or the light object - for maintainability
    # it's better to use the object so if you need to change the ID in
    # the future you only have to change it in one place,
    indigo.device.turnOff(light)

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Tue Nov 05, 2019 12:39 pm
haavarda offline
User avatar
Posts: 702
Joined: Aug 18, 2012
Location: Norway

Re: Save state then set saved state back to devices

Hmmm
When i copy the script I get this error...

Code: Select all
   Script Error                    embedded script: invalid syntax
   Script Error                    around line 4 - "if light.onState == True"

Håvard

Posted on
Tue Nov 05, 2019 12:42 pm
haavarda offline
User avatar
Posts: 702
Joined: Aug 18, 2012
Location: Norway

Re: Save state then set saved state back to devices

I found it :)

Code: Select all
   Script Error                    embedded script: invalid syntax
   Script Error                    around line 4 - "if light.onState == True"


There is missing a : ?

Code: Select all
   Script Error                    embedded script: invalid syntax
   Script Error                    around line 4 - "if light.onState == True:"

Håvard

Posted on
Tue Nov 05, 2019 5:38 pm
jay (support) offline
Site Admin
User avatar
Posts: 18220
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Save state then set saved state back to devices

Yep. See, you are getting it!

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Wed Nov 06, 2019 1:18 pm
haavarda offline
User avatar
Posts: 702
Joined: Aug 18, 2012
Location: Norway

Re: Save state then set saved state back to devices

Baby steps. Baby steps.

Thanks!


Sent from my iPhone using Tapatalk

Håvard

Posted on
Thu Nov 07, 2019 1:44 am
howartp offline
Posts: 4559
Joined: Jan 09, 2014
Location: West Yorkshire, UK

Re: Save state then set saved state back to devices

So when’s the plugin coming out?


Sent from my iPhone using Tapatalk Pro

Posted on
Thu Nov 07, 2019 10:07 am
haavarda offline
User avatar
Posts: 702
Joined: Aug 18, 2012
Location: Norway

Re: Save state then set saved state back to devices

Ha ha.
No eta on future releases


Sent from my iPhone using Tapatalk

Håvard

Who is online

Users browsing this forum: No registered users and 14 guests

cron