Motion activated light cleared dynamic delay value

Hello,

I have a lighting automation blueprint under work, and I would like to have the motion cleared for x minutes trigger to be dynamic based on an input number. The intention is to create ui cards to allow different settings for different rooms etc. and then the motion delay could be adjusted from that input number instead of having it fixed.

Current trigger

trigger:
  - platform: template
    value_template: "{{ occupancy_sensors | select('is_state', 'on') | list | count > 0 }}"
    id: Motion-Detected
  - platform: template
    value_template: "{{ occupancy_sensors | select('is_state', 'on') | list | count == 0 }}"
    id: Motion-Cleared
    for:
      hours: 0
      minutes: 5
      seconds: 0

Wanted trigger

trigger:
  - platform: template
    value_template: "{{ occupancy_sensors | select('is_state', 'on') | list | count > 0 }}"
    id: Motion-Detected
  - platform: template
    value_template: "{{ occupancy_sensors | select('is_state', 'on') | list | count == 0 }}"
    id: Motion-Cleared
    for:
      hours: 0
      minutes: "{{states(delay_input_number) | float(5)}}"
      seconds: 0

I tried the above approach but it’s not working, any ideas?

Thank you!

Did you check if this works? Triggers are affected by limited templates and is_state is in that list.
You may have re-think this a bit.

I suggest triggering on the sensor changes alone, and use conditions block and/or choose to pull in your logic.
Automations #2: the condition block.

Hello, thank you for the answer and the hint on limited templates. I have a working blueprint just without the minutes: "{{states(delay_input_number) | float(5)}}" part, since that does not work. But I think that is essential for this type of automation, it is possible to do this number selector for the blueprint, but I’d prefer having an input_number for different rooms, so that it would be easy to adjust.

The format of the number is wrong, delay is picky.
On mine I changed from an input_number to a duration selector, that produces the correct format value.

HA_Blueprints/Automations/Person_Alert_Blueprint.yaml at c05d6fb431c1d84cb145c7d6dd5ffe5a60b1d9e2 · SirGoodenough/HA_Blueprints · GitHub.

But that still means that the value needs to be changed from blueprint settings. I think the reason why input_number is not working is more related to the logic how the automations are run, and there is no implementation for a dynamic delay.

try casting to int instead. I don’t think minutes support floats.

It could be that too.
I just decided Duration looks better in the user end picking the length of time, so I suggest that now.
Duration is a dictionary or map with hrs, min, sec I believe and you can just drop it in with the !input tag and done.

But int is worth a try.

If you are logged into the HA Discord, there is this convo

If you haven’t logged into it, let me know, I’ll drop an invite here.