Hi,
I have a few automations that give me an actionable push message/notification to an Apple device. The idea is that when motion sensors don’t detect any activity in a room, but the lights are still on (or the TV is still on) that it gives an actionable notification. (action can be “Leave on” or “switch off” in a nutshell.
This all works fine except for one point.
Since I don’t want the automations to run forever I have a time-out and I want to send another message that the time-out has reached and that it didn’t do anything.
Technically and functionally I got that working, but I get the following error messages. I know why it fails, but I can’t figure out a way to prevent these error messages to appear.
2022-11-04 15:08:02.289 ERROR (MainThread) [homeassistant.helpers.template] Template variable error: 'None' has no attribute 'event' when rendering '{{ wait.trigger.event.data.action == action_uitzetten }}'
2022-11-04 15:08:02.291 WARNING (MainThread) [homeassistant.helpers.script] Error in 'choose[0]' evaluation: In 'template' condition: UndefinedError: 'None' has no attribute 'event'
2022-11-04 15:08:02.293 ERROR (MainThread) [homeassistant.helpers.template] Template variable error: 'None' has no attribute 'event' when rendering '{{ wait.trigger.event.data.action == action_aanlaten }}'
2022-11-04 15:08:02.294 WARNING (MainThread) [homeassistant.helpers.script] Error in 'choose[0]' evaluation: In 'template' condition: UndefinedError: 'None' has no attribute 'event'
2022-11-04 15:08:02.296 ERROR (MainThread) [homeassistant.helpers.template] Template variable error: 'None' has no attribute 'event' when rendering '{{ wait.trigger.event.data.action == "None" or wait.trigger == "none" }}'
2022-11-04 15:08:02.297 WARNING (MainThread) [homeassistant.helpers.script] Error in 'choose[0]' evaluation: In 'template' condition: UndefinedError: 'None' has no attribute 'event'
My Automation looks as follows:
alias: NAME lichten staan nog aan
description: Stuurt een bericht als de NAME d'r lichten nog aan staan.
trigger:
- platform: state
entity_id:
- binary_sensor.beweging_NAME_presence
to: "off"
for:
hours: 0
minutes: 9
seconds: 0
- platform: state
entity_id:
- binary_sensor.aanwezig_NAME
to: "off"
condition:
- condition: state
entity_id: binary_sensor.aanwezig_NAME
state: "off"
- condition: or
conditions:
- condition: state
entity_id: light.NAME_kast_lampen
state: "on"
- condition: state
entity_id: light.NAME_plafond_lampen
state: "on"
- condition: time
after: "06:30:00"
before: "20:45:00"
action:
- variables:
action_uitzetten: "{{ 'UITZETTEN_' ~ context.id|default('None') }}"
action_aanlaten: "{{ 'AANLATEN_' ~ context.id|default('None') }}"
action_tag: "{{ 'TAG_' ~ context.id|default('None') }}"
- service: notify.mobile_app_iphone_van_MYPHONE
data:
message: De lichten in NAME d'r kamer staan nog aan en er is niemand.
title: Lichten in NAME d'r kamer
data:
actions:
- action: "{{ action_uitzetten }}"
title: Licht uitzetten
- action: "{{ action_aanlaten }}"
title: Licht aanlaten
tag: "{{ action_tag }}"
- service: notify.mobile_app_iphone_van_HERPHPONE
data:
message: De lichten in NAME d'r kamer staan nog aan en er is niemand.
title: Lichten in NAME d'r kamer
data:
actions:
- action: "{{ action_uitzetten }}"
title: Licht uitzetten
- action: "{{ action_aanlaten }}"
title: Licht aanlaten
tag: "{{ action_tag }}"
- wait_for_trigger:
- platform: event
event_type: mobile_app_notification_action
event_data:
action: "{{ action_uitzetten }}"
- platform: event
event_type: mobile_app_notification_action
event_data:
action: "{{ action_aanlaten }}"
timeout:
hours: 0
minutes: 15
seconds: 0
milliseconds: 0
continue_on_timeout: true
- choose:
- conditions:
- condition: template
value_template: "{{ wait.trigger.event.data.action == action_uitzetten }}"
sequence:
- service: light.turn_off
data:
transition: 2
target:
device_id:
- f4c40675b8XXXXXXXXXXXXXXXX16ed9b
- e9739867e7XXXXXXXXXXXXXXXX6fe8d7
- service: notify.mobile_app_iphone_van_MYPHONE
data:
message: clear_notification
data:
tag: "{{ action_tag }}"
- service: notify.mobile_app_iphone_van_HERPHPONE
data:
message: clear_notification
data:
tag: "{{ action_tag }}"
- conditions:
- condition: template
value_template: "{{ wait.trigger.event.data.action == action_aanlaten }}"
sequence:
- service: notify.mobile_app_iphone_van_MYPHONE
data:
message: clear_notification
data:
tag: "{{ action_tag }}"
- service: notify.mobile_app_iphone_van_HERPHPONE
data:
message: clear_notification
data:
tag: "{{ action_tag }}"
- conditions:
- condition: template
value_template: >-
{{ wait.trigger.event.data.action == "None" or wait.trigger ==
"none" }}
sequence:
- service: notify.mobile_app_iphone_van_MYPHONE
data:
message: Geen reactie - De lichten in NAME d'r kamer blijven aan
title: Lichten in NAME d'r kamer
data:
tag: "{{ action_tag }}"
- service: notify.mobile_app_iphone_van_HERPHPONE
data:
message: Geen reactie - De lichten in NAME d'r kamer blijven aan
title: Lichten in NAME d'r kamer
data:
tag: "{{ action_tag }}"
default:
- service: notify.mobile_app_iphone_van_MYPHONE
data:
message: Geen reactie - De lichten in NAME d'r kamer blijven aan
title: Lichten in NAME d'r kamer
data:
tag: "{{ action_tag }}"
- service: notify.mobile_app_iphone_van_HERPHPONE
data:
message: Geen reactie - De lichten in NAME d'r kamer blijven aan
title: Lichten in NAME d'r kamer
data:
tag: "{{ action_tag }}"
mode: single
Thanks up front!!