Automation from blueprint not showing up

I’m trying to generate a blueprint for the following (working) automation

- id: '1665578010584'
  alias: Light Kitchen
  description: ''
  trigger:
  - platform: state
    entity_id:
    - switch.light_kitchen_and_dining_area_l1
    from: 'off'
    to: 'on'
    id: light_off-on
  - platform: state
    entity_id:
    - switch.light_kitchen_and_dining_area_l1
    from: 'on'
    to: 'off'
    id: light_on-off
  - platform: state
    entity_id:
    - binary_sensor.motion_kitchen_occupancy
    from: 'off'
    to: 'on'
    id: motion_occupancy_started
  - platform: state
    entity_id:
    - binary_sensor.motion_kitchen_occupancy
    from: 'on'
    to: 'off'
    id: motion_occupancy_stopped
    for:
      hours: 0
      minutes: '{{ (states(''input_number.light_on_time_kitchen'') | int / 60) | round(0,''floor'')
        }}'
      seconds: '{{ states(''input_number.light_on_time_kitchen'') | int % 60 }}'
  condition:
  - condition: state
    entity_id: input_boolean.disable_all_automations
    state: 'off'
  action:
  - choose:
    - conditions:
      - condition: trigger
        id: light_off-on
      - condition: not
        conditions:
        - condition: state
          entity_id: timer.light_kitchen_helper_timer
          state: active
      sequence:
      - service: input_boolean.turn_on
        data: {}
        target:
          entity_id: input_boolean.light_kitchen_manual
    - conditions:
      - condition: trigger
        id: motion_occupancy_started
      - condition: state
        entity_id: sensor.illumination_low_kitchen
        state: 'True'
      sequence:
      - type: turn_on
        device_id: 21903071448080aa0a9993c1aadf35a0
        entity_id: switch.light_kitchen_and_dining_area_l1
        domain: switch
      - service: timer.start
        data: {}
        target:
          entity_id: timer.light_kitchen_helper_timer
    - conditions:
      - condition: trigger
        id: motion_occupancy_stopped
      - condition: state
        entity_id: input_boolean.light_kitchen_manual
        state: 'off'
      sequence:
      - type: turn_off
        device_id: 21903071448080aa0a9993c1aadf35a0
        entity_id: switch.light_kitchen_and_dining_area_l1
        domain: switch
    - conditions:
      - condition: trigger
        id: light_on-off
      sequence:
      - service: input_boolean.turn_off
        data: {}
        target:
          entity_id: input_boolean.light_kitchen_manual
  mode: single

This is the blueprint I have generated from the automation above

blueprint:
  name: Light via Motion or Manual
  description: Light operates using a motion sensor or manual via a wall switch. If the light is off it is set to automatic mode. If the light turns on via the motion sensor it stays in automatic mode, whereas the mode changes to manual if the light is turned on using the light switch. To bring the light into manual mode if it is already turned on via the motion sensor, simply turn the light of and back on using the wall switch. If the light is in automatic mode, the motion sensor will turn it off once no motion is detected anymore and the light ON-Time (adjustable in the settings) has passed. If the light is in manual mode it stays on until turned off via the wall switch. The light activation via motion sensor is disabled at day time or if the room it too bright. Daytime is determined by the sun elevation angle which can be adjusted in the settengs. The illuminance threshold is adjustable in the settings as well.
  domain: automation
  input:
    target_light:
      name: Light
      description: The target light for the automation
      selector:
        target:
          entity:
            domain: 
              - switch
              - light
    motion_sensor_occupancy:
      name: Motion Sensor Occupancy
      description: The motion sensor occupancy entity
      selector:
        entity:
          domain: binary_sensor
          device_class: motion
    illumination_template_sensor:
      name: Illumination Sensor
      description: A template sensor which returns True if the illumionation is too low or the sun is below the horizont
      selector:
        entity:
          domain: sensor
    light_on_duration:
      name: Light ON-Time Duration
      description: This is an input_number providing the duration in seconds for which the light should stay ON after no motion is detected anymore.
      selector:
        entity:

    automation_kill_switch:
      name: Disable All Automation
      description: A global kill switch (input_boolean) which disables all automations
      selector:
        entity:
          domain: input_boolean

    helper_switch_manual:
      name: Helper Auto/Manual
      description: An input_boolean which which stored the light operation mode (auto/mmanual) 
      selector:
        entity:
          domain: input_boolean
    helper_timer:
      name: Helper Timer
      description: A deticated 2s timer
      selector:
        entity:

trigger:
- platform: state
  entity_id:
  - !input target_light
  from: 'off'
  to: 'on'
  id: light_off-on
- platform: state
  entity_id:
  - !input target_light
  from: 'on'
  to: 'off'
  id: light_on-off
- platform: state
  entity_id:
  - !input motion_sensor_occupancy
  from: 'off'
  to: 'on'
  id: motion_occupancy_started
- platform: state
  entity_id:
  - !input motion_sensor_occupancy
  from: 'on'
  to: 'off'
  id: motion_occupancy_stopped
  for:
    hours: 0
    minutes: '{{ (states(''!input light_on_duration'') | int / 60) | round(0,''floor'') }}'
    seconds: '{{ states(''!input light_on_duration'') | int % 60 }}'
condition:
- condition: state
  entity_id: !input automation_kill_switch
  state: 'off'
action:
- choose:
  - conditions:
    - condition: trigger
      id: light_off-on
    - condition: not
      conditions:
      - condition: state
        entity_id: !input helper_timer
        state: active
    sequence:
    - service: input_boolean.turn_on
      target:
        entity_id: !input helper_switch_manual
  - conditions:
    - condition: trigger
      id: motion_occupancy_started
    - condition: state
      entity_id: !input illumination_template_sensor
      state: 'True'
    sequence:
    - type: turn_on
      entity_id: !input target_light
      domain: switch
    - service: timer.start
      target:
        entity_id: !input helper_timer
  - conditions:
    - condition: trigger
      id: motion_occupancy_stopped
    - condition: state
      entity_id: !input helper_switch_manual
      state: 'off'
    sequence:
    - type: turn_off
      entity_id: !input target_light
      domain: switch
  - conditions:
    - condition: trigger
      id: light_on-off
    sequence:
    - service: input_boolean.turn_off
      target:
        entity_id: !input helper_switch_manual
mode: single

The configuration checker doesn’t find any errors and after reloading the automations the blueprint is shown under Settings / Automations & Scenes / Blueprints. If I create a new automation based on that blueprint with the UI, I can see the following new automation in the automations.yaml file.

- id: '1665587875234'
  alias: Light Kitchen 2
  description: ''
  use_blueprint:
    path: Markus/light_motion-manual.yaml
    input:
      motion_sensor_occupancy: binary_sensor.motion_kitchen_occupancy
      target_light:
        entity_id:
        - switch.light_kitchen_and_dining_area_l1
      illumination_template_sensor: sensor.illumination_low_kitchen
      light_on_duration: input_number.light_on_time_kitchen
      automation_kill_switch: input_boolean.disable_all_automations
      helper_switch_manual: input_boolean.light_kitchen_manual
      helper_timer: timer.light_kitchen_helper_timer

But unfortunately, the automation it is not shown in the UI. Also the automation is not working.
Could somebody please point me in the right direction to find out why the blueprint is not working?

I had another look at it and saw in the logs that there is an actually an error generated.

Logger: homeassistant.components.automation
Source: components/automation/__init__.py:280
Integration: Automation (documentation, issues)
First occurred: 20:38:20 (1 occurrences)
Last logged: 20:38:20

Blueprint Light via Motion or Manual generated invalid automation with inputs OrderedDict([('target_light', OrderedDict([('entity_id', 'switch.light_kitchen_and_dining_area_l2')])), ('motion_sensor_occupancy', 'binary_sensor.motion_dining_room_occupancy'), ('illumination_template_sensor', 'sensor.illumination_low_kitchen'), ('light_on_duration', 'input_number.light_on_time_diningroom'), ('automation_kill_switch', 'input_boolean.disable_all_automations'), ('helper_switch_manual', 'input_boolean.light_diningroom_manual'), ('helper_timer', 'timer.light_diningroom_helper_timer')]): Unable to determine action @ data['action'][0]['choose'][1]['sequence'][0]. Got None

If I interpret that correctly the error could be somewhere in
the first action, second element in the choose list, first element in the sequence.
I replaced the "- type: turn_on " and “- type: turn_off” with “service: switch.turn_on” and “service: switch.turn_off”. I think “- type: turn_…” is not suitable here and I also had removed the device ID.

Now, the blueprint looks like this.

blueprint:
  name: Light via Motion or Manual
  description: Light operates using a motion sensor or manual via a wall switch. If the light is off it is set to automatic mode. If the light turns on via the motion sensor it stays in automatic mode, whereas the mode changes to manual if the light is turned on using the light switch. To bring the light into manual mode if it is already turned on via the motion sensor, simply turn the light of and back on using the wall switch. If the light is in automatic mode, the motion sensor will turn it off once no motion is detected anymore and the light ON-Time (adjustable in the settings) has passed. If the light is in manual mode it stays on until turned off via the wall switch. The light activation via motion sensor is disabled at day time or if the room it too bright. Daytime is determined by the sun elevation angle which can be adjusted in the settengs. The illuminance threshold is adjustable in the settings as well.
  domain: automation
  input:
    target_light:
      name: Light
      description: The target light for the automation
      selector:
        target:
          entity:
            domain: switch
    motion_sensor_occupancy:
      name: Motion Sensor Occupancy
      description: The motion sensor occupancy entity
      selector:
        entity:
          domain: binary_sensor
          device_class: motion
    illumination_template_sensor:
      name: Illumination Sensor
      description: A template sensor which returns True if the illumionation is too low or the sun is below the horizont
      selector:
        entity:
          domain: sensor
    light_on_duration:
      name: Light ON-Time Duration
      description: This is an input_number providing the duration in seconds for which the light should stay ON after no motion is detected anymore.
      selector:
        entity:

    automation_kill_switch:
      name: Disable All Automation
      description: A global kill switch (input_boolean) which disables all automations
      selector:
        entity:
          domain: input_boolean

    helper_switch_manual:
      name: Helper Auto/Manual
      description: An input_boolean which which stored the light operation mode (auto/mmanual) 
      selector:
        entity:
          domain: input_boolean
    helper_timer:
      name: Helper Timer
      description: A deticated 2s timer
      selector:
        entity:

trigger:
- platform: state
  entity_id:
  - !input target_light
  from: 'off'
  to: 'on'
  id: light_off-on
- platform: state
  entity_id:
  - !input target_light
  from: 'on'
  to: 'off'
  id: light_on-off
