joq3
April 30, 2024, 10:44am
1
This is an example I have made, I know I can use If/Else/Then for this, but I have more automations like this with more conditions, where I cannot use If/Else/Then.
What am I doing wrong here? It looks like it triggers, but I don’t receive anything on my phone. I know it is setup correctly because I can test send the notification and that part works.
Is there something wrong with my sequence?
Thank you!
alias: Robotdammsugare - Färdig
description: ""
trigger:
- platform: event
event_type: dreame_vacuum_task_status
event_data:
completed: true
cleaning_mode: SWEEPING
- platform: event
event_type: dreame_vacuum_task_status
event_data:
completed: true
cleaning_mode: MOPPING
condition: []
action:
- choose:
- conditions:
- condition: template
value_template: "{{ trigger.event.data.cleaning_mode == 'SWEEPING'}}"
sequence:
- variables:
text_status: Städning
- conditions:
- condition: template
value_template: "{{ trigger.event.data.cleaning_mode == 'MOPPING'}}"
sequence:
- variables:
text_status: Moppning
default:
- service: notify.mobile_app_iphone
data:
title: Robotdammsugare
message: "{{ text_status }} färdig ({{ trigger.event.data.cleaned_area }}m²)"
data:
group: robotdammsugare
url: /lovelace/hem#dammsugare
mode: single
Didn’t give your YAML a long read, but I’d definitely use Trigger IDs instead of template conditions:
Also only looks like you’re sending a message if it’s NOT being triggered (the default actions only run when none of the others are ran in a choose)?
joq3
May 3, 2024, 7:04am
3
Tried simplifying it removing the variables, but I still cannot get it to work:
alias: Robotdammsugare - Färdig
description: ""
trigger:
- platform: event
event_type: dreame_vacuum_task_status
event_data:
completed: true
cleaning_mode: SWEEPING
- platform: event
event_type: dreame_vacuum_task_status
event_data:
completed: true
cleaning_mode: MOPPING
condition: []
action:
- choose:
- conditions:
- condition: template
value_template: "{{ trigger.event.data.cleaning_mode == 'SWEEPING'}}"
sequence:
- service: notify.mobile_app_iphone
data:
title: Robotdammsugare
message: "Städning färdig ({{ trigger.event.data.cleaned_area }}m²)"
data:
group: robotdammsugare
url: /lovelace/hem#dammsugare
- conditions:
- condition: template
value_template: "{{ trigger.event.data.cleaning_mode == 'MOPPING'}}"
sequence:
- service: notify.mobile_app_iphone
data:
title: Robotdammsugare
message: "Moppning färdig ({{ trigger.event.data.cleaned_area }}m²)"
data:
group: robotdammsugare
url: /lovelace/hem#dammsugare
default: []
mode: single
I get this error:
websocket_api script: Error executing script. Error for call_service at pos 1: Error rendering data template: UndefinedError: 'trigger' is undefined
are you getting that error when you are hitting ‘run’? or are you getting it somehow when the automation is triggered by the event you are defining?
when u hit run, the trigger object isn’t defined… because there’s no trigger invoking it… so that would be the expected behavior.
to test it, you actually need to make the real trigger happen.
joq3
May 3, 2024, 9:33am
5
The error is when it is triggered by the vacuum itself.
could you try this and see if you’re getting the same issue?
alias: Robotdammsugare - Färdig
description: ""
trigger:
- platform: event
event_type: dreame_vacuum_task_status
id: Städning
event_data:
completed: true
cleaning_mode: SWEEPING
- platform: event
event_type: dreame_vacuum_task_status
id: Moppning
event_data:
completed: true
cleaning_mode: MOPPING
condition: []
action:
- service: notify.mobile_app_iphone
data:
title: Robotdammsugare
message: |
{{ trigger.id }} färdig ({{ trigger.event.data.cleaned_area }}m²)
data:
group: robotdammsugare
url: /lovelace/hem#dammsugare
mode: single
if you are, replace ({{ trigger.event.data.cleaned_area }}
with a hardcoded string (no {{ }} )