dckiller51
(Dckiller51)
September 6, 2019, 2:28am
1
hello, i start with hassio. I am looking to automate the reception of parcels or the reading of the mailbox.
I need to know if I opened my front door within 4 minutes after or before opening the door of the mailbox.
if open script 1, if nothing script 2.
my template from below answers me in template true or false but no script starts.
action:
- delay:
seconds: 120
- service: script.turn_on
data_template:
entity_id: >-
{%- if states.binary_sensor.detecteur_porte_entree.last_changed -%}
{{ (as_timestamp(now())-as_timestamp(states.binary_sensor.detecteur_porte_entree.last_changed)) < 180 }}
script.boite_aux_lettres_releve_courrier
{%- else -%}
script.boite_aux_lettres_colis_recu
{%- endif -%}
Thanks for help me.
tom_l
September 6, 2019, 3:25am
2
action:
- delay:
seconds: 120
- service_template:
{% set now = as_timestamp(now()) %}
{% set last_change = as_timestamp(states.binary_sensor.detecteur_porte_entree.last_changed) %}
{%- if ( now - last_changed )|abs < 180 ) }}
script.boite_aux_lettres_releve_courrier
{%- else -%}
script.boite_aux_lettres_colis_recu
{%- endif -%}
dckiller51
(Dckiller51)
September 6, 2019, 9:36am
3
Thanks @tom_l for reply.
There is a formatting problem. The Gabarit return erreur.
{%- if ( now - last_changed )|abs < 180 ) }}
tom_l
September 6, 2019, 10:41am
4
That is indeed incorrect. Should be:
{% if ( now - last_changed )|abs < 180 ) %}
So:
action:
- delay:
seconds: 120
- service_template:
{% set now = as_timestamp(now()) %}
{% set last_change = as_timestamp(states.binary_sensor.detecteur_porte_entree.last_changed) %}
{% if ( now - last_changed )|abs < 180 ) %}
script.boite_aux_lettres_releve_courrier
{% else %}
script.boite_aux_lettres_colis_recu
{% endif %}
small typo left: should have an extra d
after {% set last_change
1 Like
tom_l
September 6, 2019, 11:45am
6
Right, hopefully this is it:
action:
- delay:
seconds: 120
- service_template:
{% set now = as_timestamp(now()) %}
{% set last_change = as_timestamp(states.binary_sensor.detecteur_porte_entree.last_changed) %}
{% if ( now - last_change )|abs < 180 ) %}
script.boite_aux_lettres_releve_courrier
{% else %}
script.boite_aux_lettres_colis_recu
{% endif %}
All wrong. See 3rd last post.
well, if it were up to me Id do this, add the d:
action:
- delay:
seconds: 120
- service_template:
{% set now = as_timestamp(now()) %}
{% set last_changed = as_timestamp(states.binary_sensor.detecteur_porte_entree.last_changed) %}
{% if ( now - last_changed )|abs < 180 ) %}
script.boite_aux_lettres_releve_courrier
{% else %}
script.boite_aux_lettres_colis_recu
{% endif %}
tom_l
September 6, 2019, 11:53am
8
TomATEo, TomAREto. PotATEo, PotAREto.
petro
(Petro)
September 6, 2019, 12:02pm
9
whats the point of the abs? Now-last_change should always be positive or in rare cases, slightly negative by microseconds.
tom_l
September 6, 2019, 12:06pm
10
Well shit. Re-reading the initial requirements I realised I’m not checking for the right time:
now() should be the mailbox last changed. That would require |abs for the before/after bit.
petro
(Petro)
September 6, 2019, 12:11pm
11
Yeah but before is impossible. You can’t predict the future. Last_changed will always be in the past in relation to now() or it will be equal (with a small chance of epsilon error).
tom_l
September 6, 2019, 12:13pm
12
Yeah your post alerted me to my mistake, I should not be using now(). It’s one sensor vs the other, not vs now(). @dckiller51 did not provide the mailbox door entity id so I made one up (which should be replaced with your actual mailbox door binary sensor @dckiller51 ). Hopefully this makes more sense:
action:
- delay:
seconds: 120
- service_template:
{% set mailbox_last_changed = as_timestamp(states.binary_sensor.mailbox_door.last_changed) %}
{% set front_door_last_changed = as_timestamp(states.binary_sensor.detecteur_porte_entree.last_changed) %}
{% if ( mailbox_last_changed - front_door_last_changed )|abs < 180 ) %}
script.boite_aux_lettres_releve_courrier
{% else %}
script.boite_aux_lettres_colis_recu
{% endif %}
Script script.boite_aux_lettres_releve_courrier
should now run if
opened my front door within 4 minutes after or before opening the door of the mailbox .
This is the bit you have to replace with your actual mailbox door sensor @dckiller51 :
{% set mailbox_last_changed = as_timestamp(states.binary_sensor.mailbox_door.last_changed) %}
^^^^^^^^^^^^^^^^^^^^^^^^^^
1 Like
petro
(Petro)
September 6, 2019, 12:28pm
13
Ah, now the abs makes sense! I suppose I should have read more of the original post.
1 Like
tom_l
September 6, 2019, 12:32pm
14
You were 100% right though and put me on the correct path. Despite watching Primer many times I have yet to perfect time travel.
dckiller51
(Dckiller51)
September 6, 2019, 9:03pm
15
Thank you thank you and thank you. It works finally.
Thank you for your proposal to add the sensor door mailbox.
You have thoroughly analyze my need.
I just correct
{% if ( mailbox_last_changed - front_door_last_changed )|abs < 180 ) %}
{% if (mailbox_last_changed - front_door_last_changed)|abs < 180 %}
180 ) delete )
1 Like
dckiller51
(Dckiller51)
September 6, 2019, 9:10pm
16
I added a delay before reading the template.
Now it works that I pick up the mail before coming home or if I’m at home is that I will pick up the mail. Thank you for participating in everyone’s ideas is important to move forward.
dckiller51
(Dckiller51)
September 6, 2019, 9:16pm
17
I will test in real this week to see if it works. Then I close the post