- platform: state
  entity_id:
  - !input motion_sensor_occupancy
  from: 'off'
  to: 'on'
  id: motion_occupancy_started
- platform: state
  entity_id:
  - !input motion_sensor_occupancy
  from: 'on'
  to: 'off'
  id: motion_occupancy_stopped
  for:
    hours: 0
    minutes: '{{ (states(''!input light_on_duration'') | int / 60) | round(0,''floor'') }}'
    seconds: '{{ states(''!input light_on_duration'') | int % 60 }}'
condition:
- condition: state
  entity_id: !input automation_kill_switch
  state: 'off'
action:
- choose:
  - conditions:
    - condition: trigger
      id: light_off-on
    - condition: not
      conditions:
      - condition: state
        entity_id: !input helper_timer
        state: active
    sequence:
    - service: input_boolean.turn_on
      target:
        entity_id: !input helper_switch_manual
  - conditions:
    - condition: trigger
      id: motion_occupancy_started
    - condition: state
      entity_id: !input illumination_template_sensor
      state: 'True'
    sequence:  
    - service: switch.turn_on
      target:
        entity_id: !input target_light
    - service: timer.start
      target:
        entity_id: !input helper_timer
  - conditions:
    - condition: trigger
      id: motion_occupancy_stopped
    - condition: state
      entity_id: !input helper_switch_manual
      state: 'off'
    sequence:
    - service: switch.turn_off
      target:
        entity_id: !input target_light
  - conditions:
    - condition: trigger
      id: light_on-off
    sequence:
    - service: input_boolean.turn_off
      target:
        entity_id: !input helper_switch_manual
mode: single

But I sill get an error.

Logger: homeassistant.components.automation
Source: components/automation/__init__.py:280
Integration: Automation (documentation, issues)
First occurred: 22:54:26 (1 occurrences)
Last logged: 22:54:26

Blueprint Light via Motion or Manual generated invalid automation with inputs OrderedDict([('target_light', OrderedDict([('entity_id', 'switch.light_backyard')])), ('motion_sensor_occupancy', 'binary_sensor.motion_backyard_occupancy'), ('illumination_template_sensor', 'sensor.illumination_low_backyard'), ('light_on_duration', 'input_number.light_on_time_backyard'), ('automation_kill_switch', 'input_boolean.disable_all_automations'), ('helper_switch_manual', 'input_boolean.light_backyard_manual'), ('helper_timer', 'timer.light_backyard_helper_timer')]): not a valid value for dictionary value @ data['action'][0]['choose'][1]['sequence'][0]['target']['entity_id']. Got None

I also commented the 2 “service: switch.turn_…” sections out. Then the error says

Logger: homeassistant.components.automation
Source: components/automation/__init__.py:280
Integration: Automation (documentation, issues)
First occurred: 22:35:59 (1 occurrences)
Last logged: 22:35:59

Blueprint Light via Motion or Manual generated invalid automation with inputs OrderedDict([('target_light', OrderedDict([('entity_id', 'switch.light_backyard')])), ('motion_sensor_occupancy', 'binary_sensor.motion_backyard_occupancy'), ('illumination_template_sensor', 'sensor.illumination_low_backyard'), ('light_on_duration', 'input_number.light_on_time_backyard'), ('automation_kill_switch', 'input_boolean.disable_all_automations'), ('helper_switch_manual', 'input_boolean.light_backyard_manual'), ('helper_timer', 'timer.light_backyard_helper_timer')]): Entity OrderedDict([('entity_id', 'switch.light_backyard')]) is neither a valid entity ID nor a valid UUID for dictionary value @ data['entity_id']. Got None

Both errors indicate that switch.light_backyard is an invalid entity_ID, but it isn’t.

I don’t understand what’s going wrong here.

You cannot have !input inside a template like this. You will have to store the result of the input into a variable and then use that variable instead.

Try this:

blueprint:
  name: Light via Motion or Manual
  description: Light operates using a motion sensor or manual via a wall switch. If the light is off it is set to automatic mode. If the light turns on via the motion sensor it stays in automatic mode, whereas the mode changes to manual if the light is turned on using the light switch. To bring the light into manual mode if it is already turned on via the motion sensor, simply turn the light of and back on using the wall switch. If the light is in automatic mode, the motion sensor will turn it off once no motion is detected anymore and the light ON-Time (adjustable in the settings) has passed. If the light is in manual mode it stays on until turned off via the wall switch. The light activation via motion sensor is disabled at day time or if the room it too bright. Daytime is determined by the sun elevation angle which can be adjusted in the settengs. The illuminance threshold is adjustable in the settings as well.
  domain: automation
  input:
    target_light:
      name: Light
      description: The target light for the automation
      selector:
        target:
          entity:
            domain: switch
    motion_sensor_occupancy:
      name: Motion Sensor Occupancy
      description: The motion sensor occupancy entity
      selector:
        entity:
          domain: binary_sensor
          device_class: motion
    illumination_template_sensor:
      name: Illumination Sensor
      description: A template sensor which returns True if the illumionation is too low or the sun is below the horizont
      selector:
        entity:
          domain: sensor
    light_on_duration:
      name: Light ON-Time Duration
      description: This is an input_number providing the duration in seconds for which the light should stay ON after no motion is detected anymore.
      selector:
        entity:

    automation_kill_switch:
      name: Disable All Automation
      description: A global kill switch (input_boolean) which disables all automations
      selector:
        entity:
          domain: input_boolean

    helper_switch_manual:
      name: Helper Auto/Manual
      description: An input_boolean which which stored the light operation mode (auto/mmanual) 
      selector:
        entity:
          domain: input_boolean
    helper_timer:
      name: Helper Timer
      description: A deticated 2s timer
      selector:
        entity:

