Problem with value_template in binary_sensor

Here’s my binary sensors:

binary_sensor:
  - platform: template
    sensors:
      people_home:
        friendly_name: People Home
        device_class: presence
        value_template: "{{ is_state('device_tracker.pixel_3_xl', 'home') or is_state('device_tracker.pixel_3_dan', 'home') }}"
            
      no_freezer_data:
        friendly_name: Freezer No Data
        device_class: problem
        value_template: "{{ (now() - states.sensor.cabin_freezer_temp_timestamp.last_changed | default(0)).total_seconds() > 60}}"

When I paste the template for no_freezer_data into the template tool, it evaluates to “True”, but the binary sensor still shows Off.

I’m sure this is something small and syntactical but new to this and I’ve tried everything I can think of and still no luck.

Any ideas?

the way you currently have it written will only update when sensor.cabin_freezer_temp_timestamp updates. Meaning it will always be zero and it will never evaluate to true. If you want it to update every minute, you need to add an entity to it to make it update every minute. something like sensor.time.

see ‘working without entities’ section of the template sensor documentation

Thanks - I went down that path a bit but missed that the point of the entity_id was to update…and since my template was evaluting as expected in the template tester, I figured I was on the right path (now I realize that the tester forces an udpate…).

But alas, when I add the entity_id like below I’m still not getting an update to the binary_sensor:

binary_sensor:
  - platform: template
    sensors:
      people_home:
        friendly_name: People Home
        device_class: presence
        value_template: "{{ is_state('device_tracker.pixel_3_xl', 'home') or is_state('device_tracker.pixel_3_dan', 'home') }}"
            
      no_freezer_data:
        friendly_name: Freezer No Data
#        device_class: problem
        entity_id: sensor.time
        value_template: "{{ (now() - states.sensor.cabin_freezer_temp_timestamp.last_changed | default(0)).total_seconds() > 60}}"

Do you have sensor.time integrated into the system. It’s a separate component that is not built into the system.

Yup - found that on one of your other posts, in configration.yaml:

sensor:

  - platform: time_date
    display_options:
      - 'date_time'

The name of trhat sensor is sensor.date_time. Not sensor.time

sensor.time is

sensor:

  - platform: time_date
    display_options:
      - 'time'

So much time for something so simple, least I understand how time_date works now - thanks for your help!