Question
data_template: >
location_name: {% if is_state("input_boolean.guest_mode" , "off") %}not_home{%
else %}home{% endif %}
dev_id: guest_mode
This is my action in an automation to set the location_name payload for a call service device_tracker.see. No matter what the state of the input_boolean, the answer is always not_home.
Anyone see what I am doing wrong?
Remove the >
And put quotes around the template
I tried your suggestion and no change.
Here is my entire automation so that I have full disclosure.
- alias: Guest Mode Toggle
trigger:
- entity_id: input_boolean.guest_mode
platform: state
action:
- data_template:
dev_id: guest_mode
location_name:
"{% if is_state("input_boolean.guest_mode" , "off") %}not_home{% else %}home{% endif %}"
service: device_tracker.see
- alias: Guest Mode Toggle
trigger:
entity_id: input_boolean.guest_mode
platform: state
action:
service: device_tracker.see
data_template:
dev_id: guest_mode
location_name: "{% 'not_home' if is_state('input_boolean.guest_mode' , 'off') else 'home' %}"
Pasted this into my automations.yaml and still get the same results. I see the automation trigger, but the result never changes. I’m starting to think that a template can’t be used for device_tracker.see.
It definitely can because I use one.
Any errors in the log?
Edit - the only real difference in mine is it includes source_type - try…
- alias: Guest Mode Toggle
trigger:
entity_id: input_boolean.guest_mode
platform: state
action:
service: device_tracker.see
data_template:
dev_id: guest_mode
source_type: network
location_name: "{% 'not_home' if is_state('input_boolean.guest_mode' , 'off') else 'home' %}"
Guest Mode Toggle: Error executing script. Invalid data for call_service at pos 1: must contain at least one of mac, dev_id.
Try adding source_type, as above?
Added and it still doesn’t work. I did a full restart of HA (Docker container on UNRaid) and got an error for automations not being able to start. Investigating…
After several restarts, I am now getting this in my notifications panel:
The following integrations and platforms could not be set up:
Please check your config
But my automations are running
ERROR (MainThread) [homeassistant.config] Invalid config for [automation]: invalid template (TemplateSyntaxError: tag name expected) for dictionary value @ data[‘action’][0][‘data_template’][‘location_name’]. Got None. (See /config/configuration.yaml, line 129).
That is where my include statement is for my automations.
Paste your automation as it is now please.
I have about 30 automations in the file. Here is the one we have been working on.
- alias: Guest Mode Toggle
trigger:
entity_id: input_boolean.guest_mode
platform: state
action:
service: device_tracker.see
data_template:
dev_id: guest_mode
source_type: network
location_name: "{% 'not_home' if is_state('input_boolean.guest_mode' , 'off') else 'home' %}"
Even if I delete it from my automations.yaml file, I still get the error.
Just paste that template in to the template tester in developer tools for me? Make sure it’s valid, I can’t see any issues with it but the error message implies it’s not resolving.
This is what I got to work and I pasted it into my automations.yaml file. It still does not change the device_tracker.guest_mode entity.
location_name: "{% if is_state('input_boolean.guest_mode' , 'off') %}not_home{% else %}home{% endif %}"
The general error went away, of course.
I figured it out. The input_boolean was listed as editable: false. I changed this to true and it now works as expected. Thank you for all of your help.
1 Like
Hi @unw1red where exactly did you change the editable from false to true?
I went to Developer Tools, clicked on the entity, changed editable: true and pressed SET STATE.
1 Like