variables:
  light_on_duration: !input light_on_duration

trigger:
- platform: state
  entity_id:
  - !input target_light
  from: 'off'
  to: 'on'
  id: light_off-on
- platform: state
  entity_id:
  - !input target_light
  from: 'on'
  to: 'off'
  id: light_on-off
- platform: state
  entity_id:
  - !input motion_sensor_occupancy
  from: 'off'
  to: 'on'
  id: motion_occupancy_started
- platform: state
  entity_id:
  - !input motion_sensor_occupancy
  from: 'on'
  to: 'off'
  id: motion_occupancy_stopped
  for:
    hours: 0
    minutes: '{{ (states(light_on_duration) | int(0) / 60) | round(0) }}'
    seconds: '{{ states(!input light_on_duration) | int(0) % 60 }}'
condition:
- condition: state
  entity_id: !input automation_kill_switch
  state: 'off'
action:
- choose:
  - conditions:
    - condition: trigger
      id: light_off-on
    - condition: not
      conditions:
      - condition: state
        entity_id: !input helper_timer
        state: active
    sequence:
    - service: input_boolean.turn_on
      target:
        entity_id: !input helper_switch_manual
  - conditions:
    - condition: trigger
      id: motion_occupancy_started
    - condition: state
      entity_id: !input illumination_template_sensor
      state: 'True'
    sequence:  
    - service: switch.turn_on
      target:
        entity_id: !input target_light
    - service: timer.start
      target:
        entity_id: !input helper_timer
  - conditions:
    - condition: trigger
      id: motion_occupancy_stopped
    - condition: state
      entity_id: !input helper_switch_manual
      state: 'off'
    sequence:
    - service: switch.turn_off
      target:
        entity_id: !input target_light
  - conditions:
    - condition: trigger
      id: light_on-off
    sequence:
    - service: input_boolean.turn_off
      target:
        entity_id: !input helper_switch_manual
mode: single

Thanks for that hint Edward, but unfortunately that isn’t the cause of the error. I’m still getting the same error message

Logger: homeassistant.components.automation
Source: components/automation/__init__.py:280
Integration: Automation (documentation, issues)
First occurred: 23:25:55 (1 occurrences)
Last logged: 23:25:55

Blueprint Light via Motion or Manual Test generated invalid automation with inputs OrderedDict([('target_light', OrderedDict([('entity_id', 'switch.light_backyard')])), ('motion_sensor_occupancy', 'binary_sensor.motion_backyard_occupancy'), ('illumination_template_sensor', 'sensor.illumination_low_backyard'), ('light_on_duration', 'input_number.light_on_time_backyard'), ('automation_kill_switch', 'input_boolean.disable_all_automations'), ('helper_switch_manual', 'input_boolean.light_backyard_manual'), ('helper_timer', 'timer.light_backyard_helper_timer')]): not a valid value for dictionary value @ data['action'][0]['choose'][1]['sequence'][0]['target']['entity_id']. Got None

Any other idea what could be wrong?

So, please try this one (I will explain in another post what I’ve done):

blueprint:
  name: Light via Motion or Manual
  description: Light operates using a motion sensor or manual via a wall switch. If the light is off it is set to automatic mode. If the light turns on via the motion sensor it stays in automatic mode, whereas the mode changes to manual if the light is turned on using the light switch. To bring the light into manual mode if it is already turned on via the motion sensor, simply turn the light of and back on using the wall switch. If the light is in automatic mode, the motion sensor will turn it off once no motion is detected anymore and the light ON-Time (adjustable in the settings) has passed. If the light is in manual mode it stays on until turned off via the wall switch. The light activation via motion sensor is disabled at day time or if the room it too bright. Daytime is determined by the sun elevation angle which can be adjusted in the settengs. The illuminance threshold is adjustable in the settings as well.
  domain: automation
  input:
    target_light:
      name: Light
      description: The target light for the automation
      selector:
        target:
          entity:
            domain: [light, switch]
    motion_sensor_occupancy:
      name: Motion Sensor Occupancy
      description: The motion sensor occupancy entity
      selector:
        entity:
          domain: binary_sensor
          device_class: motion
    illumination_template_sensor:
      name: Illumination Sensor
      description: A template sensor which returns True if the illumionation is too low or the sun is below the horizon
      selector:
        entity:
          domain: sensor
    light_on_duration:
      name: Light ON-Time Duration
      description: This is an input_number providing the duration in seconds for which the light should stay ON after no motion is detected anymore.
      selector:
        entity:

    automation_kill_switch:
      name: Disable All Automation
      description: A global kill switch (input_boolean) which disables all automations
      selector:
        entity:
          domain: input_boolean

    helper_switch_manual:
      name: Helper Auto/Manual
      description: An input_boolean which which stored the light operation mode (auto/mmanual) 
      selector:
        entity:
          domain: input_boolean
    helper_timer:
      name: Helper Timer
      description: A deticated 2s timer
      selector:
        entity:

variables:
  light_on_duration: !input light_on_duration

