Templating (states, etc.) with Homematic IP Integration shows only errors

I have several Homematic IP devices, e.g. a HmIP-SWDO-I (but the following is the same for all devices until now). If I want to template.

{{ states.light.wohnzimmer }}

results in <template TemplateState(<state light.wohnzimmer=off; supported_color_modes=[‘onoff’], is_hue_group=True, friendly_name=Wohnzimmer, supported_features=40 @ 2021-08-05T22:16:14.018204+02:00>)>

but for all HMIP devices it is throwing an error:

{{ states.binary_sensor.0815_state }}

results everywhere TemplateSyntaxError: expected token ‘end of print statement’, got ‘integer’

If I open in developer menu, e.g. light brings:

Copy to clipboard

min_mireds: 153
max_mireds: 500
  - colorloop
  - random
  - color_temp
  - hs
is_hue_group: true
friendly_name: Ablage
supported_features: 63

whereas HMIP-entities bring

Copy to clipboard

id: abc
interface: ip
battery: High
sabotage: 'No'
rssi_device: -75
voltage: 1.5
friendly_name: Test
icon: mdi:window-closed-variant

which is not that different, that I can see, why states. etc. is not working.

Is there someting wrong with this integration or with the template engine or where is my mistake?

Edit: Wrong information. See Taras’ answer below.

My bet goes to the fact that the object id starts with a digit.
try (the recommended way, anyway):

{{ states["binary_sensor.0815_state"] }}

Yes, thank you, states() and states[] are working. and with [] …last_changed etc as well.

But I wanted to double-check, why states. does not work, because I don’t have any idea why this is happening.

It’s mentioned at the bottom of the Templating section in Entity_id that begins with a number

If your template uses an entity_id that begins with a number (example: states.device_tracker.2008_gmc) you must use a bracket syntax to avoid errors caused by rendering the entity_id improperly. In the example given, the correct syntax for the device tracker would be: states.device_tracker['2008_gmc']

1 Like

Aaaah. Thx for pointing to this doc. Was searching in the state-object doc, but yes, you are right. In Templating doc it is. And it is working this way.