pyscript: Bug with multiple state-triggers

I just tried to use multiple state triggers as described with one decorator:

@state_trigger("binary_sensor.bad_bewegung=='on'","binary_sensor.wohnzimmer_bewegung=='on'", "person.rico == 'home'")

But, as long as the third trigger is included (which is always true, but should not trigger, because it does not change), the function triggers on every binary_sensors change, not only when changing to “on” (as stated)

binary_sensor.wohnzimmer_bewegung: {‘trigger_type’: ‘state’, ‘value’: ‘on’, ‘old_value’: ‘off’, ‘context’: Context(user_id=None, parent_id=None, id=‘466747cb06fdd2a162b1813d5e60dcce’)} binary_sensor.wohnzimmer_bewegung: {‘trigger_type’: ‘state’, ‘value’: ‘off’, ‘old_value’: ‘on’, ‘context’: Context(user_id=None, parent_id=None, id=‘24eeef4f530f9b24657ad7b4205d3c32’)}

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 17 (9 by maintainers)

Commits related to this issue

Most upvoted comments

The trigger function already gets called with several keyword arguments, including the entity name whose change caused the trigger to become True, and its prior and new values. That should allow it to figure out what caused the trigger.

That said, I agree it could be helpful to allow trigger-dependent arguments to be passed to the trigger function. Perhaps optional keyword arguments args and kwargs could be set for positional and keyword arguments (args would be set to a list and kwargs would be set to a dict)? A single hardcoded keyword argument would be easier, but less flexible. If there is a typo in the keyword argument there should be an error if the function’s declaration doesn’t expect that argument.