trigger:
  - id: light_off_on
    platform: state
    entity_id: !input target_light
    from: 'off'
    to: 'on'

  - id: light_on_off
    platform: state
    entity_id: !input target_light
    from: 'on'
    to: 'off'

  - id: motion_occupancy_started
    platform: state
    entity_id: !input motion_sensor_occupancy
    from: 'off'
    to: 'on'

  - id: motion_occupancy_stopped
    platform: state
    entity_id: !input motion_sensor_occupancy
    from: 'on'
    to: 'off'
    for:
      hours: 0
      minutes: '{{ (states(light_on_duration) | int(0) / 60) | round(0) }}'
      seconds: '{{ states(!input light_on_duration) | int(0) % 60 }}'

condition:
  - condition: state
    entity_id: !input automation_kill_switch
    state: 'off'

action:
  - choose:
      - conditions:
          - condition: trigger
            id: light_off_on
          - condition: not
            conditions:
              - condition: state
                entity_id: !input helper_timer
                state: active
        sequence:
          - service: input_boolean.turn_on
            target:
              entity_id: !input helper_switch_manual
      - conditions:
          - condition: trigger
            id: motion_occupancy_started
          - condition: state
            entity_id: !input illumination_template_sensor
            state: 'True'
        sequence:
          - service: homeassistant.turn_on
            target:
              entity_id: !input target_light
          - service: timer.start
            target:
              entity_id: !input helper_timer
      - conditions:
          - condition: trigger
            id: motion_occupancy_stopped
          - condition: state
            entity_id: !input helper_switch_manual
            state: 'off'
        sequence:
          - service: homeassistant.turn_off
            target:
              entity_id: !input target_light
      - conditions:
          - condition: trigger
            id: light_on_off
        sequence:
          - service: input_boolean.turn_off
            target:
              entity_id: !input helper_switch_manual
    default: []

mode: single

The main thing I’ve worked on was the indentation. I’m pretty sure that wasn’t correct.
How have you copied your code from the automation to the blueprint? Have the indentation changed with that?
It didn’t looks correct in your original automation also.

I’ve added the option to select a light (mainly to facilitate my test, so you can roll back this, but you probably want to have a more generic blueprint and, if changing a light is the goal, you should consider supporting lights :wink: ).

In order to support both switches and lights I had to change the service call to the more generic homeassistant.turn_off instead of switch.turn_off (same for turning on). If you are not familiar with this, you can find more details here: Service Calls - Home Assistant (home-assistant.io)

Are you sure the “True” from your sensor have the upper case in the first char? Is this a template sensor you have made?
Typically, sensors will be “on” or “off” only, and latter translated to something else in the UI. Also, it’s typically all lower case. But if this is a custom template sensor, then it will depend on what you have set.
You can double check by going to Developers Tools and selecting the tab States. Search for your sensor and over there you will see the state exactly how it will be seen by the automations.

Is this the right mode for you? It can be a challenge when you have a trigger and a “for”…
I’m thinking, what happens if the light is turned on by a motion, then right after that someone turns the light off manually? What happens when the trigger finished, and the automation is triggered by motion stopping for X amount of time?

Hi Edward,

thanks for your time to look over the blueprint.

I copied the automation into the blueprint using VS Code. So the indentation should be OK. Maybe the problem here is that because the forum doesn’t offer a mono space font it looks incorrect as the white spaces don’t align with other characters.

Thanks for adding lights. I had the switch and light domain in my original blueprint but later removed it because I didn’t know how to use both service calls switch.turn_… and light.turn_… at the same time.and also wanted to remove possible error sources. Good to know about homeassistant.turn

“True / False” is what is shown under the entity info and under the Developer Tools / STATES
Screenshot 2022-10-14 212810
Also it works that way in my automation which is the basis for the blueprint.

If the light is turned on by the motion sensor and then back off with the wall switch and then the delayed trigger from “motion sensor stopped detecting motion” fires, nothing unexpected happens. The action for this trigger is “turn the light off” but it is already off anyway.
If the light is turned on again with the wall switch before the motion stopped trigger fires, then the input_boolean “light_manual” is set which prevents the light from turning off when the motion stopped action runs.
The only annoying thing which I don’t think I can change without setting the motion sensor cool-off period to a very low value which might drain the battery quickly is that the motion activation of the light might not work any more if you turn off the light with the switch and you are still in the room.
The light only turns back on if the occupancy goes from clear to detected. But the motion sensor stays in the state detected because it is retriggered from you still being in the room.So you have to stand very still until the cool-off period is over. It would be great if one could issue a command to the sensor to reset its state to clear so that it can trigger again immediately.

Now to the most important point. I’ve tried your blueprint, but unfortunately it behaves exactly the same as before. If an automation is generated based on the blueprint the automation doesn’t show up in the list of automations and the same error as before can be found in the logs.

Logger: homeassistant.components.automation
Source: components/automation/__init__.py:280
Integration: Automation (documentation, issues)
First occurred: 21:05:18 (1 occurrences)
Last logged: 21:05:18

Blueprint Blueprint Test generated invalid automation with inputs OrderedDict([('target_light', OrderedDict([('entity_id', 'switch.light_backyard')])), ('motion_sensor_occupancy', 'binary_sensor.motion_backyard_occupancy'), ('illumination_template_sensor', 'sensor.illumination_low_backyard'), ('light_on_duration', 'input_number.light_on_time_backyard'), ('automation_kill_switch', 'input_boolean.disable_all_automations'), ('helper_switch_manual', 'input_boolean.light_backyard_manual'), ('helper_timer', 'timer.light_backyard_helper_timer')]): not a valid value for dictionary value @ data['action'][0]['choose'][1]['sequence'][0]['target']['entity_id']. Got None

