Cannot get motion activated light automation to work

I’m trying to get a motion activated light after dark to work using a blueprint however, I keep receiving this error

Message malformed: Entity entity_id is neither a valid entity ID nor a valid UUID for dictionary value @ data['condition'][1]['entity_id']

I have setup a group with all PIRs and and a group with all lights, and I am using the PIR group as the motion entity to trigger the light group.

Any ideas?

Thanks

Show us the code. Not sure how you think we’ll be able to provide detailed insight without it. You don’t even tell us which blueprint.

1 Like

HAHA sorry I completely forgot the code…

Automation:

description: ""
use_blueprint:
  path: homeassistant/motion_light_conditions.yaml
  input:
    motion_entity: binary_sensor.outdoor_pirs
    light_target:
      entity_id: light.outdoor_lights
alias: New Automation

Blueprint:

blueprint:
  name: Motion-activated Light After Dark
  description: Turn on a light when motion is detected after the sun is below the horizon.
  domain: automation
  source_url: https://github.com/home-assistant/core/blob/551fb449752e1c3f55eb688d24509876020852d1/homeassistant/components/automation/blueprints/motion_light.yaml
  input:
    motion_entity:
      name: Motion Sensor
      selector:
        entity:
          domain: binary_sensor
          device_class: motion
    light_target:
      name: Light
      selector:
        target:
          entity:
            domain: light
    no_motion_wait:
      name: Wait time
      description: Time to leave the light on after last motion is detected.
      default: 120
      selector:
        number:
          min: 0
          max: 3600
          unit_of_measurement: seconds

# If motion is detected within the delay,
# we restart the script.
mode: restart
max_exceeded: silent

trigger:
  platform: state
  entity_id: !input motion_entity
  from: "off"
  to: "on"

condition:
  - condition: state
    entity_id: sun.sun
    state: below_horizon
  - condition: state
    entity_id: !input light_target
    state: "off"

action:
  - service: light.turn_on
    data:
      transition: 4
      brightness_pct: 60
      kelvin: 3000
    target: !input light_target
  - wait_for_trigger:
      platform: state
      entity_id: !input motion_entity
      from: "on"
      to: "off"
  - delay: !input no_motion_wait
  - service: light.turn_off
    target: !input light_target

Thanks

heeellllooo?

Is anyone there?

The error is due to a modification you made to an existing blueprint. You added two State Conditions where the second one references the blueprint’s Target Selector. Target Selectors aren’t meant to be used with a State Condition.

I suggest you consider replacing the Target Selector with an Entity Selector. However, this will then require that you modify both service calls to work with an Entity Selector because they’re currently designed to work exclusively with a Target Selector.

Delete your existing automation and then change the blueprint to this (the Target Selector has beed replaced by an Entity Selector and both service calls have been adapted to use it).

blueprint:
  name: Motion-activated Light After Dark
  description: Turn on a light when motion is detected after the sun is below the horizon.
  domain: automation
  source_url: https://github.com/home-assistant/core/blob/551fb449752e1c3f55eb688d24509876020852d1/homeassistant/components/automation/blueprints/motion_light.yaml
  input:
    motion_entity:
      name: Motion Sensor
      selector:
        entity:
          domain: binary_sensor
          device_class: motion
    light_target:
      name: Light
      selector:
        entity:
          domain: light
    no_motion_wait:
      name: Wait time
      description: Time to leave the light on after last motion is detected.
      default: 120
      selector:
        number:
          min: 0
          max: 3600
          unit_of_measurement: seconds

# If motion is detected within the delay,
# we restart the script.
mode: restart
max_exceeded: silent

trigger:
  platform: state
  entity_id: !input motion_entity
  from: "off"
  to: "on"

condition:
  - condition: state
    entity_id: sun.sun
    state: below_horizon
  - condition: state
    entity_id: !input light_target
    state: "off"

action:
  - service: light.turn_on
    data:
      transition: 4
      brightness_pct: 60
      kelvin: 3000
    target:
      entity_id: !input light_target
  - wait_for_trigger:
      platform: state
      entity_id: !input motion_entity
      from: "on"
      to: "off"
  - delay: !input no_motion_wait
  - service: light.turn_off
    target:
      entity_id: !input light_target

After you have modified the blueprint, you’ll need to execute Reload Automations then use the blueprint to create a new automation. This new automation shouldn’t produce the same error message.

Thank you for this! It is working.

How could I add to this template Time condition to be active before and after a certain time.

Like

After 20:00
Before 07:00

Thanks

Here what I added, I dont think it works as the blueprint no longer shows in the list.

To be honest, I just guessed the !input start_time and !input end_time as I dont know how to define this or what it would be.

condition:
  alias: "Time"
  condition: time
  # At least one of the following is required.
  after: !input start_time
  before: !input end_time

Ok, my final result.

blueprint:
  name: Motion-activated Light After Dark
  description: Turn on a light when motion is detected after the sun is below the horizon.
  domain: automation
  source_url: https://github.com/home-assistant/core/blob/551fb449752e1c3f55eb688d24509876020852d1/homeassistant/components/automation/blueprints/motion_light.yaml
  input:
    motion_entity:
      name: Motion Sensor
      selector:
        entity:
          domain: binary_sensor
          device_class: motion
    light_target:
      name: Light
      selector:
        entity:
          domain: light
    no_motion_wait:
      name: Wait time
      description: Time to leave the light on after last motion is detected.
      default: 120
      selector:
        number:
          min: 0
          max: 3600
          unit_of_measurement: seconds
    after_time:
      name: 'After: '
      description: runs only after this time.
      default: '23:59:59'
      selector:
        time:

    before_time:
      name: 'Before: '
      description: runs only before this time.
      default: '05:00:00'
      selector:
        time:

# If motion is detected within the delay,
# we restart the script.
mode: restart
max_exceeded: silent

trigger:
  platform: state
  entity_id: !input motion_entity
  from: "off"
  to: "on"

condition:
  condition: time
  after: !input 'after_time'
  before: !input 'before_time'
  
action:
  - service: light.turn_on
    data:
      transition: 4
      brightness_pct: 60
      kelvin: 3000
    target:
      entity_id: !input light_target
  - wait_for_trigger:
      platform: state
      entity_id: !input motion_entity
      from: "on"
      to: "off"
  - delay: !input no_motion_wait
  - service: light.turn_off
    target:
      entity_id: !input light_target