Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Variables for state_hold ? #727

Answered by ALERTua
khaimong asked this question in General
Discussion options

Is there any way to use a variable for state_hold in a trigger? i.e. instead of using a constant integer seconds, the ability to use a defined "input_integer.xxx" to define the hold time

You must be logged in to vote

You can, if you wrap your state trigger in a factory

registered_setup_example_app = {}
def setup_example_app(entity_id: str):
 task_name = f"{__name__}_{entity_id}"
 
 state_hold_value = int(state.get('input_integer.xxx'))
 @state_trigger(
 entity_id,
 watch=[entity_id],
 state_hold=state_hold_value,
 )
 def fnc_trigger(trigger_type=None, var_name=None, value=None, old_value=None, context=None, **kwargs):
 task.unique(task_name)
 log.info(f"{task_name}: {old_value}->{var_name}->{value}")
 registered_setup_example_app[task_name] = fnc_trigger
@time_trigger('once(now)')
def gen():
 for config in pyscript.app_config:
 s...

Replies: 1 comment 2 replies

Comment options

You can, if you wrap your state trigger in a factory

registered_setup_example_app = {}
def setup_example_app(entity_id: str):
 task_name = f"{__name__}_{entity_id}"
 
 state_hold_value = int(state.get('input_integer.xxx'))
 @state_trigger(
 entity_id,
 watch=[entity_id],
 state_hold=state_hold_value,
 )
 def fnc_trigger(trigger_type=None, var_name=None, value=None, old_value=None, context=None, **kwargs):
 task.unique(task_name)
 log.info(f"{task_name}: {old_value}->{var_name}->{value}")
 registered_setup_example_app[task_name] = fnc_trigger
@time_trigger('once(now)')
def gen():
 for config in pyscript.app_config:
 setup_example_app(**config)
You must be logged in to vote
2 replies
Comment options

but you will also need to trigger on the input_integer.xxx state change and execute pyscript.reload

Comment options

Thank you very much! It's more wordy than what I expected, but it will do.

Answer selected by khaimong
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants

AltStyle によって変換されたページ (->オリジナル) /