Hi All,
My blueprint code is at the bottom and it appears to work without a hitch. Each time i run it i get the following errors. I don’t know if it’s due to the automation or something else.
Any advice on how to debug it?
2021-01-20 23:08:08 INFO (MainThread) [homeassistant.components.automation.living_room_night_light] Living Room Night Light: Running automation actions
2021-01-20 23:08:08 INFO (MainThread) [homeassistant.components.automation.living_room_night_light] Living Room Night Light: Choose at step 1: choice 1: Running automation actions
2021-01-20 23:08:08 INFO (MainThread) [homeassistant.components.automation.living_room_night_light] Living Room Night Light: Choose at step 1: choice 1: Executing step call service
2021-01-20 23:08:09 INFO (MainThread) [homeassistant.components.automation.living_room_night_light] Living Room Night Light: Choose at step 1: choice 1: Running automation actions
2021-01-20 23:08:09 INFO (MainThread) [homeassistant.components.automation.living_room_night_light] Living Room Night Light: Choose at step 1: choice 1: Executing step call service
2021-01-20 23:08:09 INFO (MainThread) [homeassistant.components.automation.living_room_night_light] Living Room Night Light: Test condition template: True
2021-01-20 23:08:09 INFO (MainThread) [homeassistant.components.automation.living_room_night_light] Living Room Night Light: Executing step wait template
2021-01-20 23:08:18 INFO (MainThread) [homeassistant.components.automation.living_room_night_light] Living Room Night Light: Executing step delay 0:00:45
2021-01-20 23:09:00 ERROR (MainThread) [homeassistant.helpers.condition] Error during template condition: UndefinedError: homeassistant.helpers.template.AllStates object has no element False
2021-01-20 23:09:00 ERROR (MainThread) [homeassistant.helpers.condition] Error during template condition: UndefinedError: homeassistant.helpers.template.AllStates object has no element True
2021-01-20 23:09:03 INFO (MainThread) [homeassistant.components.automation.living_room_night_light] Living Room Night Light: Test condition and: True
2021-01-20 23:09:03 INFO (MainThread) [homeassistant.components.automation.living_room_night_light] Living Room Night Light: Choose at step 9: choice 1: Running automation actions
2021-01-20 23:09:03 INFO (MainThread) [homeassistant.components.automation.living_room_night_light] Living Room Night Light: Choose at step 9: choice 1: Executing step call service
2021-01-20 23:09:04 INFO (MainThread) [homeassistant.components.automation.living_room_night_light] Living Room Night Light: Choose at step 10: choice 1: Running automation actions
2021-01-20 23:09:04 INFO (MainThread) [homeassistant.components.automation.living_room_night_light] Living Room Night Light: Choose at step 10: choice 1: Executing step call service
configuration.yaml
logger:
default: info
logs:
homeassistant.components.automation: debug
homeassistant.components.script: debug
homeassistant.helpers.condition: debug
homeassistant.helpers.template: debug
homeassistant.helpers.template.AllStates: debug
blueprint:
name: Turn on light, switch, scene, script or group based on motion and illuminance.
description: "The blueprint was modified from https://gist.github.com/freakshock88/2311759ba64f929f6affad4c0a67110b#file-motion_illuminance_activated_entity-yaml"
domain: automation
input:
trigger_entity_1:
name: Trigger Entity No. 1
description: This binary sensor, switch or other entity with an on/off state
will trigger the turning on of the target entity.
It can be the same as either of the other triggers if three discrete triggers
aren't available.
selector:
entity: {}
trigger_entity_2:
name: Trigger Entity No. 2
description: This binary sensor, switch or other entity with an on/off state
will trigger the turning on of the target entity.
It can be the same as either of the other triggers if three discrete triggers
aren't available.
default:
selector:
entity: {}
trigger_entity_3:
name: Trigger Entity No. 3
description: This binary sensor, switch or other entity with an on/off state
will trigger the turning on of the target entity.
It can be the same as either of the other triggers if three discrete triggers
aren't available.
default:
selector:
entity: {}
adaptive_lighting_switch_1:
name: (OPTIONAL) Switch for Adaptive Lighting No. 1.
description: The switch used for turn adaptive lighting manual control on
or off.
default:
selector:
entity:
domain: switch
target_start_entity_1:
name: Target Start Entity No. 1.
description: The light, switch, scene to turn on (or script to run) when the
automation is triggered.
selector:
entity: {}
target_start_entity_2:
name: (OPTIONAL) Target Start Entity No. 2.
description: The light, switch, scene to turn on (or script to run) when the
automation is triggered.
default:
selector:
entity: {}
target_start_entity_3:
name: (OPTIONAL) Target Start Entity No. 3.
description: The light, switch, scene to turn on (or script to run) when the
automation is triggered.
default:
selector:
entity: {}
illuminance_sensor:
name: (OPTIONAL) Illuminance sensor
description: This sensor will be used to determine the illumination.
default:
selector:
entity:
domain: sensor
device_class: illuminance
illuminance_cutoff:
name: (OPTIONAL) Illuminance cutoff value
description: This input_number will be used to compare to the current illumination
to determine if it is low.
default:
selector:
entity:
domain: input_number
start_blocking_entity_on_1:
name: (OPTIONAL) Start blocking entity - on 1
description: If this entity's state is on, it will prevent the automation from
running. E.g. sleepmode or away mode.
default:
selector:
entity: {}
start_blocking_entity_on_2:
name: (OPTIONAL) Start blocking entity - on 2
description: If this entity's state is on, it will prevent the automation from
running. E.g. sleepmode or away mode.
default:
selector:
entity: {}
start_blocking_entity_on_3:
name: (OPTIONAL) Start blocking entity - on 3
description: If this entity's state is on, it will prevent the automation from
running. E.g. sleepmode or away mode.
default:
selector:
entity: {}
start_blocking_entity_off_1:
name: (OPTIONAL) Start blocking entity - off 1
description: If this entity's state is off, it will prevent the automation from
running. E.g. sleepmode or away mode.
default:
selector:
entity: {}
start_blocking_entity_off_2:
name: (OPTIONAL) Start blocking entity - off 2
description: If this entity's state is off, it will prevent the automation from
running. E.g. sleepmode or away mode.
default:
selector:
entity: {}
start_blocking_entity_off_3:
name: (OPTIONAL) Start blocking entity - off 3
description: If this entity's state is off, it will prevent the automation from
running. E.g. sleepmode or away mode.
default:
selector:
entity: {}
time_limit_before:
name: (OPTIONAL) Only run before time.
description: Automation will only run when time is earlier than this input_datetime
value.
default:
selector:
entity:
domain: input_datetime
time_limit_after:
name: (OPTIONAL) Only run after time.
description: Automation will only run when time is later than this input_datetime
value.
default:
selector:
entity:
domain: input_datetime
delay_time:
name: (OPTIONAL) Delay start time
description: Delay time before starting the target entity.
If not used entity will start immediately.
default:
selector:
entity:
domain: input_number
no_motion_wait:
name: (OPTIONAL) On duration
description: Time the entity will be on before ending/turning off the target entity
unless motion is detected or any of the triggers remains on.
If not used ending entity will operate.
default:
selector:
entity:
domain: input_number
end_blocking_entity_on_1:
name: (OPTIONAL) End blocking entity - on 1
description: If this entity's state is on, it will prevent the automation from
stopping. E.g. sleepmode or away mode.
default:
selector:
entity: {}
end_blocking_entity_on_2:
name: (OPTIONAL) End blocking entity - on 2
description: If this entity's state is on, it will prevent the automation from
stopping. E.g. sleepmode or away mode.
default:
selector:
entity: {}
end_blocking_entity_on_3:
name: (OPTIONAL) End blocking entity - on 3
description: If this entity's state is on, it will prevent the automation from
stopping. E.g. sleepmode or away mode.
default:
selector:
entity: {}
end_blocking_entity_off_1:
name: (OPTIONAL) End blocking entity - off 1
description: If this entity's state is off, it will prevent the automation from
stopping. E.g. sleepmode or away mode.
default:
selector:
entity: {}
end_blocking_entity_off_2:
name: (OPTIONAL) End blocking entity - off 2
description: If this entity's state is off, it will prevent the automation from
stopping. E.g. sleepmode or away mode.
default:
selector:
entity: {}
end_blocking_entity_off_3:
name: (OPTIONAL) End blocking entity - off 3
description: If this entity's state is off, it will prevent the automation from
stopping. E.g. sleepmode or away mode.
default:
selector:
entity: {}
target_end_entity_1:
name: (OPTIONAL) End entity - 1
description: If defined, this entity will be turned off instead of the
target entity 1. If it is a script or scene then it will be turned on.
default:
selector:
entity: {}
target_end_entity_2:
name: (OPTIONAL) End entity - 2
description: If defined, this entity will be turned off instead of the
target entity 2. This can be helpful when using target entities of type scene
or script.
default:
selector:
entity: {}
target_end_entity_3:
name: (OPTIONAL) End entity - 3
description: If defined, this entity will be turned off instead of the
target entity 3. This can be helpful when using target entities of type scene
or script.
default:
selector:
entity: {}
mode: restart
max_exceeded: silent
variables:
trigger_entity_1: !input 'trigger_entity_1'
trigger_entity_2: !input 'trigger_entity_2'
trigger_entity_3: !input 'trigger_entity_3'
# trigger_entity_off_and: '
# {% if states[trigger_entity_1] in [''unknown'', ''unavailable'', ''off'', ''away'']
# and states[trigger_entity_2] in [''unknown'', ''unavailable'', ''off'', ''away'']
# and states[trigger_entity_3] in [''unknown'', ''unavailable'', ''off'', ''away''] %}
# true
# {% else %}
# false
# {% endif %}'
# trigger_entity_off_or: '
# {% if states[trigger_entity_1] in [''unknown'', ''unavailable'', ''off'', ''away'']
# or states[trigger_entity_2] in [''unknown'', ''unavailable'', ''off'', ''away'']
# or states[trigger_entity_3] in [''unknown'', ''unavailable'', ''off'', ''away''] %}
# ''off''
# {% else %}
# ''on''
# {% endif %}'
target_start_entity_1: !input 'target_start_entity_1'
target_start_entity_2: !input 'target_start_entity_2'
target_start_entity_3: !input 'target_start_entity_3'
adaptive_lighting_switch_1: !input 'adaptive_lighting_switch_1'
illuminance_currently: !input 'illuminance_sensor'
illuminance_cutoff: !input 'illuminance_cutoff'
start_blocking_entity_on_1: !input 'start_blocking_entity_on_1'
start_blocking_entity_on_2: !input 'start_blocking_entity_on_2'
start_blocking_entity_on_3: !input 'start_blocking_entity_on_3'
start_blocking_entity_off_1: !input 'start_blocking_entity_off_1'
start_blocking_entity_off_2: !input 'start_blocking_entity_off_2'
start_blocking_entity_off_3: !input 'start_blocking_entity_off_3'
time_limit_before: !input 'time_limit_before'
time_limit_after: !input 'time_limit_after'
delay_time: !input 'delay_time'
no_motion_wait: !input 'no_motion_wait'
end_blocking_entity_on_1: !input 'end_blocking_entity_on_1'
end_blocking_entity_on_2: !input 'end_blocking_entity_on_2'
end_blocking_entity_on_3: !input 'end_blocking_entity_on_3'
end_blocking_entity_off_1: !input 'end_blocking_entity_off_1'
end_blocking_entity_off_2: !input 'end_blocking_entity_off_2'
end_blocking_entity_off_3: !input 'end_blocking_entity_off_3'
target_end_entity_1: !input 'target_end_entity_1'
target_end_entity_2: !input 'target_end_entity_2'
target_end_entity_3: !input 'target_end_entity_3'
# Create list of lights, if any, for passing to adaptive lighting
start_light_list_1: '
{% if states[target_start_entity_1].domain == ''scene'' or states[target_start_entity_1].domain == ''light'' %}
{% for entity_ids in state_attr(target_start_entity_1, ''entity_id'') -%}
{% if states[entity_ids].domain == ''light'' -%}
{{ entity_ids }}
{% endif %}
{%- endfor %}
{% else %}
none
{% endif %}'
start_light_list_2: '
{% if target_start_entity_2 != none %}
{% if states[target_start_entity_2].domain == ''scene'' or states[target_start_entity_2].domain == ''light'' %}
{% for entity_ids in state_attr(target_start_entity_2, ''entity_id'') -%}
{% if states[entity_ids].domain == ''light'' -%}
{{ entity_ids }}
{% endif %}
{%- endfor %}
{% endif %}
{% else %}
none
{% endif %}'
start_light_list_3: '
{% if target_start_entity_3 != none %}
{% if states[target_start_entity_3].domain == ''scene'' or states[target_start_entity_3].domain == ''light'' %}
{% for entity_ids in state_attr(target_start_entity_3, ''entity_id'') -%}
{% if states[entity_ids].domain == ''light'' -%}
{{ entity_ids }}
{% endif %}
{%- endfor %}
{% endif %}
{% else %}
none
{% endif %}'
trigger:
- platform: state
entity_id:
- !input 'trigger_entity_1'
- !input 'trigger_entity_2'
- !input 'trigger_entity_3'
to: 'on'
condition:
# Illuminance test
- condition: template
value_template: '{{ (states[target_start_entity_1].state == ''on'') or (illuminance_currently
== none) or (illuminance_cutoff == none) or (states[illuminance_currently].state
| int < states[illuminance_cutoff].state | int) }}'
# Blocking entities for the start
- condition: and
conditions:
- condition: template
value_template: '{{ start_blocking_entity_on_1 == none or states[start_blocking_entity_on_1].state != ''on'' }}'
- condition: template
value_template: '{{ start_blocking_entity_on_2 == none or states[start_blocking_entity_on_2].state != ''on'' }}'
- condition: template
value_template: '{{ start_blocking_entity_on_3 == none or states[start_blocking_entity_on_3].state != ''on'' }}'
- condition: and
conditions:
- condition: template
value_template: '{{ start_blocking_entity_off_1 == none or states[start_blocking_entity_off_1].state != ''off'' }}'
- condition: template
value_template: '{{ start_blocking_entity_off_2 == none or states[start_blocking_entity_off_2].state != ''off'' }}'
- condition: template
value_template: '{{ start_blocking_entity_off_3 == none or states[start_blocking_entity_off_3].state != ''off'' }}'
# Time test
- condition: template
value_template: '{% set current_time = now().strftime("%H:%M") %}
{% if time_limit_before != none and time_limit_after == none %}
{{ states[time_limit_before].state > current_time }}
{% elif time_limit_before == none and time_limit_after != none %}
{{ states[time_limit_after].state < current_time }}
{% elif time_limit_before != none and time_limit_after != none %}
{% set before_limit_is_on_next_day = time_limit_after > time_limit_before %}
{% if not before_limit_is_on_next_day %}
{{ (states[time_limit_after].state < current_time) and (states[time_limit_before].state > current_time) }}
{% elif before_limit_is_on_next_day %}
{{ (states[time_limit_before].state > current_time) or (states[time_limit_after].state < current_time) }}
{% endif %}
{% else %}
true
{% endif %}
'
action:
# Turn on entity 1
- choose:
- conditions:
- condition: template
value_template: '{{ target_start_entity_1 != none }}'
sequence:
- service: adaptive_lighting.set_manual_control
data:
entity_id: !input 'adaptive_lighting_switch_1'
manual_control: true
lights: '{{ start_light_list_1 }}'
- service: homeassistant.turn_on
entity_id: !input 'target_start_entity_1'
# Turn on entity 2
- choose:
- conditions:
- condition: template
value_template: '{{ target_start_entity_2 != none }}'
sequence:
- service: adaptive_lighting.set_manual_control
data:
entity_id: !input 'adaptive_lighting_switch_1'
manual_control: true
lights: '{{ start_light_list_2 }}'
- service: homeassistant.turn_on
entity_id: !input 'target_start_entity_2'
# Turn on entity 3
- choose:
- conditions:
- condition: template
value_template: '{{ target_start_entity_3 != none }}'
sequence:
- service: adaptive_lighting.set_manual_control
data:
entity_id: !input 'adaptive_lighting_switch_1'
manual_control: true
lights: '{{ start_light_list_3 }}'
- service: homeassistant.turn_on
entity_id: !input 'target_start_entity_3'
# Delay
- condition: template
value_template: '{{ no_motion_wait != none }}'
- wait_template: '{{ states[trigger_entity_1].state != ''on'' and states[trigger_entity_2].state != ''on'' and states[trigger_entity_3].state != ''on'' }}'
- delay:
seconds: '{{ states[no_motion_wait].state | int }}'
# End blocking entities
- condition: and
conditions:
- condition: template
value_template: '{{ end_blocking_entity_on_1 == none or states[end_blocking_entity_on_1].state != ''on'' }}'
- condition: template
value_template: '{{ end_blocking_entity_on_2 == none or states[end_blocking_entity_on_2].state != ''on'' }}'
- condition: template
value_template: '{{ end_blocking_entity_on_3 == none or states[end_blocking_entity_on_3].state != ''on'' }}'
- condition: and
conditions:
- condition: template
value_template: '{{ end_blocking_entity_off_1 == none or states[end_blocking_entity_off_1].state != ''off'' }}'
- condition: template
value_template: '{{ end_blocking_entity_off_2 == none or states[end_blocking_entity_off_2].state != ''off'' }}'
- condition: template
value_template: '{{ end_blocking_entity_off_3 == none or states[end_blocking_entity_off_3].state != ''off'' }}'
# End sequence entity 1
- choose:
# IF End Entity is Scene
- conditions:
- condition: template
value_template: '{{ target_end_entity_1 != none and ( states[target_start_entity_1].domain == ''scene'' or states[target_start_entity_1].domain == ''script'' ) }}'
sequence:
- service: homeassistant.turn_on
entity_id: !input 'target_end_entity_1'
# ELIF End Entity is Not Scene or Script
- conditions:
- condition: template
value_template: '{{ (target_end_entity_1 != none) }}'
sequence:
- service: homeassistant.turn_off
entity_id: !input 'target_end_entity_1'
default:
- service: homeassistant.turn_off
entity_id: !input 'target_start_entity_1'
- choose:
- conditions:
- condition: template
value_template: '{{ target_start_entity_1 != none }}'
sequence:
- service: adaptive_lighting.set_manual_control
data:
entity_id: !input 'adaptive_lighting_switch_1'
manual_control: false
lights: '{{ start_light_list_1 }}'
# End sequence entity 2
- choose:
- conditions:
- condition: template
value_template: '{{ target_end_entity_2 != none and ( states[target_start_entity_2].domain == ''scene'' or states[target_start_entity_2].domain == ''script'' ) }}'
sequence:
- service: homeassistant.turn_on
entity_id: !input 'target_end_entity_2'
- conditions:
- condition: template
value_template: '{{ (target_end_entity_2 != none) }}'
sequence:
- service: homeassistant.turn_on
entity_id: !input 'target_end_entity_2'
- conditions:
- condition: template
value_template: '{{ (target_start_entity_2 != none) }}'
sequence:
- service: homeassistant.turn_off
entity_id: !input 'target_start_entity_2'
- choose:
- conditions:
- condition: template
value_template: '{{ target_start_entity_2 != none }}'
sequence:
- service: adaptive_lighting.set_manual_control
data:
entity_id: !input 'adaptive_lighting_switch_1'
manual_control: false
lights: '{{ start_light_list_2 }}'
# End sequence entity 3
- choose:
- conditions:
- condition: template
value_template: '{{ target_end_entity_3 != none and ( states[target_start_entity_3].domain == ''scene'' or states[target_start_entity_3].domain == ''script'' ) }}'
sequence:
- service: homeassistant.turn_on
entity_id: !input 'target_end_entity_3'
- conditions:
- condition: template
value_template: '{{ (target_end_entity_3 != none) }}'
sequence:
- service: homeassistant.turn_on
entity_id: !input 'target_end_entity_3'
- conditions:
- condition: template
value_template: '{{ (target_start_entity_3 != none) }}'
sequence:
- service: homeassistant.turn_off
entity_id: !input 'target_start_entity_3'
- choose:
- conditions:
- condition: template
value_template: '{{ target_start_entity_3 != none }}'
sequence:
- service: adaptive_lighting.set_manual_control
data:
entity_id: !input 'adaptive_lighting_switch_1'
manual_control: false
lights: '{{ start_light_list_3 }}'