Invalid config for [automation]: Expected HH:MM, HH:MM:SS or Entity ID with domain 'input_datetime' or 'sensor' @ data['at'][0]. Got None

If someone runs into this error … drove me crazy for an hour or so …

This:

- alias: Nachtlicht ein
  description: Jacobs Nachtlicht einschalten
  trigger:
  - platform: time
    at: 22:30:00
  action:
  - service: switch.turn_on
    entity_id: switch.plugtwo
  - service: notify.pushover
    data:
      message: Nachtlicht ein
  mode: single

will raise above error, while

at: 06:30:00

will not (whysoever … when Hours are starting with a “0” it’s ok for the parser …)

Correct way to write is using hyphens:

at: "22:00:00"

5 Likes

I did, many thanks for the Post!!

Sorry. I’m bumping this - can anyone help please ?

I have something - Do I need to create a time sensor or value template as this does not work for me, resulting in the same error

alias: _A_TEST
description: ""
triggers:
  - trigger: time
    at: "{{ state_attr('sensor.mc', 'd') }}"
    id: MY-Zuhr
conditions: []
actions:
  - action: logbook.log
    metadata: {}
    data:
      name: TEST
      message: trigger id = {{ trigger.id }}
mode: single

The output of "{{ state_attr('sensor.mc', 'd') }}" is in the correct format HH:MM:SS but I’m still getting

Message malformed: Expected HH:MM, HH:MM:SS, an Entity ID with domain 'input_datetime' or 'sensor', or a combination of a timestamp sensor entity and an offset. @ data['at'][0]

Read the docs:

There are three allowed formats:

  • Time string
  • Input datetime
  • Sensors of datetime device class

at does not support templates. You could create a template sensor helper with a similar template and a timestamp device class (note the requirement for it to be a datetime object or ISO8601 string) and use that sensor’s entity ID.

{{ today_at(state_attr('sensor.mc', 'd')).isoformat() }}
1 Like

Thanks @Troon … guess you’re going to leave me to do the hard work :joy:

I really didn’t want to create time sensors but guess that’s the way to do it easily

???

I’ve extracted the key bits from the docs, told you that templates won’t work, and given you a state trigger for a template sensor helper. Use it like this:

Then:

triggers:
  - trigger: time
    at: sensor.my_zuhr
    id: MY-Zuhr
1 Like

Oh man, I’ve made a mess of things by trying to create these entitles via API as that’s how I’m updating them daily

foreach $p('a', 'b', 'c', 'd', 'e') {

  $curlData="{
    \"state\": \"$pt_object->{$p}\",
    \"device_class\": \"timestamp\"
  }";

#print $curlData,"\n";
system("curl -s -X POST -H \"Content-Type: application/json\" -H \"Authorization: Bearer $token\" -d '$curlData' https://homeassistant.home.xxxx.net/api/states/input_datetime.mcec_${p} 2>&1 >/dev/null");

}

Ufff now to work out how to create time objects via API if at all possible ?

You simply need to create / update a sensor with an ISO8601 string (including the T!) as its state (not an attribute), and a device_class of timestamp.

1 Like

Sorted … thanks mate

  $pt_object->{$key."_formatted"}=DateTime->now()->strftime('%Y-%m-%dT').$time->strftime('%H:%M:%S').'Z';

Which has created these that I can use in the automation

Now how do I get rid of these sensors that I accidently created or do I need to RTFM ?

Just in case anyone lands here looking for a solution

  • Restarting HA will get rid of any temporary entities created by API
  • To use datetime objects in an automation, set them up correctly ie
    – Create datetime helpers
  • To update those helpers via the API use a service call - DO NOT attempt to update the state of the object ie
system("curl -s -X POST -H \"Content-Type: application/json\" -H \"Authorization: Bearer $token\" -d '$curlData' https://homeassistant.home.xxxx.net/api/services/input_datetime/set_datetime 2>&1 >/dev/null");

Where your payload is

  $curlData="{
    \"datetime\": \"2024-10-01 00:00:00\",
    \"entity_id\": \"input_datetime.your_id\"
  }";