I’m running into an issue getting a script to pass the validation, for some reason it keeps throwing an error in the logs and I can’t figure out why, especially since there is another variable entity in the script it seems to have no issue with.
Automation (no errors):
- alias: Lights auto on
id: '9e82b1c4-0f3c-42ed-a8f4-5487d2ad90da'
mode: parallel
max: 9
max_exceeded: silent
trigger:
- platform: state
entity_id: binary_sensor.back_door
to: 'on'
- platform: state
entity_id: binary_sensor.front_door
to: 'on'
- platform: state
entity_id: binary_sensor.ranch_slider
to: 'on'
condition:
- condition: or
conditions:
- condition: state
entity_id: input_boolean.night_mode
state: 'on'
- condition: state
entity_id: input_boolean.sunset_mode
state: 'on'
action:
- service: script.autodoorlight
data_template:
door: "{{ trigger.entity_id }}"
light: "{{ trigger.entity_id.split('.')[1] }}"
Script:
autodoorlight:
alias: Door Light Auto on
variables:
on_light: 'light.{{ light }}'
sequence:
- choose:
- conditions:
- condition: state
entity_id: "{{ on_light }}"
state: "unavailable"
sequence:
- service: script.notification
data:
notify_service: notify.user_mobile_devices
message: "{{ door.attributes.friendly_name }} light is turned off, please turn me on \uD83D\uDCA1"
default:
- service: light.turn_on
entity_id: "{{ on_light }}"
- wait_for_trigger:
platform: state
entity_id: "{{ door }}"
to: "off"
for:
seconds: 30
timeout:
minutes: 5
continue_on_timeout: true
- service: light.turn_off
entity_id: "{{ on_light }}"
Cannot for the life of me figure out why it is ok with the door variable and not the on_light variable. I’ve even done it so the automations sends the whole entity, i.e. light.front_door. Script still throws an error in the logs.
I’m not sure, but is it possible, to use two “templated” entries in a row? First you use a template/variable to get to the on_light. And later on you use this templated entry again. Something rings a bell (but a very small one) that you can’t use it that way. But there is a good chance, that I confuse this with something else, sorry.
Maybe you try it “directly” and see if it works:
autodoorlight:
alias: Door Light Auto on
sequence:
- choose:
- conditions:
- condition: state
entity_id: "light.{{ light }}"
state: "unavailable"
[...]
- choose:
- conditions:
- condition: state
entity_id: "light.{{ open }}"
state: "unavailable"
Exact same issue:
Invalid config for [script]: Entity ID light.{{ open }} is an invalid entity ID for dictionary value @ data[‘sequence’][0][‘choose’][0][‘conditions’][0][‘entity_id’]. Got None not a valid value for dictionary value @ data[‘sequence’][0][‘default’][0][‘entity_id’]. Got None. (See /config/configuration.yaml, line 219).
I should have noticed the missing bracket too.
I wasn’t sure about the friendly name either, but was going to sort that once the light variable issue was sorted.
All tested and working brilliantly, thank you very much
If you want to post the full piece up I will mark it as a solution.