pyscript
pyscript copied to clipboard
Feaure request: make var_name available in state_trigger condition
problem with state trigger. (see this example in the docs) @state_trigger("domain.light_level == '255' or domain.light2_level == '0'")
when domain.light_level or domain.light2_level is changed, the condition is evaluated. test: domain.light_level is changed to '255' => ok, condition is met. domain.light_level is changed to '200' and domain.light2_level is not changed, but contains '0'=> condition is met ! And, the var_name contains contains domain.light_level in the function...
fueature request: make var_name available in the condition, so we can: @state_trigger("varname='domain.light_level' and domain.light_level == '255' or var_name='domain.light2_level' and domain.light2_level == '0'"). This way, we have more control.
with EVENT TRIGGERS I could solve my problem @event_trigger(EVENT_STATE_CHANGED,"(entity_id='domain.light_level' and new_state.state='255') or (entity_id='domain.light2_level' and new_state.state='0'))
You realise that
@state_trigger("domain.light_level == '255' or domain.light2_level == '0'")
is the same as
@state_trigger("domain.light_level == '255'", "domain.light2_level == '0'")
?
Yes... the same, so, still the same problem.... test: domain.light2_level contains "0" and is changed. domain.light_level changes to whatever value the condition is evaluate because of this change. the first condition is false , but the second condition (domain.light2_level) still is "0" and is true, so, the trigger is .executed....
Please review the docs https://hacs-pyscript.readthedocs.io/en/stable/reference.html#state-trigger
It is difficult to understand what you're asking for, however, if I am understanding you correctly, this is working exactly as expected.
var_name
will be equal to the entity_id that changed causing the trigger to be evaluated (and then run). The functionality you're looking for, if I understand correctly, can be achieved in MANY ways including using two trigger functions, or perhaps the state_hold_false
argument to state_trigger
.
@stefanuytterhoeven could you please update or close the issue? Thank you