state trigger problem. #231
Unanswered
stefanuytterhoeven
asked this question in
Ideas
Replies: 2 comments 1 reply
-
Other possibility is using closures:
|
Beta Was this translation helpful? Give feedback.
1 reply
-
Also, it is incredibly easy (and equally as performant) to write multiple triggers that all call some helper function. def doStuff():
log.info('stuff')
@state_trigger("input_boolean.test_1 == 'unavailable' or input_boolean.test_1.old == 'unavailable'")
def one():
doStuff()
@state_trigger("input_boolean.test_2 == 'unavailable' or input_boolean.test_2.old == 'unavailable'")
def one():
doStuff() Also, your enclosures in your trigger condition don't really add anything here, so I'm not if that's working as you expect. True or True or True or True
# same thing as
(True or True) or (True or True) |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I would like to use this in a state trigger:
@state_trigger("(light.spot1=='unavailable' or light.spot1.old=='unavailable') or (light.spot2=='unavailable' or light.spot2.old=='unavailable') ")
def test_spot(trigger_type=None, var_name=None, value=None, old_value=None):
notify.....
At first sight,this should work. If spot1 or spot2 becomes "unavailable", or was "unavailable" and becomes 'on' or 'off',
the trigger should go off.
Test;
Initial state:
spot2 is 'unavailable'
spot1 is 'on'
Test:
=> I turn spot1 'off
Result:
trigger is triggered. Probably, because light.spot1 is "watched" by the trigger and something happened with the state.
Then the condition is evaluated. Since spot2 (!) is 'unavailable' , the trigger is triggered....
var_name='light.spot1'
value='off'
old_value='on'
So, the result is not what i want.
What I need, is that I can use 'var_name' in the trigger condition. (or something similar)
Then I could write
@state_trigger("((light.spot1=='unavailable' or light.spot1.old=='unavailable') and var_name=='light.spot1') or ((light.spot2=='unavailable' or light.spot2.old=='unavailable') and var_name=='light.spot2') ")
def test_spot(trigger_type=None, var_name=None, value=None, old_value=None):
notify.....
this should solve my problem....
Beta Was this translation helpful? Give feedback.
All reactions