My apologies, I’ve looked at everything else and didn’t looked at the error you’re asking for help… I will focus on that now, however I cannot try it on my system as I don’t have similar sensor to the ones you use in your automation, so I will need your help with the new error messages (if any).

Please try this one:

blueprint:
  name: Light via Motion or Manual
  description: Light operates using a motion sensor or manual via a wall switch. If the light is off it is set to automatic mode. If the light turns on via the motion sensor it stays in automatic mode, whereas the mode changes to manual if the light is turned on using the light switch. To bring the light into manual mode if it is already turned on via the motion sensor, simply turn the light of and back on using the wall switch. If the light is in automatic mode, the motion sensor will turn it off once no motion is detected anymore and the light ON-Time (adjustable in the settings) has passed. If the light is in manual mode it stays on until turned off via the wall switch. The light activation via motion sensor is disabled at day time or if the room it too bright. Daytime is determined by the sun elevation angle which can be adjusted in the settengs. The illuminance threshold is adjustable in the settings as well.
  domain: automation
  input:
    target_light:
      name: Light
      description: The target light for the automation
      selector:
        target:
          entity:
            domain: [light, switch]
    motion_sensor_occupancy:
      name: Motion Sensor Occupancy
      description: The motion sensor occupancy entity
      selector:
        entity:
          domain: binary_sensor
          device_class: motion
    illumination_template_sensor:
      name: Illumination Sensor
      description: A template sensor which returns True if the illumionation is too low or the sun is below the horizon
      selector:
        entity:
          domain: sensor
    light_on_duration:
      name: Light ON-Time Duration
      description: This is an input_number providing the duration in seconds for which the light should stay ON after no motion is detected anymore.
      selector:
        entity:

    automation_kill_switch:
      name: Disable All Automation
      description: A global kill switch (input_boolean) which disables all automations
      selector:
        entity:
          domain: input_boolean

    helper_switch_manual:
      name: Helper Auto/Manual
      description: An input_boolean which which stored the light operation mode (auto/mmanual) 
      selector:
        entity:
          domain: input_boolean
    helper_timer:
      name: Helper Timer
      description: A deticated 2s timer
      selector:
        entity:

variables:
  light_on_duration: !input light_on_duration

trigger:
  - id: light_off_on
    platform: state
    entity_id: !input target_light
    from: 'off'
    to: 'on'

  - id: light_on_off
    platform: state
    entity_id: !input target_light
    from: 'on'
    to: 'off'

  - id: motion_occupancy_started
    platform: state
    entity_id: !input motion_sensor_occupancy
    from: 'off'
    to: 'on'

  - id: motion_occupancy_stopped
    platform: state
    entity_id: !input motion_sensor_occupancy
    from: 'on'
    to: 'off'
    for:
      hours: 0
      minutes: '{{ (states(light_on_duration) | int(0) / 60) | round(0) }}'
      seconds: '{{ states(!input light_on_duration) | int(0) % 60 }}'

condition:
  - condition: state
    entity_id: !input automation_kill_switch
    state: 'off'

action:
  - choose:
      - conditions:
          - condition: trigger
            id: light_off_on
          - condition: not
            conditions:
              - condition: state
                entity_id: !input helper_timer
                state: active
        sequence:
          - service: input_boolean.turn_on
            target:
              entity_id: !input helper_switch_manual
      - conditions:
          - condition: trigger
            id: motion_occupancy_started
          - condition: state
            entity_id: !input illumination_template_sensor
            state: 'True'
        sequence:
          - service: homeassistant.turn_on
            target: !input target_light
          - service: timer.start
            target:
              entity_id: !input helper_timer
      - conditions:
          - condition: trigger
            id: motion_occupancy_stopped
          - condition: state
            entity_id: !input helper_switch_manual
            state: 'off'
        sequence:
          - service: homeassistant.turn_off
            target: !input target_light
      - conditions:
          - condition: trigger
            id: light_on_off
        sequence:
          - service: input_boolean.turn_off
            target:
              entity_id: !input helper_switch_manual
    default: []

mode: single

Your target_light input is of the type target, so you cannot use as an entity_id.

Mmmm… Then it will beak at the trigger… We will have to change the input type…

This should work:

blueprint:
  name: Light via Motion or Manual
  description: Light operates using a motion sensor or manual via a wall switch. If the light is off it is set to automatic mode. If the light turns on via the motion sensor it stays in automatic mode, whereas the mode changes to manual if the light is turned on using the light switch. To bring the light into manual mode if it is already turned on via the motion sensor, simply turn the light of and back on using the wall switch. If the light is in automatic mode, the motion sensor will turn it off once no motion is detected anymore and the light ON-Time (adjustable in the settings) has passed. If the light is in manual mode it stays on until turned off via the wall switch. The light activation via motion sensor is disabled at day time or if the room it too bright. Daytime is determined by the sun elevation angle which can be adjusted in the settengs. The illuminance threshold is adjustable in the settings as well.
  domain: automation
  input:
    target_light:
      name: Light
      description: The target light for the automation
      selector:
        entity:
          domain: [light, switch]
    motion_sensor_occupancy:
      name: Motion Sensor Occupancy
      description: The motion sensor occupancy entity
      selector:
        entity:
          domain: binary_sensor
          device_class: motion
    illumination_template_sensor:
      name: Illumination Sensor
      description: A template sensor which returns True if the illumionation is too low or the sun is below the horizon
      selector:
        entity:
          domain: sensor
    light_on_duration:
      name: Light ON-Time Duration
      description: This is an input_number providing the duration in seconds for which the light should stay ON after no motion is detected anymore.
      selector:
        entity:

    automation_kill_switch:
      name: Disable All Automation
      description: A global kill switch (input_boolean) which disables all automations
      selector:
        entity:
          domain: input_boolean

    helper_switch_manual:
      name: Helper Auto/Manual
      description: An input_boolean which which stored the light operation mode (auto/mmanual) 
      selector:
        entity:
          domain: input_boolean
    helper_timer:
      name: Helper Timer
      description: A deticated 2s timer
      selector:
        entity:

