Motion Activated Event Time

I have the following sensor that captures the time the Foyer motion Sensor activate AND deactivate events occur :

  foyer_eventtime:
    friendly_name: "Last Foyer Motion"
    icon_template: "mdi:clock-alert"
    value_template: "{{ as_timestamp(states.binary_sensor.aeotec_dsb05_multisensor_sensor.last_updated) | timestamp_custom('%a %b %d %H:%M:%S') }}"

I want to change this so only the activated (β€˜on’) event is captured. I am at a loss on what I need to change. Anyone can help would be much appreciated.

What about updating via an automation?

Not tested, give it a try.

          {% if is_state('binary_sensor.aeotec_dsb05_multisensor_sensor', 'on') %}
            "{{ as_timestamp(states.binary_sensor.aeotec_dsb05_multisensor_sensor.last_updated) | timestamp_custom('%a %b %d %H:%M:%S') }}"
          {% else %}
            {{ states.binary_sensor.aeotec_dsb05_multisensor_sensor.state }}
          {% endif %}

Not sure I formatted it correctly but the way it is I get errors. Specifically:

Error loading /home/homeassistant/.homeassistant/configuration.yaml: while scanning for the next token
found character '%' that cannot start any token
  in "/home/homeassistant/.homeassistant/configuration.yaml", line 253, column 26

where line 253, column 26 is the first % in the first line of

value_template: {% if is_state('binary_sensor.aeotec_dsb05_multisensor_sensor', 'on') %}
                  "{{ as_timestamp(states.binary_sensor.aeotec_dsb05_multisensor_sensor.last_updated) | timestamp_custom('%a %b %d %H:%M:%S') }}"
                {% else %}
                  {{ states.binary_sensor.aeotec_dsb05_multisensor_sensor.state }}
                {% endif %}

Not sure how I would do that either.

Try it this way:

value_template: >
  {% if is_state('binary_sensor.aeotec_dsb05_multisensor_sensor', 'on') %}
    "{{ as_timestamp(states.binary_sensor.aeotec_dsb05_multisensor_sensor.last_updated) | timestamp_custom('%a %b %d %H:%M:%S') }}"
  {% else %}
    {{ states.binary_sensor.aeotec_dsb05_multisensor_sensor.state }}
  {% endif %}
1 Like

Works perfectly with one exception. When the sensor becomes inactive the Last Foyer Motion is set to β€˜off’. I modified what you posted above to:

value_template: >
  {% if is_state('binary_sensor.aeotec_dsb05_multisensor_sensor', 'on') %}
    "{{ as_timestamp(states.binary_sensor.aeotec_dsb05_multisensor_sensor.last_updated) | timestamp_custom('%a %b %d %H:%M:%S') }}"
  {% endif %}

but all that did what blank the field once the sensor became inactive.