Is this jinja template syntax correct? (mind the gap)

by accident found out that

 {{states ('binary_sensor.outside_daylight_sensor')}}

returns no error, and even better, returns the correct value :wink:

same goes for

 {{is_state ('binary_sensor.outside_daylight_sensor','on')}}

never realized this, and havent found any documentation in that. Is this supposed to be correct?

thanks for having a look.

returns no error… as opposed to what?
This is pretty much standard template, even recommended versus {{states.binary_sensor.outside_daylight_sensor.state}} (as it won’t error if unknown)

I mean the space between states/is_state and the (‘xxx’).

Always thought they needed to be attached:

 {{states('binary_sensor.outside_daylight_sensor')}}

 {{is_state('binary_sensor.outside_daylight_sensor','on')}}

Spooky…
I’ve also just recently come across a couple of ‘typos’ in my config with spaces too. And I don’t think just in the type of examples you give…

that makes more sense, I was getting concerned after reading your message, its not like you’re new here :wink:
I guess recommended format would be without space, but most commands accept spaces so I’m not surprised these do too

haha, no thank you :wink:
I solely use these states templates, indeed because of the way they wont error on unknown. Also, because I like the eye candy better… gotta love the view of a nicely written template.

2 Likes

I think that’s the OCD in all of us :rofl:

I don’t think it should be documented as it’s down to the way Jinja parser works, pretty low level stuff (imho)
Presume that if it encounters a keyword (states) it start looking for a delimiter - “(” (but not “.”).
So there’s no magic, you can do that if you wish :wink:

UPDATE: I find this much more fascinating as it works, too

{{ states  .  binary_sensor  .  outside_daylight_sensor }}

I love how we can get excited just by the way a compiler accepts code syntax :rofl:

Whoa There Nelly … you really need some warm milk and then I think it’s time for Bed ! :rofl:

1 Like