jarrah
(jarrah)
December 2, 2021, 2:53pm
21
@petro I’ve noticed another little problem with the automation.
Whenever I press any of the Opple switch buttons, the following error appears in the logs:
2021-12-02 14:50:33 WARNING (MainThread) [homeassistant.helpers.template] Template variable warning: homeassistant.helpers.template.Wrapper object has no element -2 when rendering '{{ items[-2] }}'
Could this be happening when the action playload is empty?
petro
(Petro)
December 2, 2021, 3:00pm
22
yep, change the event variable to
event: >
{{ trigger.payload_json.action or 'button_0_invalid' }}
jarrah
(jarrah)
December 2, 2021, 3:08pm
23
That fixed it - thank you again!
Thanks for editing your post with the fix - could you add the right arrow ‘>’ next to the button variable too please?
jarrah
(jarrah)
December 2, 2021, 3:10pm
24
Github issue for the ‘show trace’ link bug for reference.
opened 02:45PM - 02 Dec 21 UTC
bug
### Checklist
- [X] I have updated to the latest available Home Assistant versi… on.
- [X] I have cleared the cache of my browser.
- [X] I have tried a different browser to see if it is related to my browser.
### Describe the issue you are experiencing
When I run an automation that actions scripts, the 'show trace' link within the Logbook entry for that automation has the wrong URL.
For example, when I hover my mouse over the show trace link, the screenshot below shows the link as being:
`http://192.168.1.10:8123/config/automation/trace/opple_kitchen_2_single?run_id=2cd3eb532a0d6c48d3ac51c4a8516af3`
Note that the URL includes "opple_kitchen_2_single" rather than the automation id name "aqara_opple_kitchen_room"
<img width="880" alt="image" src="https://user-images.githubusercontent.com/3072303/144438323-ee738416-ee6e-4f67-9b13-cd8872a9e24a.png">
When you click the link, it results in a “Chosen trace is no longer available” error message.
This doesn't appear to happen all the time as sometimes the show trace link is valid. I haven't been able to pin down when the error occurs.
I'm reporting this bug based on the following HA Forum discussion:
https://community.home-assistant.io/t/automation-and-script-debugging/361630
### Describe the behavior you expected
The 'show trace' link within Logbook should have the automation name in the URL and not the script name that was actioned
### Steps to reproduce the issue
The following are just two automation examples where the link hasn't worked. It has done this with many other automations as well.
```
- alias: Bed3 Bedside Night Light Button
id: bed3_bedside_nightlight_button
initial_state: 'on'
trigger:
platform: state
entity_id: sensor.xiaomi_switch_sw10_action
action:
- choose:
- conditions: "{{ trigger.to_state.attributes.action == 'single' }}"
sequence:
- service: script.opple_bed3_2_hold
- conditions: "{{ trigger.to_state.attributes.action == 'double' }}"
sequence:
- service: script.opple_bed3_1_double
- conditions: "{{ trigger.to_state.attributes.action == 'hold' }}"
sequence:
- service: script.opple_bed3_1_hold
```
```
- alias: "Aqara Opple kitchen Room"
id: aqara_opple_kitchen_room
initial_state: 'on'
trigger:
- platform: mqtt
topic: 'zigbee2mqttcc1352/switch_opple_kitchen'
variables:
config:
button_1:
- single
- hold
button_2:
- single
- hold
button_3:
- single
- double
- triple
button_4:
- single
- double
- triple
- hold
button_5:
- single
- double
- triple
- hold
button_6:
- single
- double
- triple
- hold
event: >
{{ trigger.payload_json.action | default('button_0_invalid') }}
items: >
{{ event.split('_') }}
button: >
{{ items[-2] }}
action: >
{{ items[-1] }}
continue: >
{{ action in config.get('button_' ~ button, []) }}
service: >
script.opple_kitchen_{{ button }}_{{ action }}
condition:
- condition: template
value_template: "{{ continue }}"
action:
- service: "{{ service }}"
```
### What version of Home Assistant Core has the issue?
core-2021.11.5
### What was the last working version of Home Assistant Core?
_No response_
### In which browser are you experiencing the issue with?
Chrome 95.0.4638.69, Safari 15.1
### Which operating system are you using to run this browser?
macOS Monterey
### State of relevant entities
```txt
N/A
```
### Problem-relevant frontend configuration
```yaml
N/A
```
### Javascript errors shown in your browser console/inspector
```txt
N/A
```
### Additional information
_No response_
1 Like
And if going back to see another original problem in the message, only storing 5 traces, you can store as many traces as you would like now. Here is the Docs on the subject: