Input_datetime and input_number don't work as a condition

I’m trying to make a variable before/after condition, but can’t get it to work.

I tried (with input_datetime):

- id: 'Klimatisierung_Away_Mode_off_Tag'
  alias: Klimatisierung Away Mode OFF Tag
  trigger:
  - entity_id: group.people
    platform: state
    from: not_home
    to: home
  condition:
  - conditions: time
     after: "{{ input_datetime.sz_heizung_tag }}"
     before: "{{ input_datetime.sz_heizung_abend }}"
  action:
  - service: climate.set_away_mode
    data:
      entity_id: climate.schlafzimmer
      away_mode: false
  - delay: 00:00:01
  - service: climate.set_temperature
    data_template:
      entity_id: climate.schlafzimmer
      temperature: "{{ states.input_number.sz_t_tag.state }}"

The strange thing is, the automation DOES work technically. It does what it’s supposed to. If I come home between these times (which I can set from lovelace), the temperature gets set correctly. BUT when I check the configuration, this is the result:

Invalid config for [automation]: expected a dictionary @ data[‘condition’][0][‘conditions’][0]. Got None extra keys not allowed @ data[‘condition’][0][‘after’]. Got None extra keys not allowed @ data[‘condition’][0][‘before’]. Got None required key not provided @ data[‘condition’][0][‘condition’]. Got None. (See /config/configuration.yaml, line 65). Please check the docs at Automation - Home Assistant

I also tried with input_number:

  condition:
  - condition: time
    after: "{{ states.input_number.01.state }}:{{ states.input_number.02.state }}:00"
    before: "{{ states.input_number.03.state }}:{{ states.input_number.04.state }}:00"

… which results in:

Invalid config for [automation]: extra keys not allowed @ data[‘condition’][0][‘after’]. Got None
extra keys not allowed @ data[‘condition’][0][‘before’]. Got None
not a valid value for dictionary value @ data[‘condition’][0][‘condition’]. Got None
required key not provided @ data[‘condition’][0][‘entity_id’]. Got None. (See /config/configuration.yaml, line 65). Please check the docs at Automation - Home Assistant

input_datetime does work as a trigger, without any problems when checking the configuration:

- id: 'Klimatisierung_Schlafzimmer_Tag'
  alias: Klimatisierung Schlafzimmer Tag
  trigger:
  - platform: template
    value_template: "{{ states('sensor.time') == (states.input_datetime.sz_heizung_tag.attributes.timestamp | int | timestamp_custom('%H:%M', False)) }}"
  condition:
  - condition: state
    entity_id: group.people
    state: home
  action:
  - service: climate.set_temperature
    data_template:
      entity_id: climate.schlafzimmer
      temperature: "{{ states.input_number.sz_t_tag.state }}"

Any suggestions what I could do?!

EDIT:

This works flawlessly:

  condition:
    condition: time
    after: '08:00:00'
    before: '18:00:00'

Unless something has changed very recently you can’t use templates with a time condition, you’ll need to use a template condition.

hmm ok - how do I do that? do you have any links to examples?!

A template condition itself, or one using an input_datetime specifically?

I believe you already pointed me into the right direction! :slight_smile:
The Automation now looks like this:

- id: 'Klimatisierung_Away_Mode_off_Morgen'
  alias: Klimatisierung Away Mode OFF Morgen
  trigger:
  - entity_id: group.people
    platform: state
    from: not_home
    to: home
  condition:
    condition: and
    conditions:
      - condition: template
        value_template: "{{ states('sensor.time') > (states.input_datetime.sz_heizung_morgen.attributes.timestamp | int | timestamp_custom('%H:%M:%S', true)) }}"
      - condition: template
        value_template: "{{ states('sensor.time') < (states.input_datetime.sz_heizung_tag.attributes.timestamp | int | timestamp_custom('%H:%M:%S', true)) }}"
  action:
  - service: climate.set_away_mode
    data:
      entity_id: climate.schlafzimmer
      away_mode: false
  - delay: 00:00:01
  - service: climate.set_temperature
    data_template:
      entity_id: climate.schlafzimmer
      temperature: "{{ states.input_number.sz_temp_morgen.state }}"

It works and doesn’t show any errors.

Does it look right to you too?

1 Like

Looks good to me :slight_smile:

1 Like