How to write a "For: <time>" entry with an !input parameter in a blueprint?

In a blueprint, I define a time input …

input:
    door_or_window_open_recognition_time:
      name: Door or window open recognition time
      description: The time for which a door or window can be open before the heating switches off
      selector:
        time:
      default: "00:03:00"

… then try to use it as a “for:” entry is a trigger …


trigger:
  - type: opened
    id: door_or_window_opened
    platform: device
    entity_id: !input door_or_window_opening_sensor
    domain: binary_sensor
    for: !input door_or_window_open_recognition_time. # <<-- not accepted

… the “for:” line is rejected as a “malformed message”.

How should I write it?

I don’t think for: will work with a time input. You will have ti use a number input to enter the number of seconds (or do some calculations if you want your input in hours or minutes).

Something like:

input:
    door_or_window_open_recognition_time:
      name: Door or window open recognition time (in seconds)
      description: The time for which a door or window can be open before the heating switches off
      default: 180
      selector:
        number:
          min: 0
          max: 3600
          step: 1
          unit_of_measurement: seconds
          mode: slider

And remove the “.” by the end or your input name (I believe this is the source of your error message):

trigger:
  - type: opened
    id: door_or_window_opened
    platform: device
    entity_id: !input door_or_window_opening_sensor
    domain: binary_sensor
    for: !input door_or_window_open_recognition_time

That was not in the original code, must have snuck in when I pasted it here

1 Like

Thanks for the tip but the problem seems to be more fundamental. I cannot find a way to use ANY template within a “for:” statement.

I did some experiments, with results below. It’s an odd one because most changes I make are accepted by the editor (Studio Code Server). I have to look back at the Automations page to see whether the automation created from the blueprint is still there! If not, the test fails. Luckily, correcting the code does bring it back, so it seems it is just disabled if there is an error in it, even if there is no message to say so.

The pertinent results are

  1. After the for:key you cannot just put a number (of seconds). This fails:
    for: 10 
  1. You CAN write just seconds without the hours or minutes:
    for:
        seconds: 10 
  1. The number of seconds can be more than 59. With the following it correctly waited 1 minute 20 seconds.
    for:
        seconds: 80 
  1. The number of seconds is treated as text. So this is OK too
    for:
        seconds:  '10' 
  1. HOWEVER, it seems that no kind of template can be used to define the number of seconds. Even this fails
    for:
        seconds: '{{ 10 }}' 

So, is it the case that
a) trigger “for:” statements cannot use templates? And
b) therefore, they cannot be set using a blueprint input?

Hi,

Try the duration selector. This is an example from one of my blueprints, works fine:

time_left_open:
      name: Time left open
      description: Time a window is permitted to be left open before a notification is sent
      selector:
        duration:

and here’s the trigger:

trigger:
  - platform: state
    id: window left open for too long
    entity_id: !input window_contact
    from: "off"
    to: "on"
    for: !input time_left_open

Are you sure? As soon as I write the line

 
 for: !input door_or_window_open_recognition_time

… my automation is disabled :frowning:

I did check the input definition name is correct

input:
  door_or_window_open_recognition_time:
      name: Door or window open recognition time
      description: The time for which a door or window can be open before the heating switches off
      selector:
        duration:
      default: "00:03:00"

… and that is not the problem.

@AndySymons
Could you try with omitting the default? Mine works with 17 windows, so yeah I’m sure

Edit: Just noticed that your trigger is totally different from mine. Could that be the issue?

Further trial-and-error (I still get no error messages) shows that it does not matter whether the input is time or duration, or whether there is a default or not. What fixed it was changing the trigger platform from ‘device’ to ‘state’. It seems that only the ‘device’ platform has the problem. I cannot imagine why, but ‘state’ is actually more suitable anyway in my case, so this is solved :slight_smile: :slight_smile:

Glad you figured it out :slightly_smiling_face:

@AndySymons, I do remember someone else having a discussion around using an input into for:, that was a couple of months ago, and I remember he ended up creating a bug in Github about this. You probably can find there to understand if that is the same case that you have.

However, as other said, I also have a few blueprints using for: !input xxx and they are all working fine, like this, which I recently changed to use for: !input (replacing a delay: !input in the actions) and it is working fine:

Maybe you can download that blueprint and try it on your system. This one is pretty easy to test, as it will turn on some device when it is off for certain time and, if that works for you, then you know it is something on your code and might help you on the troubleshooting.

Thanks for responding. I’d like to know more about the bug report as I did not find it by searching “github bug homeassistant for: !input”.

As for your example, like @DarkWarden, you are also using the platform state, which works for me too. A bug report would have to refer specifically to the device platform.

I couldn’t find as well. Will try again tomorrow, as it is quite late now.

FYI I raised my own github bug report
trigger with device platform rejects blueprint !input in a for: statement

1 Like