Dumonster
(Tiago Dumont)
October 30, 2021, 12:49pm
1
The objective here is to notify the last person to leave the house and ask if they want to turn the alarm on (still missing bits).
However, when I tried to run this snippet which should notify my phone the automation stops with the error: extra keys not allowed @ data[‘actions’].
action:
service: >
{% if is_state('proximity.marinhais.nearest', 'Tiago') %}
notify.mobile_app_tlmtiago
{% else %}
notify.mobile_app_tlmtiago
{% endif %}
data:
title: "Não ficou ninguém em casa"
message: "Ligar alarme?"
actions:
- action: Ligar_Parcial
title: "Ligar Parcial"
- action: Ligar_Total
title: "Ligar Total"
destructive: true
mode: single
What am I doing wrong?
Dumonster
(Tiago Dumont)
October 30, 2021, 2:52pm
3
I’m about to lose my shit here.
It worked once with the first image below.
I did some code clean up which broke it. So I reverted to exactly that image and it’s not working. I’m seriously about to lose my shit.
Actions needs to be inside a second data block:
action:
service: >
{% if is_state('proximity.marinhais.nearest', 'Tiago') %}
notify.mobile_app_tlmtiago
{% else %}
notify.mobile_app_tlmtiago
{% endif %}
data:
title: "Não ficou ninguém em casa"
message: "Ligar alarme?"
data:
actions:
- action: Ligar_Parcial
title: "Ligar Parcial"
- action: Ligar_Total
title: "Ligar Total"
destructive: true
mode: single
Also your service template doesn’t make any sense as it calls the same service whether the condition is true or not.
Dumonster
(Tiago Dumont)
October 30, 2021, 4:48pm
5
Also your service template doesn’t make any sense as it calls the same service whether the condition is true or not.
Aye, I’m just trying to get past this to input the other conditions. I’ll give it a go. Thanks!
Dumonster
(Tiago Dumont)
October 30, 2021, 7:08pm
6
Didn’t work.
action:
service: >
{% if is_state('proximity.marinhais.nearest', 'Tiago') %}
notify.mobile_app_tlmtiago
{else if is_state('proximity.marinhais.nearest', 'Joana') %}}
notify.mobile_app_tlmjoana
{else if is_state('proximity.marinhais.nearest', 'Clara') %}}
notify.mobile_app_tlmclara
{else if is_state('proximity.marinhais.nearest', 'Helena') %}}
notify.mobile_app_tlmhelena
{% endif %}
data:
title: "Não ficou ninguém em casa"
message: "Ligar alarme?"
data:
actions:
- action: Ligar_Parcial
title: "Ligar Parcial"
- action: Ligar_Total
title: "Ligar Total"
destructive: true
mode: single
Returns “Template rendered invalid service:”
You forgot the % signs in the beginning of the else if statements and also it’s elif instead of else if. In addition you have too many closing curly brackets in the else if lines
Should be:
service: >
{% if is_state('proximity.marinhais.nearest', 'Tiago') %}
notify.mobile_app_tlmtiago
{% elif is_state('proximity.marinhais.nearest', 'Joana') %}
notify.mobile_app_tlmjoana
{% elif is_state('proximity.marinhais.nearest', 'Clara') %}
notify.mobile_app_tlmclara
{% elif is_state('proximity.marinhais.nearest', 'Helena') %}
notify.mobile_app_tlmhelena
{% endif %}
You can always test your Templates under Developer Tools → Templates
Dumonster
(Tiago Dumont)
October 30, 2021, 7:26pm
8
Yeah, just noticed. I probably messed that up while trying to solve the original problem and didn’t notice.
Didn’t work.
The full code is, if it’s any help.
- id: '1635440984456'
alias: Alarme_Marinhais_On_Check
description: ''
trigger:
- platform: zone
entity_id: person.tiago
zone: zone.marinhais_2
event: leave
- platform: zone
entity_id: person.clara
zone: zone.marinhais_2
event: leave
- platform: zone
entity_id: person.joana
zone: zone.marinhais_2
event: leave
- platform: zone
entity_id: person.helena
zone: zone.marinhais_2
event: leave
condition:
- condition: state
entity_id: sensor.nobody_home_marinhais
state: 'True'
action:
service: >
{% if is_state('proximity.marinhais.nearest', 'Tiago') %} notify.mobile_app_tlmtiago
{% elif is_state('proximity.marinhais.nearest', 'Joana') %} notify.mobile_app_tlmjoana
{% elif is_state('proximity.marinhais.nearest', 'Clara') %} notify.mobile_app_tlmclara
{% elif is_state('proximity.marinhais.nearest', 'Helena') %} notify.mobile_app_tlmhelena
{% endif %}
data:
title: Não ficou ninguém em casa
message: Ligar alarme?
data:
actions:
- action: Ligar_Parcial
title: Ligar Parcial
- action: Ligar_Total
title: Ligar Total
destructive: true
The result turns out like this:
I’m absolutely lost. The rest of the code works if I remove the IF condition and just slap notify.mobile_app_tlmtiago in it’s place.
I noticed another issue, the proximity entity has two dots, that’s not a valid entity_if. It should probably be
proximity.marinhais_nearest
Dumonster
(Tiago Dumont)
October 30, 2021, 7:39pm
10
Didn’t work. I’ve tried:
proximity.marinhais_nearest
proximity.marinhais.nearest
proximity.marinhais.attributes.nearest
proximity.marinhais.attributes_nearest
The proximity sensor is working properly so that’s not the issue:
Any more ideas?
Nearest is an attribute of the proximity sensor, so you need to use is_state_attr
service: >
{% if is_state_attr('proximity.marinhais', 'nearest', 'Tiago') %} notify.mobile_app_tlmtiago
{% elif is_state_attr('proximity.marinhais', 'nearest', 'Joana') %} notify.mobile_app_tlmjoana
{% elif is_state_attr('proximity.marinhais', 'nearest', 'Clara') %} notify.mobile_app_tlmclara
{% elif is_state_attr('proximity.marinhais', 'nearest', 'Helena') %} notify.mobile_app_tlmhelena
{% endif %}
See here for more info → Templating - Home Assistant
Dumonster
(Tiago Dumont)
October 30, 2021, 7:53pm
12
Worked! Thanks so much for your patience!