Minutes from number or text helper object for occupation off trigger

Hi,

I am trying to use a helper variable, text or number input, as the input for the minutes of a motion off trigger. The aim is to have an off trigger “for” condition which can be changed via another button/trigger/…

I hoped the solution is easy, following a supposed working solution presented in thread ttps://community.home-assistant.io/t/automation-trigger-for-input-datetime-for/279557/4

I tried several approaches:

  • text helper, for example “00:30:00” or “30”
  • number helper, for example 30

None of them works. However, I can read the variable correctly in the Template Editor.

My current setting is as follow:

The trigger:

type: not_occupied
platform: device
device_id: 571f67dc25aa8f3aad02e3c60c6c879e
entity_id: binary_sensor.philips_sml001_occupancy
domain: binary_sensor
for:
  hours: 0
  minutes: {{ states('input_number.lrt') | float }}
  seconds: 0

The error is the followoing:

Message malformed: expected float for dictionary value @ data['action'][1]['if'][0]['for']['minutes']

Does anybody have something working on his HA?

Cheers

jm78

  1. All templates need to be enclosed in quotes or prefaced by a multi-line quote symbol
  2. Many filters, including float(), need a default value. But I think the for actually requires int, not float.
  3. Entity id’s are slugs containing only lowercase letters and _.
for:
  hours: 0
  minutes: "{{ states('input_number.lrt') | int(0) }}"
  seconds: 0

Hi Drew,

Thank for the quick response. You proposed solution causes the same error. I tried this actually already.
Thanks for pointing out the lower case id issue. That, was a spelling error in my post and I corrected it.

Any further ideas?

Please post the entire automation… the error message is about an action, but you only posted a trigger.

Sure:

alias: Living Room Off Test
description: ""
trigger:
  - type: not_occupied
    platform: device
    device_id: 571f67dc25aa8f3aad02e3c60c6c879e
    entity_id: binary_sensor.philips_sml001_occupancy
    domain: binary_sensor
    for:
      hours: 0
      minutes: "{{ states('input_number.lrt') | float(0) }}"
      seconds: 0
condition: []
action:
  - service: light.turn_off
    data: {}
    target:
      area_id: living_room
mode: single

Device Trigger doesn’t support templates. Use a State Trigger.

alias: Living Room Off Test
description: ""
trigger:
  - platform: state
    entity_id: binary_sensor.philips_sml001_occupancy
    from: 'off'
    to: 'on'
    for:
      minutes: "{{ states('input_number.lrt') | float(0) }}"
condition: []
action:
  - service: light.turn_off
    data: {}
    target:
      area_id: living_room
mode: single

Thanks a lot! That works!