Does task.unique work for pyscript tasks called from hass automation? #217
Replies: 4 comments 2 replies
-
Yes, that is what Also, existing running tasks are not terminated when pyscript scripts are reloaded. Could you have changed the argument to |
Beta Was this translation helpful? Give feedback.
-
It would be helpful to see the whole function. For example, does it make other service calls or run other tasks (which won't be terminated by |
Beta Was this translation helpful? Give feedback.
-
OK - I'm not saying the code is particularly good - I'm a bit rusty on coding! I don't think there is anything private here. @service
def Location(parms="null"):
task.unique("Location")
log.info(f"Location: parms: {parms}")
command = parms["command"]
location = parms["area"]
log.info(f"ParmTest: Command: {command} {location}")
if location != "home": return
entity = "alarm_control_panel"
if command == "enter":
input_boolean.turn_on(entity_id="input_boolean.mikeathome")
arm_command = "alarm_disarm"
expected_state = "disarmed"
elif command == "leave":
input_boolean.turn_off(entity_id="input_boolean.mikeathome")
arm_command = "alarm_arm_away"
expected_state = "armed_away"
log.info(f"Command: {entity} - {arm_command}")
service.call(entity, arm_command, entity_id="alarm_control_panel.blink_home")
task.sleep(5)
if alarm_control_panel.blink_home != expected_state:
log.info(f"Command (repeat!): {entity} - {arm_command}")
service.call(entity, arm_command, entity_id="alarm_control_panel.blink_home")
task.sleep(5)
log.info(f"Status: {alarm_control_panel.blink_home}") |
Beta Was this translation helpful? Give feedback.
-
The code looks good. I can't see any obvious issue - What versions of HASS / pyscript / python are you using? It would be good to try a very simple example to see if it fails, eg: do a Also, try turning on pyscript debuggingm eg: logger:
logs:
custom_components.pyscript: debug |
Beta Was this translation helpful? Give feedback.
-
I have a pyscript function that gets called from a HASS automation that triggers from a webhook.
From the log.info messages I am seeing, it appears that multiple copies of the pyscript function are running despite there being a task.unique() call at the start of the function.
Am I wrong in my understanding of what task.unique is supposed to do?
Thanks
Beta Was this translation helpful? Give feedback.
All reactions