Pyscript: Struggling to get @state_trigger to respond to changes in UI

Category: No matches found for Pyscript
Optional Tags: No matches found for Pyscript

Hello all! I am trying to get Pyscript to respond to UI changes using the @state_trigger decorator. I got it all installed and printing log.info messages to the logs…but it just never triggers my function when I change the state in the UI.

I am using this definition:

log.info(f"<vBridge>:  state.exist('counter.helper_counter1'):{state.exist('counter.helper_counter1')}")

@state_trigger("counter.helper_counter1")
def why_wont_this_ever_trigger():
    log.info("yay!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")

…and I see this in the logs:

2025-05-18 09:46:38.703 DEBUG (MainThread) [custom_components.pyscript.eval] file.vbridge: calling exist("counter.helper_counter1", {})
2025-05-18 09:46:38.703 DEBUG (MainThread) [custom_components.pyscript.eval] file.vbridge: calling info("<vBridge>:  state.exist('counter.helper_counter1'):True", {})
2025-05-18 09:46:38.703 INFO (MainThread) [custom_components.pyscript.file.vbridge] <vBridge>:  state.exist('counter.helper_counter1'):True
2025-05-18 09:46:38.703 INFO (MainThread) [custom_components.pyscript.global_ctx] Reloaded /config/pyscript/vbridge.py
2025-05-18 09:46:38.703 DEBUG (MainThread) [custom_components.pyscript.trigger] trigger file.vbridge.why_wont_this_ever_trigger is active
2025-05-18 09:46:38.706 DEBUG (MainThread) [custom_components.pyscript.trigger] trigger file.vbridge.why_wont_this_ever_trigger: watching vars {'counter.helper_counter1'}
2025-05-18 09:46:38.706 DEBUG (MainThread) [custom_components.pyscript.trigger] trigger file.vbridge.why_wont_this_ever_trigger waiting for state change or event

…everything looks like it is setup properly…then I manually change the counter in the UI…and nothing…my function never triggers.

Comment1: I have tried many, many variations including task.wait_until, @state_active and others. The @time_trigger works, but my @state_trigger never works. I have also tried to trigger on several different entity types from lights, to input_numbers, to counters, to text strings, but nothing works.

Comment2: I have tried EVENT_STATE_CHANGED …but some of the tutorials say this:
It’s much better to use @state_trigger decorators to trigger on state variable changes, rather than triggering on all EVENT_STATE_CHANGED events.

Any guidance is appreciated. Thanks!!

  • VoltVisionFrenchy

ps-My ultimate goal is to be able to fire off OSC messages to my MR-18 mixer and/or Ableset based on manual UI triggers or automations using:
https://pypi.org/project/python-osc/