Binary sensor template not change state

hi.
i try to make sensor template.
the value run only on start the HA…
how can i make it changing ?
its looks like he run only by start…
my code :

  • platform: template
    sensors:
    test_in:
    friendly_name: “taaaa”
    value_template: >-
    {%- if (as_timestamp(states.sensor.shabbat_in.state) |int - as_timestamp(now()) |int) <= 272000 -%}
    True
    {%- else -%}
    False
    {%- endif -%}

First, please post code using proper formatting so that we can read it correctly. (See instructions at top of page.)

Next, a sensor like this will only update if the entity it references - sensor.shabbat_in - changes, not when time changes. If you want it to change with time, then you need to use a time-based entity in the template, like:

1 Like
sensor:
  - platform: time_date
    display_options:
      - 'date_time'
  - platform: template
    sensors:
      test_in:
        friendly_name: taaaa
        value_template: >
          {{ (as_timestamp(states.sensor.shabbat_in.state) - as_timestamp(strptime(states('sensor.datetime'),'%Y-%m-%d, %H:%M'))) <= 272000 }}
  1. You need to use @pnbruckner’s solution because sensor.datetime’s state updates minutely, sensor.shabbat_in only updates when it updates. Otherwise your state will only update when sensor.shabbat_in updates.
  2. Need to convert the sensor.datetime string into a datetime object, then convert it into a timestamp.
  3. No need to have an if statement to specify true / false, that is returned naturally through the the check.
1 Like

many thanks…its work…
you have error in text , not sensor.datetime else sensor.date__time

1 Like