silvrr
April 5, 2019, 12:20pm
3
Your quotes look odd
value_template: '{{ trigger.payload_json[''last_device_mac''] == ''10:08:C1:XX:XX:XX''
}}'
Try
value_template: "{{ trigger.payload_json['last_device_mac'] == '10:08:C1:XX:XX:XX'
}}"
looks like petro is replying also so you are in good hands if that doesn’t work.
1 Like
Hi petro, thanks so much for your help!!
I applied those changes but it resulted same error message
I rebooted the machine, no change…
I removed the condition containing the mac, however, the error persisted.
Definitely seems to be in the data template.
I checked device_tracker.see; the parameters appear to be correct.
I then converted the yaml to json, input it into the UI for the automation but it gave me back the yaml as I had converted.
I’m sorry for all this,
Paul Buckley
petro
(Petro)
April 5, 2019, 6:04pm
5
thats odd, so you’re still getting the error?
seaser
(Seaser)
April 26, 2019, 7:21pm
6
I have the same issue. My automation par looks as follows.
- alias: Mark person as just arrived
trigger:
platform: state
entity_id: group.mike
action:
- service: notify.ios_mischaiphonexs
data:
title: "Just Arrived"
message: '{{ trigger.entity_id }} Just arrived.'
The error message is:
Error while executing automation automation.mark_person_as_just_arrived. Error rendering template for call_service at pos 1: UndefinedError: ‘trigger’ is undefined
roleary
(Ryan O)
April 30, 2019, 7:55pm
7
I’ve got the same issue here.
- alias: 'Alert for garage door'
trigger:
- platform: state
entity_id: cover.garage_door_state
action:
- service: notify.html5
data_template:
message: "is {{trigger.to_state.state }}"
title: "Garage Door"
ERROR (MainThread) [homeassistant.helpers.service] Error rendering data template: UndefinedError: ‘trigger’ is undefined
Same issue:
automation:
- alias: 'Notify washingroom'
hide_entity: False
initial_state: 'on'
trigger:
- platform: state
entity_id: binary_sensor.washer
to: 'off'
- platform: state
entity_id: binary_sensor.dryer
to: 'off'
action:
- service: notify.chat_telegram
data_template:
title: "Attention!"
message: >
{{ trigger.to_state.attributes.friendly_name }} completed at {{ now().strftime('%a %-H:%M') }}
data:
displaytime: 30000
icon: "info"
ERROR (MainThread) [homeassistant.helpers.service] Error rendering data template: UndefinedError: ‘trigger’ is undefined
Denis_I
(Denis)
June 3, 2019, 11:10pm
9
Same issue here:
- id: '1557697595652'
alias: '[IFTTT] Turn on the PS4'
trigger:
- event_data:
action: call_service
event_type: ifttt_webhook_received
platform: event
condition:
- condition: template
value_template: '{{ trigger.event.data.entity_id == ''media_player.playstation_4''
}}'
- condition: template
value_template: '{{ trigger.event.data.service == ''media_player.turn_on'' }}'
- condition: state
entity_id: media_player.playstation_4
state: 'off'
action:
- data_template:
entity_id: '{{ trigger.event.data.entity_id }}'
service_template: '{{ trigger.event.data.service }}'
- data:
entity_id: media_player.living_room_lg_tv
service: media_player.turn_on
Was working fine before upgrading to 0.93.2, but now I get:
Error while executing automation automation.ifttt_turn_on_the_ps4. Error rendering template for call_service at pos 1: UndefinedError: 'trigger' is undefined
The funny thing is that when I trigger the recepie from the IFTTT site it works, but it doesn’t work when triggered from HA itself, nor with my voice command.
petro
(Petro)
June 4, 2019, 12:18pm
10
Are you pressing the button to fire the automation? Or are you waiting for it to naturally trigger? If you are pressing the button to test the automation, it will not work because the trigger object doesn’t exist. Because it didn’t trigger.
1 Like
Denis_I
(Denis)
June 4, 2019, 12:42pm
11
@petro I have tried the following yesterday:
Trigerring via voice command (IFTTT) - didn’t work (used ot work)
Trigerring via “Check now” on th IFTTT applet - works
Trigerring via clicking the button in HA - didn’t work (which makes sense as you explained)
Today - 1) worked flawlessly, therefore I suspect that it was related to the major google outage the other day.
1 Like
I’m getting all sorts of similar issues on a very simple automation to push state to MQTT:
- id: '1574917260819'
alias: Kitchen Motion to MQTT
description: ''
trigger:
- entity_id: binary_sensor.kitchen_motion_motion
platform: state
condition: []
action:
- data:
payload_template: '{{ trigger.to_state.state }}'
topic: home/kitchen/motion
service: mqtt.publish
Results in this when a real triggered event occurs:
2019-11-28 00:16:03 INFO (MainThread) [homeassistant.components.automation] Executing Kitchen Motion to MQTT
2019-11-28 00:16:03 INFO (MainThread) [homeassistant.helpers.script] Script Kitchen Motion to MQTT: Running script
2019-11-28 00:16:03 INFO (MainThread) [homeassistant.helpers.script] Script Kitchen Motion to MQTT: Executing step call service
2019-11-28 00:16:03 ERROR (MainThread) [homeassistant.components.automation] Error while executing automation automation.kitchen_motion_to_mqtt. Error rendering template for call_service at pos 1: UndefinedError: 'trigger' is undefined
I’ve also tried changing it to every combination of (data, data_template, payload and payload_template):
- id: '1574917260819'
alias: Kitchen Motion to MQTT
description: ''
trigger:
entity_id: binary_sensor.kitchen_motion_motion
platform: state
condition: []
action:
data_template:
payload_template: '{{ trigger.to_state.state }}'
topic: home/kitchen/motion
service: mqtt.publish
But the results are always the same:
2019-11-28 00:54:24 INFO (MainThread) [homeassistant.components.automation] Executing Kitchen Motion to MQTT
2019-11-28 00:54:24 INFO (MainThread) [homeassistant.helpers.script] Script Kitchen Motion to MQTT: Running script
2019-11-28 00:54:24 INFO (MainThread) [homeassistant.helpers.script] Script Kitchen Motion to MQTT: Executing step call service
2019-11-28 00:54:24 ERROR (MainThread) [homeassistant.components.automation] Error while executing automation automation.kitchen_motion_to_mqtt. Error rendering template for call_service at pos 1: UndefinedError: 'trigger' is undefined
petro
(Petro)
November 28, 2019, 11:14am
14
Are you pressing the button in the UI? Did you read my post above that explains why that doesn’t work? If you press the test button in the UI, trigger will be undefined and you’ll get errors.
1 Like
for testing purposes one could however change the state in the Dev-tools/states page
select the entity which triggers the automation (binary_sensor.kitchen_motion_motion
)
set a state you want to be triggering the automation
click Set state.
If the automation would be correct, this would trigger the automation.
1 Like
Yes, that’s why I went out of my way to say “REAL triggered event”. I am not using the test button in the UI. This is an actual motion sensor triggering from a real motion event.
petro
(Petro)
November 28, 2019, 2:29pm
17
ah, didn’t see that. I would say, don’t use payload template. It may have a different environment and trigger may not be passed to it.
service: mqtt.publish
data_template:
payload: '{{ trigger.to_state.state }}'
topic: home/kitchen/motion
and according to this issue back in 2017, your second automation should work.
It isn’t. I get the same error with that config.
petro
(Petro)
November 28, 2019, 2:41pm
19
are you restarting (or reloading automations) between making changes?
No, I wasn’t. That didn’t seem to be necessary. But I just decided to a second before you asked.
petro
(Petro)
November 28, 2019, 2:42pm
21
it is. This config should work after you make changes and restart (or reload automations):
- id: '1574917260819'
alias: Kitchen Motion to MQTT
description: ''
trigger:
entity_id: binary_sensor.kitchen_motion_motion
platform: state
condition: []
action:
data_template:
payload_template: '{{ trigger.to_state.state }}'
topic: home/kitchen/motion
service: mqtt.publish
Well, it’s a kitchen motion sensor and it is Thanksgiving so I should get plenty of data points to test!