Automations: Message malformed: invalid template

I have made a very simple automation which so far has worked fine:

alias: Upload temperatur
description: ''
mode: single
trigger: []
condition: []
action:
  - service: notify.indetemptilfil
    data:
      message: '{{ states.sensor.stue_temp_temperature.state }}'

If I change the sensor to another as shown here:

alias: Upload temperatur
description: ''
mode: single
trigger: []
condition: []
action:
  - service: notify.indetemptilfil
    data:
      message: '{{ states.sensor.0x00124b0023ea1980_temperature.state }}'

This results in the following error:

Message malformed: invalid template (TemplateSyntaxError: expected token 'end of print statement', got 'x00124b0023ea1980_temperature') for dictionary value @ data['action'][0]['data']

What am I doing wrong?

The two sensors are exactly the same brand. Both sensors work fine in HA. It’s like when I use a sensor that starts with “0x” I get problems.

It could be related to “entity_id that begins with a number”:

But I can not make it work.

First, an automation without a trigger is effectively a script. If you’re not going to give it a trigger, make a script instead.

Yes, the problem is the Object ID. Do one of these (the second is the preferred method):

  - service: notify.indetemptilfil
    data:
      message: '{{ states.sensor["0x00124b0023ea1980_temperature"].state }}'
  - service: notify.indetemptilfil
    data:
      message: '{{ states("sensor.0x00124b0023ea1980_temperature") }}'

Thank you very much for the quick reply. Number two is nice and simple :slight_smile:

PS: I have a time trigger, I just removed it to make the code smaller when I posted my question.