MinutesSinceLastMotionDetected

nicolaw 30th August 2021 at 2:06pm
HassioHomeAssistant
group:
  motion:
  name: Motion activity
  entities:
    - binary_sensor.bathroom_motion_sensor_motion
    - binary_sensor.master_bed_motion_sensor_motion
    - binary_sensor.hallway_motion_sensor_motion
    - binary_sensor.study_motion_sensor_motion
    - binary_sensor.lounge_motion_sensor_motion
    - binary_sensor.dining_room_motion_sensor_motion

template:
  - trigger:
      - platform: state
        entity_id: group.motion
        to: "on"
    sensor:
      - name: Last motion detected
        icon: mdi:walk
        state: "{{ now() }}"
        attributes:
          timestamp: "{{ as_timestamp(now()) }}"

  - sensor:
      - name: Time since last motion detected
        icon: mdi:walk
        unit_of_measurement: "Minutes"
        state: >
          {% if is_state('sensor.last_motion_detected', 'unknown') %}
            shrug
          {% else %}
            {{ ((as_timestamp(now()) - as_timestamp(states('sensor.last_motion_detected'))) | float / 60) | round }}
          {% endif %}