variables:
  light_on_duration: !input light_on_duration

trigger:
  - id: light_off_on
    platform: state
    entity_id: !input target_light
    from: 'off'
    to: 'on'

  - id: light_on_off
    platform: state
    entity_id: !input target_light
    from: 'on'
    to: 'off'

  - id: motion_occupancy_started
    platform: state
    entity_id: !input motion_sensor_occupancy
    from: 'off'
    to: 'on'

  - id: motion_occupancy_stopped
    platform: state
    entity_id: !input motion_sensor_occupancy
    from: 'on'
    to: 'off'
    for:
      hours: 0
      minutes: '{{ (states(light_on_duration) | int(0) / 60) | round(0) }}'
      seconds: '{{ states(!input light_on_duration) | int(0) % 60 }}'

condition:
  - condition: state
    entity_id: !input automation_kill_switch
    state: 'off'

action:
  - choose:
      - conditions:
          - condition: trigger
            id: light_off_on
          - condition: not
            conditions:
              - condition: state
                entity_id: !input helper_timer
                state: active
        sequence:
          - service: input_boolean.turn_on
            target:
              entity_id: !input helper_switch_manual
      - conditions:
          - condition: trigger
            id: motion_occupancy_started
          - condition: state
            entity_id: !input illumination_template_sensor
            state: 'True'
        sequence:
          - service: homeassistant.turn_on
            target:
              entity_id: !input target_light
          - service: timer.start
            target:
              entity_id: !input helper_timer
      - conditions:
          - condition: trigger
            id: motion_occupancy_stopped
          - condition: state
            entity_id: !input helper_switch_manual
            state: 'off'
        sequence:
          - service: homeassistant.turn_off
            target:
              entity_id: !input target_light
      - conditions:
          - condition: trigger
            id: light_on_off
        sequence:
          - service: input_boolean.turn_off
            target:
              entity_id: !input helper_switch_manual
    default: []

mode: single

By the way, you will have to create your automation again, as the input type changed and the previous entries will be invalid (you will have to remove those from automations.yaml to stop receiving error messages).

Please don’t apologize, I’m grateful that I’m getting help with that.
I tried the latest blueprint you posted. I got the following error

...
expected float for dictionary value @ data['for']['minutes']. Got None expected float for dictionary value @ data['for']['seconds']. Got None

but that was because the templates for minutes and seconds were not correct. After I modified them, generating an automation based on the blueprint worked without errors and the automation showed up in the list this time.

The automation seemed to work first. It turned on the light trigger by motion, but the light did not turn off after the motion stopped and the time should have been over. My conclusion was that there is probably still something wrong with the templates or setting the variable.
I replaced the templates with fixed numbers and then the blueprint based automation ran as expected.

To figure out what’s wrong I tried the templates via “Developer Tools” / Templates. To get it to work, I had to turn the variable value into a string.

{% set light_on_duration = 'input_number.light_on_time_backyard' %}

'{{ (states(light_on_duration) | int / 60) | round(0) }}'
'{{ states(light_on_duration) | int % 60 }}'

I tried to define the variable like this

variables:
  light_on_duration: '!input light_on_duration'

but that still doesn’t work. Is the variable of type string if we use
light_on_duration: !input light_on_duration ?

Good… Looks like we are progressing…

Please try this:

blueprint:
  name: Light via Motion or Manual
  description: Light operates using a motion sensor or manual via a wall switch. If the light is off it is set to automatic mode. If the light turns on via the motion sensor it stays in automatic mode, whereas the mode changes to manual if the light is turned on using the light switch. To bring the light into manual mode if it is already turned on via the motion sensor, simply turn the light of and back on using the wall switch. If the light is in automatic mode, the motion sensor will turn it off once no motion is detected anymore and the light ON-Time (adjustable in the settings) has passed. If the light is in manual mode it stays on until turned off via the wall switch. The light activation via motion sensor is disabled at day time or if the room it too bright. Daytime is determined by the sun elevation angle which can be adjusted in the settengs. The illuminance threshold is adjustable in the settings as well.
  domain: automation
  input:
    target_light:
      name: Light
      description: The target light for the automation
      selector:
        entity:
          domain: [light, switch]
    motion_sensor_occupancy:
      name: Motion Sensor Occupancy
      description: The motion sensor occupancy entity
      selector:
        entity:
          domain: binary_sensor
          device_class: motion
    illumination_template_sensor:
      name: Illumination Sensor
      description: A template sensor which returns True if the illumionation is too low or the sun is below the horizon
      selector:
        entity:
          domain: sensor
    light_on_duration:
      name: Light ON-Time Duration
      description: This is an input_number providing the duration in seconds for which the light should stay ON after no motion is detected anymore.
      selector:
        entity:

    automation_kill_switch:
      name: Disable All Automation
      description: A global kill switch (input_boolean) which disables all automations
      selector:
        entity:
          domain: input_boolean

    helper_switch_manual:
      name: Helper Auto/Manual
      description: An input_boolean which which stored the light operation mode (auto/mmanual) 
      selector:
        entity:
          domain: input_boolean
    helper_timer:
      name: Helper Timer
      description: A deticated 2s timer
      selector:
        entity:

