Template doesn't work in trigger "for:" but in the action "message:"

I try to put the value of an input_number into the trigger time (for: minutes) with a template.
This doesn’t work with the error:

Error loading /config/configuration.yaml: invalid key: "OrderedDict([("states('input_number.zeit_einstellen'')|int", None)])"
in "/config/automations.yaml", line 46, column 0

Means the line with the minutes: ...
The similar line starting with message: ... works. Why?!

  trigger:
  - platform: device
    type: turned_on
    device_id: 158cbd37fca011ea9ae29d78e159a700
    entity_id: switch.on_off_plug_in_unit_4
    domain: switch
    for:
      hours: 0
      minutes: {{ states('input_number.zeit_einstellen'')|int }}
      seconds: 0
  condition: []
  action:
  - service: persistent_notification.create
    data:
      title: Test-Message
      message: "blabla: {{ states('input_number.zeit_einstellen')|int }}"
      notification_id: testm
  - type: turn_off
    device_id: 158cbd37fca011ea9ae29d78e159a700
    entity_id: switch.on_off_plug_in_unit_4
    domain: switch

Sorry for the slightly question. But the template editor is fine with the code above.

I also tried to work with double quotes in all variations, like in the documentation described, this could not be the right way in my point of view (didn’t work, too):

 minutes: "{{ states('input_number.high_temp_min')|int }}"

Thanks for your help…

These fields (hours, minute, seconds in the for: section) are currently not templatable, but will probably be soon as the devs said they are going to expand the fields that are templatable.

That’s incorrect, they have been able to template those fields for at least 6 months, probably longer. I’ve used it for ages to control how long a light stays on based on whether it is light or dark outside.

The only thing I’m wondering is whether they can’t be templated on ‘device triggers’

OP, try this…

  trigger:
  - platform: state 
    entity_id: switch.on_off_plug_in_unit_4
    to: 'on' 
    for:
      minutes: "{{ states('input_number.zeit_einstellen')|int }}"
  action:
  - service: persistent_notification.create
    data:
      title: Test-Message
      message: "blabla: {{ states('input_number.zeit_einstellen')|int }}"
      notification_id: testm
  - type: turn_off
    device_id: 158cbd37fca011ea9ae29d78e159a700
    entity_id: switch.on_off_plug_in_unit_4
    domain: switch

Edit - in doing this for you I realised that you have an extra ’ in the template (at the end of the entity_id), so it might work in the device trigger if you remove that, but it will definitely work using my code.

Sorry for the irritation of the quote mistake only made here in the forum but not in my code. However, now it works fine. Thank you very much!

1 Like

I’m so sorry, I mixed it up with the to: and :from fields in the state trigger, my apologies. @anon43302295 is totally right, as always :sunglasses:

1 Like