Use of Optional Device Selector (default:) in the Blueprint Template

I would like to have the following button as optional, but I can’t figure out what should be the default value in the blueprint so this device can be optional (not selected).

Device: IKEA TRÅDFRI shortcut button
Available entities: battery, identify, LQI and RSSI

Working automation when the existing device_id is set in the default value:

blueprint:
  ...
  input:
    overwrite_button:
      name: Overwrite Button (Optional)
      description: When pressed, ignores automation for duration of 'Overwrite Time'.
      default: df04521ef69c3a9c8b9998d75db7bd57
      selector:
        device:
trigger:
  - id: overwrite_button
    device_id: !input overwrite_button
    domain: zha
    platform: device
    type: remote_button_short_press
    subtype: turn_on

It seems that HA expects valid device_id from the dictionary, therefore setting the default value to any of the following doesn’t work when the device is not selected:

default: df000111222333444555666777888999
default:
default: ''
default: []
default: none
default: 'none'
default: None
default: 'None'
default: unknown
default: 'unknown'
default: null

Any idea what could be the valid default: entry for the optional device?

According to this:
Selectors - Home Assistant.
The first on that list should work.

I try to avoid device triggers where possible but in this case you may need it.

If you wanted the input to be allowed to be empty, default: should work as the selector result is a string.

If you get an error with what you have there, make sure the default line is what is causing the error.

That doc link specifically suggests using the ui editor to ‘build’ the device trigger for you to get all the syntax right.

1 Like

I have checked the trigger with the UI and verified that the default: is what is causing the blueprints without button defined to become unavailable. When I select the device in these blueprints, the automation becomes available and works. When I remove that device again and save the changes, I get:
Message malformed: Unknown device"

It seems like that the device can’t be empty.

I assume that I don’t have to do e.g. something like this in the trigger for the device_id:

trigger:
  - id: overwrite_button
    device_id: "{{ device_id(overwrite_button) }}"
    ...

I had the trigger completely wrong. It was a valid and functional code when the default device was specified, but not when the default: was empty.

Following code has fixed that:

blueprint:
  ...
  input:
    overwrite_button:
      name: Overwrite Button (Optional)
      description: When pressed, ignores door-related automation for duration of 'Overwrite Time'.
      default:
      selector:
        device:
trigger:
  - id: overwrite_button
    platform: event
    event_type: zha_event
    event_data:
      device_id: !input overwrite_button