1 Variables
Fabio Manganiello edited this page 2024-05-25 23:19:28 +02:00

Variables

You can persist custom state across runs through variables.

Variables will be stored on the application database and can model any kind of state that you want to share across different pieces of automation.

For example, you can set a AT_HOME variable in the previous procedure.at_home - and, conversely, you may want to unset it if you have a procedure.outside_home when that procedure is called.

from platypush import Variable, procedure

@procedure
def at_home():
  # ...
  Variable('AT_HOME').set(True)

@procedure
def outside_home():
  # ...
  Variable('AT_HOME').set(False)

Within another procedure or hook, for example, you may want to turn on the lights only if you're at home:

from platypush import Variable, procedure, run

@procedure
def my_procedure():
  # ...
  at_home = Variable('AT_HOME')

  if at_home.get():
    run('light.hue.on')