Time in template

Research leads me to think that:-

{{ states(‘sensor.time’) }}
as a template should return the current time.
But all I get is ‘unknown’.

I have the time integration installed and that shows the time. But trying to use the time anywhere is simply not working.

I’m sure it’s something simple, but I can’t figue out what and it’s driving me nuts, so any help would be appreciated.

Try:

{{ states.sensor.time.state }}

What are you actually trying to do?

Are you trying to make a Template Sensor Helper? If so, did you apply an inappropriate device class. (If you applied any device class, the answer is “yes”.)

Hi, accessing current date and time from templates, should be easier with now()

I want to make a template binary sensor using a couple of parameters (time and day) to determine if a certain light should be on or not. I need to use these conditions in a couple of places, but want to only have one place to actually set the values being used - hence the template binary sensor.

In fact, states(‘sensor.time’) is now working as it should. I originally copied it from somewhere and pasted it into the template, but I suspect the quotes were wrong, having been ‘smartened’ along the way, which is not visibly obvious. I re-typed them as actual single quotes and it now works.

I should have thought of that before as it’s not the first time this sort of thing has caught me out.

{{ now().time() }} will give you the current time
sensor.time only is available if you’ve set up the integration. Of which I see basically no use unless you want a sensor to display on a dashboard.
For usage in templates just use now() to retreive the current time or date

Good point, although I don’t recall setting up the integration. As now() is apparently the built-in method, I’ll use that.

Can I throw in another question here though. I know binary sensors basically just return true or false, but the type chosen means one sees other descriptions, like ‘no light’ or ‘light detected’ for a light. Is there a type that can be used to simply show true or false?

Although this will be used to control lights, it is not detecting anything. I just want a yes|true or false|no to be the choices offered and shown in the UI, but none of the types offered seem to be that simple. Is there one?

Without a device class it will show on or off
these are the possible device classes and their output
https://www.home-assistant.io/integrations/binary_sensor/#device-class

Thanks, I had seen that list, but not noticed the ‘none’ option.