Hello All
I try to get the last time a motion sensor detect something (anyelse, human, animal, vehicule)
I test this code
- platform: template
sensors:
sam_last_motion:
friendly_name: 'SAM Last Motion'
value_template: >
{%- set sensors = [states.binary_sensor.capteur_salle_a_manger_motion] %}
{% for sensor1 in sensors %}
{% if as_timestamp(sensor1.last_changed) == as_timestamp(sensors | map(attribute='last_changed') | max) %}
{{ (sensor1.last_changed) }}
{% endif %}
{% endfor %}
sam_last_motion_min:
friendly_name: 'SAM Last Motion en minutes'
value_template: >
{%- set sensors = [states.binary_sensor.capteur_salle_a_manger_motion] %}
{% for sensor1 in sensors %}
{% if as_timestamp(sensor1.last_changed) == as_timestamp(sensors | map(attribute='last_changed') | max) %}
{{ (( as_timestamp(now()) - as_timestamp(sensor1.last_changed)) / 60 ) | int }}
{% endif %}
{% endfor %}
cuis_last_motion:
friendly_name: 'Cuisine Last Motion'
value_template: >
{%- set sensors = [states.binary_sensor.bienvenue_motion] %}
{% for sensor2 in sensors %}
{% if as_timestamp(sensor2.last_changed) == as_timestamp(sensors | map(attribute='last_changed') | max) %}
{{ (sensor2.last_changed) }}
{% endif %}
{% endfor %}
cuis_last_motion_min:
friendly_name: 'Cuisine Last Motion en minutes'
value_template: >
{%- set sensors = [states.binary_sensor.bienvenue_motion] %}
{% for sensor2 in sensors %}
{% if as_timestamp(sensor2.last_changed) == as_timestamp(sensors | map(attribute='last_changed') | max) %}
{{ (( as_timestamp(now()) - as_timestamp(sensor2.last_changed)) / 60 ) | int }}
{% endif %}
{% endfor %}
entreh_last_motion:
friendly_name: 'Entrée :dernière personne detectée'
value_template: >
{%- set sensors = [states.binary_sensor.video_entree_outdoor_human] %}
{% for sensor3 in sensors %}
{% if as_timestamp(sensor3.last_changed) == as_timestamp(sensors | map(attribute='last_changed') | max) %}
{{ (sensor3.last_changed) }}
{% endif %}
{% endfor %}
entreh_last_motion_min:
friendly_name: 'Entrée :dernière personne detectée en minutes'
value_template: >
{%- set sensors = [states.binary_sensor.video_entree_outdoor_human] %}
{% for sensor3 in sensors %}
{% if as_timestamp(sensor3.last_changed) == as_timestamp(sensors | map(attribute='last_changed') | max) %}
{{ (( as_timestamp(now()) - as_timestamp(sensor3.last_changed)) / 60 ) | int }}
{% endif %}
{% endfor %}
entrea_last_motion:
friendly_name: 'Entrée :dernièr animal detecté'
value_template: >
{%- set sensors = [states.binary_sensor.video_entree_outdoor_animal] %}
{% for sensor4 in sensors %}
{% if as_timestamp(sensor4.last_changed) == as_timestamp(sensors | map(attribute='last_changed') | max) %}
{{ (sensor4.last_changed) }}
{% endif %}
{% endfor %}
entrea_last_motion_min:
friendly_name: 'Entrée :dernièr animal detecté en minutes'
value_template: >
{%- set sensors = [states.binary_sensor.video_entree_outdoor_animal] %}
{% for sensor4 in sensors %}
{% if as_timestamp(sensor4.last_changed) == as_timestamp(sensors | map(attribute='last_changed') | max) %}
{{ (( as_timestamp(now()) - as_timestamp(sensor4.last_changed)) / 60 ) | int }}
{% endif %}
{% endfor %}
entrev_last_motion:
friendly_name: 'Entrée :dernier véhicule detecté'
value_template: >
{%- set sensors = [states.binary_sensor.video_entree_outdoor_vehicle] %}
{% for sensor5 in sensors %}
{% if as_timestamp(sensor5.last_changed) == as_timestamp(sensors | map(attribute='last_changed') | max) %}
{{ (sensor5.last_changed) }}
{% endif %}
{% endfor %}
entrev_last_motion_min:
friendly_name: 'Entrée :dernier véhicule detecté en minutes'
value_template: >
{%- set sensors = [states.binary_sensor.video_entree_outdoor_vehicle] %}
{% for sensor5 in sensors %}
{% if as_timestamp(sensor5.last_changed) == as_timestamp(sensors | map(attribute='last_changed') | max) %}
{{ (( as_timestamp(now()) - as_timestamp(sensor5.last_changed)) / 60 ) | int }}
{% endif %}
{% endfor %}
and in the dev Tool state
for sensor.last_motion_min I have for all 0
but in template I have the correct time in min
-
platform: template
sensors:
sam_last_motion:
friendly_name: ‘SAM Last Motion’
value_template: >
2019-07-31 18:58:07.464843+00:00sam_last_motion_min: friendly_name: 'SAM Last Motion en minutes' value_template: > 0 cuis_last_motion: friendly_name: 'Cuisine Last Motion' value_template: > 2019-07-31 18:46:04.725865+00:00 cuis_last_motion_min: friendly_name: 'Cuisine Last Motion en minutes' value_template: > 12 entreh_last_motion: friendly_name: 'Entrée :dernière personne detectée' value_template: > 2019-07-31 18:51:45.468091+00:00 entreh_last_motion_min: friendly_name: 'Entrée :dernière personne detectée en minutes' value_template: > 6 entrea_last_motion: friendly_name: 'Entrée :dernièr animal detecté' value_template: > 2019-07-31 18:51:45.431238+00:00 entrea_last_motion_min: friendly_name: 'Entrée :dernièr animal detecté en minutes' value_template: > 6 entrev_last_motion: friendly_name: 'Entrée :dernier véhicule detecté' value_template: > 2019-07-31 18:46:04.923940+00:00 entrev_last_motion_min: friendly_name: 'Entrée :dernier véhicule detecté en minutes' value_template: > 12
Can you help me please ? I have remarks that all last motion is given with UTC (0) I need to add 2 hours for my good time
Thanks