variables:
  light_on_duration_helper: !input light_on_duration
  light_on_duration: "{{ states(light_on_duration_helper) | float(0) | round(0) }}"

trigger:
  - id: light_off_on
    platform: state
    entity_id: !input target_light
    from: 'off'
    to: 'on'

  - id: light_on_off
    platform: state
    entity_id: !input target_light
    from: 'on'
    to: 'off'

  - id: motion_occupancy_started
    platform: state
    entity_id: !input motion_sensor_occupancy
    from: 'off'
    to: 'on'

  - id: motion_occupancy_stopped
    platform: state
    entity_id: !input motion_sensor_occupancy
    from: 'on'
    to: 'off'
    for:
      seconds: "{{ light_on_duration }}"

condition:
  - condition: state
    entity_id: !input automation_kill_switch
    state: 'off'

action:
  - choose:
      - conditions:
          - condition: trigger
            id: light_off_on
          - condition: not
            conditions:
              - condition: state
                entity_id: !input helper_timer
                state: active
        sequence:
          - service: input_boolean.turn_on
            target:
              entity_id: !input helper_switch_manual
      - conditions:
          - condition: trigger
            id: motion_occupancy_started
          - condition: state
            entity_id: !input illumination_template_sensor
            state: 'True'
        sequence:
          - service: homeassistant.turn_on
            target:
              entity_id: !input target_light
          - service: timer.start
            target:
              entity_id: !input helper_timer
      - conditions:
          - condition: trigger
            id: motion_occupancy_stopped
          - condition: state
            entity_id: !input helper_switch_manual
            state: 'off'
        sequence:
          - service: homeassistant.turn_off
            target:
              entity_id: !input target_light
      - conditions:
          - condition: trigger
            id: light_on_off
        sequence:
          - service: input_boolean.turn_off
            target:
              entity_id: !input helper_switch_manual
    default: []

mode: single

I tried your blueprint, but it still doesn’t work. The light doesn’t turn off. There was no error in the logs.

I thought I’ll try it with a constant value first. Like this

variables:
  light_on_duration_helper: !input light_on_duration
  light_on_duration: "{{ 50 }}"

This generated the error

Error rendering 'Blueprint Test' for template: expected float for dictionary value @ data['seconds']

Removing the " " around the template like this

variables:
  light_on_duration_helper: !input light_on_duration
  light_on_duration: {{ 50 }}

also doesn’t work and creates a config error.

This doesn’t work either (no error, just not turning off)

variables:
  light_on_duration_helper: !input light_on_duration
  light_on_duration: 50

The only version which I found working is if the “for seconds” value is set to a constant value directly like this

    for:
      seconds: "50"

or

    for:
      seconds: 50

Looks like blueprints don’t support variables be used for the “for seconds, minutes, hours” values although automations do. I might have to use an additional helper timer to realise the turn-off delay.

Are you sure that works for automations? It should be the same.

By the way, what is the reason you are using an input for this? Why don’t you enter the value directly as an input in your blueprint? Are you planning to have a card where anyone can select this time?

This looks like a bug that was never fixed, so we will need a different approach:

1 Like

Yes, I’m sure the template works in automations. I’m using it.


I’ve just started to built my HA system. I created the automation for 1 light and now, as I’m happy with it, I want to duplicate it for all other lights. As it is a fair bit of work to just copy the automation and replace all sensors and actors and as it is also error-prone I decided to create a blueprint and use that to generate all automations.

Yes, I could just edit the automations, but I wanted it to be adjustable from my dashboards. I have a subview with settings where I wanted to add the times.

I have opened a new HA issue with a simple example to demonstrate the problem.

What would be your suggestion how to realize this most efficiently? Create a time for each light and use that as an input in the blueprint. Then in the “motion has stopped” trigger action start the timer and created a new trigger for when the timer expires to turn off the light?

One timer per light could be a way to go, but certainly not the easiest one to setup and maintain.
When I come back home I will take a look again at your automation and come back with other suggestions (if any).

Don’t worry Edward, I will look into ways to realise this myself. I don’t want to take up more of your time. You already helped me a lot. Thank you very much for that.
Also, somebody has the same problem in scripts and has opened issue #80456 just yesterday. So the problem might be even fixed by the developers.

What is the helper timer doing?

I understand it starts when the light turns on, but then you check it as a condition for the light to turn on. What is the goal here?

I use that timer to figure out if the light was turned on manually by the wall switch or automatically by the motion sensor.
If the 2 triggers “motion detected” and “light off->on” are activated very close together (with in the 2s runtime of the helper time), then I know that the light was activated by the motion sensor. If the trigger “light off->on” fires alone, then the light was turned on by the light switch and I set the mode to manual.