Open harmptor opened 1 year ago
On a likely related note: The widget's spinning animation cancels after 15s if the script's mode is set to single
, even though the script is still running. If I change it to parallel
it spins until the script has finished, which I assume to be the intended behaviour. (to be precise: it spins until the second execution finished, the second one being the unintentional one)
To me it feels like the widget tries to fire the script again after 15s in order to see if its running, and if its not (because its blocked by mode: single
) it cancels its spinning animation.
I hope this can help troubleshooting :)
Strange the app logs show we only send the service call once but HA core logs show it got the response twice? We don't have any retry logic so I wonder where that is coming from? Very strange how the automation mode changes this behavior, makes me wonder if its a HA core issue as a result of that?
Are you keeping the screen on the entire time with the spinning animation? If the screen is turning on and off then it is expected that the spinning animation will be removed. This has nothing to do with the service call itself and is only a visual change because in some cases the spinning never stops and the user cannot interact with the widget. If the service call was sent twice via the button action we would see that in the logs but we do not.
Trying to reproduce this, but I'm not able to. Using the same example script as your code but it is correctly finishing after 18s, only being triggered once. Only difference is Home Assistant core is the latest here (2023.10.1), but I'm not aware of any changes that should affect it. 🤔
The widget's spinning animation cancels after 15s if the script's mode is set to single, even though the script is still running. If I change it to parallel it spins until the script has finished, which I assume to be the intended behaviour.
The behavior is actually supposed to be: it spins until finished (unless the system refreshes the widget like @dshokouhi mentions). I wonder if this issue may be device specific somehow. Would you able to test on another device?
Yea its very strange. And I kept my screen on, yes. I dont understand. If you guys are unable to reproduce it's likely just an issue on my end and I will be closing this. I could dig up an old phone somewhere in the piles but I don't think its worth it, unless you guys want me to. Parallel to filing this issue I created a relay script that executes the actual script, it works for me and will do until I change phones or reset the app which I think will fix this issue.
For anyone with the same issue, here's my remedy script:
widget_relay:
alias: "widget_relay"
description: "this functions as a relay script for mobile app widgets, because they fire twice"
fields:
script_to_run:
description: "the entity_id(s) of the script(s) to run"
default: "script.testscript"
example: "script.testscript, script.anotherscript"
script_to_wait_for:
description: "the entity_id of the script to wait for"
default: "script.testscript"
example: "script.testscript"
variables:
description: "the variables to be sent to script_to_run as data"
default: '{"shuffle": "true", "limit": 20}'
example: '{"shuffle": "true", "limit": 20}'
mode: parallel
# max_exceeded: silent
sequence:
- variables:
variables: "{{ variables|default('{}')|join(',')|from_json }}"
first_script: >
{% if script_to_run is string -%}
{{ script_to_run.split(',')[0] }}
{%- else -%}
{{ script_to_run[0] }}
{%- endif %}
script_to_wait_for: "{{ (script_to_wait_for|default(first_script)) }}"
- alias: "IF current > 0, then wait, else run script"
if:
- alias: current > 0
condition: template
value_template: "{{ this.attributes.current > 0 }}"
then:
- alias: wait for script to finish
wait_template: "{{ is_state(script_to_wait_for, 'off') }}"
timeout: "00:05:00"
continue_on_timeout: false
else: # if not current > 0
- alias: send temp notif
service: persistent_notification.create
data:
title: "Widget Relay Script:"
message: |
{{ now().strftime('%Y-%m-%d %H:%M:%S') }}
waiting for {{ script_to_wait_for }} to finish...
variables: {{ variables|to_json(pretty_print=True,sort_keys=True) }}
notification_id: "widgetrelay-{{ context.id }}"
- alias: run script_to_run
service: script.turn_on
target:
entity_id: "{{ script_to_run }}"
data: "{'variables': {{ variables }} }"
- delay: 0.5
- alias: wait for script to finish
wait_template: "{{ is_state(script_to_wait_for, 'off') }}"
timeout: "00:05:00"
continue_on_timeout: false
- alias: dismiss temp notif
service: persistent_notification.dismiss
data:
notification_id: "widgetrelay-{{ context.id }}"
I believe I am also experiencing this issue, I added a delay to a script that I call from a widget and since then it's been running twice. It's not at 15 seconds exactly, it's been 18 and 20 seconds, but still repeating a second time.
If I can provide any logs let me know.
Core 2024.2.1 Supervisor 2024.01.1 Operating System 11.5 Frontend 20240207.1
App 2024.1.5-full
Edit: My script is set to restart, not single. But it seems to still be affected, as the trace today shows it was restarted at the 18 second mark, which I didn't (couldn't?) do, since it was triggered by the widget.
2024-02-18 22:29:49.754 INFO (MainThread) [homeassistant.components.script.bedtime] Bedtime Automation: Restarting
2024-02-18 22:29:49.756 INFO (MainThread) [homeassistant.components.script.bedtime] Bedtime Automation: Running script sequence
Home Assistant Android app version(s): 2023.9.2-full
Android version(s): 10
Device model(s): ONEPLUS A5000
Home Assistant version: 2023.9.3
Last working Home Assistant release (if known):
Description of problem, include YAML if issue is related to notifications: If a button widget fires a script directly via
script.testscript
, and that script runs for at least for 15 seconds, then it is executed a second time 15 or 16 seconds after its initial execution. There is no second execution if the script is configured to run less than 15 seconds or the script is aborted prematurely via script.turn_off. I feel like it has something to do with the animation the widget displays. It seems like it checks after 15 seconds if the animation is still supposed to show, and by that it accidentally triggers the script again. Maybe.In this example, I got one HA trace for this script at
16:05:41
and another at16:05:56
. The script config is thisand I get notifications at
16:05:41
and16:05:56
.All that doesn't happen with Quick Setting Tiles, only with widgets afaik. I enabled debug logging for the mobile_app integration and this is what was logged:
Companion App Logs:
Screenshot or video of problem:
Additional information: