Error rendering data template: Result is not a Dictionary in automation (solved)

Hi all,
i am trying to count the seconds my freezer is open a day.
When opening and closing set timestamps works.

data:
  timestamp: "{{ as_timestamp(now()) }}"
target:
  entity_id: input_datetime.gefrierschrankzuletztgeschlossen
action: input_datetime.set_datetime

but after closing calc and set the difference gives me the error in the subject.

action: input_number.set_value
metadata: {}
data: >-
  value:>- "states('input_datetime.gefrierschrankzuletztgeschlossen') -
  states('input_datetime.gefrierschrankoffenseit')"
target:
  entity_id: input_number.gefrierschrankoffenheutesek

like my searches the result should be an integer. And why he would a dictionary? :worried:

many thanks for any tip.

best regards.

Get rid of the >-. Not sure what showed you that, but I have a guess.

In addition to SG’s comments above, your ā€œtemplateā€ has no template delimiters. Also, states are strings… and the states of input_datetime entities are datetime strings. Without conversion to either a timestamp or datetime object, subtracting them is a nonsense operation.

Hi,
ive tried a lot of different Versions now. i get things like ā€œError rendering data template: UndefinedError: ā€˜str object’ has no attribute ā€˜valueā€™ā€ or again ā€œError rendering data template: Result is not a Dictionaryā€. That means i read the values correct now and the calculations works now or not? But why did ha need/search a dictionary for setting a number? gefrierschrankoffenheutesek is defined as input.number!

btw: ha sets >- for a carriage return. In the link i didn’t find a solution or an explanation why ha wants a dictionary.

The actual version is:

action: input_number.set_value
metadata: {}
data_template: >-
  {{ (states('input_datetime.gefrierschrankzuletztgeschlossen') | as_datetime -
  states('input_datetime.gefrierschrankoffenseit') |
  as_datetime).total_seconds() }}
target:
  entity_id: input_number.gefrierschrankoffenheutesek

i’ve no more ideas, what to test. (sorry for my bad englih :confused: )

Stop using LLM bullshit engines… without very well-crafted and detailed prompts they are very bad at HA.

If you had followed the two pieces of advice given above, you would have a working action:

action: input_number.set_value
metadata: {}
data:
  value: |
    {{ (states('input_datetime.gefrierschrankzuletztgeschlossen') | as_datetime -
    states('input_datetime.gefrierschrankoffenseit') | as_datetime).total_seconds() }}
target:
  entity_id: input_number.gefrierschrankoffenheutesek
1 Like

Many thanks for that, it works. I will check the two pieces of advice again. Sorry to be slow on the uptake.