Input_datetime expects float timestamp, but that's what I provide?

Hi!

I am using the input_datetime integration, and through it’s service input_datetime.set_datetime, I am trying to update the date with a timestamp.

I am using the code below:

type: button
tap_action:
  action: call-service
  service: input_datetime.set_datetime
  service_data:
    entity_id: input_datetime.task
    timestamp: '{{ now().timestamp() + 259200.0 }}'
show_name: true
show_icon: false
name: Mark as done
hold_action:
  action: none

But once I try to execute the service call, I recieve the error:

expected float for dictionary value @ data['timestamp']

I have also tried |float and as_timestamp() with no luck.

I have no clue whatsoever why this is happening, because i AM providing a float value.

Do you guys have any ideas?

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 135, in handle_call_service
    await hass.services.async_call(
  File "/usr/src/homeassistant/homeassistant/core.py", line 1402, in async_call
    processed_data = handler.schema(service_data)
  File "/usr/local/lib/python3.8/site-packages/voluptuous/validators.py", line 218, in __call__
    return self._exec((Schema(val) for val in self.validators), v)
  File "/usr/local/lib/python3.8/site-packages/voluptuous/validators.py", line 340, in _exec
    raise e if self.msg is None else AllInvalid(self.msg, path=path)
  File "/usr/local/lib/python3.8/site-packages/voluptuous/validators.py", line 336, in _exec
    v = func(v)
  File "/usr/local/lib/python3.8/site-packages/voluptuous/schema_builder.py", line 272, in __call__
    return self._compiled([], data)
  File "/usr/local/lib/python3.8/site-packages/voluptuous/schema_builder.py", line 817, in validate_callable
    return schema(data)
  File "/usr/local/lib/python3.8/site-packages/voluptuous/schema_builder.py", line 272, in __call__
    return self._compiled([], data)
  File "/usr/local/lib/python3.8/site-packages/voluptuous/schema_builder.py", line 594, in validate_dict
    return base_validate(path, iteritems(data), out)
  File "/usr/local/lib/python3.8/site-packages/voluptuous/schema_builder.py", line 432, in validate_mapping
    raise er.MultipleInvalid(errors)
voluptuous.error.MultipleInvalid: expected float for dictionary value @ data['timestamp']
Kunne ikke kalde tjenesten input_datetime/set_datetime. expected float for dictionary value @ data['timestamp']

3 Likes

Hmmm exactly same problem.

service: input_datetime.set_datetime
data:
  timestamp: {{ as_timestamp(states('sensor.neato_last_finished')) }} 
target:
  entity_id: input_datetime.vac_last_completed

errors with:

expected float for dictionary value @ data['timestamp']

Value of
sensor.neato_last_finished
is
2022-04-15 20:20:52.669114+01:00

and its device_class is
timestamp

also tried

{{ as_timestamp(states('sensor.neato_last_finished')) | float(0) }} 

same problem.

Can’t see whats going wrong here?

Thanks for any suggestions.

I just ran into this issue too—I was also trying to set an input_datetime dynamically from a tap action.

Thinking it might be a problem with the timestamp option, I tried changing my data to a datetime instead. This got me a slightly more meaningful error:

Failed to call service input_datetime/set_datetime. Invalid datetime specified: {{ now }} for dictionary value @ data[‘datetime’]

The verbatim copy of my template in the error message indicates that templating is not occurring. However, checking the docs for actions, it turns out that this is expected:

Limitations

It is not possible to use templates for actions. But calling a script is a good alternative.

The solution is therefore to put the input_datetime-updating logic into a script, and call that from the tap action.