Anyway to display "for" timer in dashboard?

Let’s say you have a motion sensor that will turn off the light after it stops sensing motion for 10 minutes. Is there a way to expose that 10 minute counter on the dashboard?

I tried creating a sensor to get a snapshot of the timestamp when motion stops being detected and then I have another sensor that basically gets the current timestamp and subtracts the two. However the value doesn’t update on the dashboard. It either shows “unavailable”, when there is motion, or “0” when it stops detecting motion. Here is the yaml code. I don’t like this approach because 1, it doesn’t work and 2, I’d rather expose the actual counter. Any thoughts?

- platform: template
  sensors:
    last_motion_detected:
      friendly_name: "Last Motion Detected"
      value_template: "{{ now() }}"
      availability_template: "{{ is_state('binary_sensor.test_light_switch_motion_sensor', 'off') }}"
- platform: template
  sensors:
    motion_counter:
      friendly_name: "Motion Counter"
      unit_of_measurement: 'seconds'
      value_template: "{{ ((as_timestamp(now()) - as_timestamp(states('sensor.last_motion_detected'))) ) | round(0) }}"

Use a Timer - Home Assistant and display that.

I played around with the idea of a timer but a timer is something that countsdown from a specified duration. What I’m trying to do is display how much time has elapsed since the sensor went into off mode.

What counter?

If you’re referring to the value of a State Trigger’s for option then the answer is no.

See:

I think a better way to describe it is to display the time elapsed since the sensor stopped detecting motion. Sorry English is not my first language.

Try this:

- platform: template
  sensors:
    motion_counter:
      friendly_name: "Motion Counter"
      unit_of_measurement: 'seconds'
      value_template: >
        {% if is_state('binary_sensor.test_light_switch_motion_sensor', 'off') %} 
          {{ (now() - states.binary_sensor.test_light_switch_motion_sensor.last_changed).total_seconds() | round(0) }}
        {% else %}
          0
        {% endif %}

Be advised that the template will only update every minute (because of the inclusion of the now() function) and when the binary_sensor’s state changes. It won’t update any faster than that.

Hey thanks for offering a solution! Unfortunately I would like to display the time increments down to the second. Still diving into this forum along with the subreddit to look for solutions but haven’t found any yet.

Not feasible.

A template is evaluated only when one of the entities it references changes state. As explained, now() causes the template to be evaluated every minute and no faster.

A brute-force workaround is to create a Trigger-based Template Sensor with a Time Pattern Trigger set for every second. You’ll have to decide if that’s something you want running continuously on your system. Generally speaking, I don’t recommend doing that.