Skip to content
This repository has been archived by the owner on Jul 23, 2021. It is now read-only.

Last Motion Sensor #61

Closed
schneekluth opened this issue May 22, 2018 · 5 comments
Closed

Last Motion Sensor #61

schneekluth opened this issue May 22, 2018 · 5 comments

Comments

@schneekluth
Copy link

Please add a sensor for last motion or add an explanation how to do it in the README.

Thanks.

@Mariusthvdb
Copy link
Contributor

Mariusthvdb commented May 24, 2018

see https://diyfuturism.com/index.php/2017/12/15/useful-sensor-motion-last-seen-________/

variable:
  last_motion:
    value: 'Not set'
    restore: true
    attributes:
      icon: mdi:map-marker
      name: 'Last Motion'

and

automation:
# Update Last Motion variable
  - alias: "Update Last Motion"
    id: 'Update Last Motion'
    initial_state: 'on'
    trigger:
      platform: state
      entity_id:
        - sensor.corridor_motion_sensor
        - sensor.auditorium_motion_sensor
        - sensor.dining_table_motion_sensor
        - sensor.master_bedroom_motion_sensor
        - sensor.dorm_motion_sensor
        - sensor.frontdoor_motion_sensor
        - sensor.control_room_motion_sensor
      to: 'on'
    action:
      service: variable.set_variable
      data:
        variable: last_motion
        attributes_template: >
          {
                "history_1": "{{ variable.state }}",
                "history_2": "{{ variable.attributes.history_1 }}",
                "history_3": "{{ variable.attributes.history_2 }}",
                "history_4": "{{ variable.attributes.history_3 }}",
                "history_5": "{{ variable.attributes.history_4 }}"
          }
      data_template:
        value: "{{ trigger.to_state.attributes.friendly_name }}"

schermafbeelding 2018-05-24 om 14 03 15

@robmarkcole
Copy link
Owner

last_updated doesn't always == last motion? If not then last_motion could be added as an attribute

@raoulteeuwen
Copy link

@schneekluth is what @hvbhome shows what you intended, are you asking for a variable for every motion sensor holding the last date and time motion was detected for that motion sensor or something else :-)?

@schneekluth
Copy link
Author

Yes, it was exactly what I was looking for. It's already set up an running. Thanks for the advice. I didn't know hassvariables.

@Mariusthvdb
Copy link
Contributor

cool.
of course you can add the show_last_changed: true for the sensors, customize some more, and have it show like this:

schermafbeelding 2018-05-25 om 23 35 30

    sensor.frontdoor_motion_sensor:
      show_last_changed: true
      templates:
        icon_color: >
          if (state === 'on') return 'rgb(192, 39, 30)';
          return 'rgb(54, 95, 140)';
        icon: >
          if (state === 'on') return 'mdi:run-fast';
          return 'mdi:security-home';
        _stateDisplay: >
          if (state === 'on') return 'Alert';
          return 'Clear';
      group:
        group.philips_motion_sensors:
          friendly_name: Frontdoor

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants