I’m working on implementing my automation from this thread.
Here are the automations:
- id: garage_light_automation_1
alias: Garage Lights Door Event Handler
description: Update garage_timer_input on door events when it is night
trigger:
- platform: state
entity_id: binary_sensor.garage_door
from: 'off'
to: 'on'
condition:
- condition: state
entity_id: sun.sun
state: below_horizon
- condition: or
conditions:
- condition: numeric_state
entity_id: input_number.garage_timer_input
above: -1
- condition: state
entity_id: light.frst_garage_interior
state: 'off'
action:
- service: input_number.set_value
data_template:
entity_id: input_number.garage_timer_input
value: "{{ [states('input_number.garage_timer_input')|int, 5]|max }}"
- id: garage_light_automation_2
alias: Garage Lights Counter State Handler
description: Decrement garage_timer_input and take actions
trigger:
- platform: state
entity_id: input_number.garage_timer_input
action:
- delay: '00:00:01'
- condition: numeric_state
entity_id: input_number.garage_timer_input
above: -1
- service_template: "{% if (states('input_number.garage_timer_input')|int - 1) == 0 %}\n switch.turn_off\n\
{% else %}\n switch.turn_on\n{% endif %}"
entity_id: light.frst_garage_interior
- service: notify.mobile_app_devans_iphone
data_template:
title: Garage Timer
message: Garage lights will turn off in {{ trigger.to_state.state|int - 1 }} minutes.
data:
apns_headers:
apns-collapse-id: garge-interior-light
push:
category: gargetimer
- wait_template: "{{ states('input_number.garage_timer_input') != trigger.to_state.state }}"
timeout: '00:01:00'
- service: input_number.decrement
entity_id: input_number.garage_timer_input
- id: garage_light_automation_3
alias: Garage Lights iOS App Event Handler
description: Update garage_timer_input on app events
trigger:
- platform: event
event_type: ios.notification_action_fired
event_data:
actionName: SLEEP_TIMER
- platform: event
event_type: ios.notification_action_fired
event_data:
actionName: DISABLE_TIMER
action:
service: input_number.set_value
data_template:
entity_id: input_number.garage_timer_input
value: >
{% if trigger.event.data.actionName == "SLEEP_TIMER" %}
{{ states('input_number.garage_timer_input')|int + 5 }}
{% else %}
-1
{% endif %}
I’m running in to a problem where the garage_light_automation_2
automation is firing twice (notify with 5 then 3, etc). From reading around it appears I need to solve this by placing the delay inside of a script which waits 1 minute and then decrements the count.
I’m ok with this, but I was wondering if someone could explain to me why this is happening?
{
"event_type": "state_changed",
"data": {
"entity_id": "automation.garage_lights_counter_state_handler",
"old_state": {
"entity_id": "automation.garage_lights_counter_state_handler",
"state": "on",
"attributes": {
"last_triggered": "2020-03-09T20:11:15.062080+00:00",
"id": "garage_light_automation_2",
"friendly_name": "Garage Lights Counter State Handler"
},
"last_changed": "2020-03-09T20:08:45.919139+00:00",
"last_updated": "2020-03-09T20:11:15.062627+00:00",
"context": {
"id": "6aed3a96d82346c0904506c0331dc216",
"parent_id": "4dc67bcebc074630bed88021a84277c1",
"user_id": null
}
},
"new_state": {
"entity_id": "automation.garage_lights_counter_state_handler",
"state": "on",
"attributes": {
"last_triggered": "2020-03-09T20:11:15.077279+00:00",
"id": "garage_light_automation_2",
"friendly_name": "Garage Lights Counter State Handler"
},
"last_changed": "2020-03-09T20:08:45.919139+00:00",
"last_updated": "2020-03-09T20:11:15.077951+00:00",
"context": {
"id": "6aed3a96d82346c0904506c0331dc216",
"parent_id": "4dc67bcebc074630bed88021a84277c1",
"user_id": null
}
}
},
"origin": "LOCAL",
"time_fired": "2020-03-09T20:11:15.078047+00:00",
"context": {
"id": "6aed3a96d82346c0904506c0331dc216",
"parent_id": "4dc67bcebc074630bed88021a84277c1",
"user_id": null
}
}
Event 8 fired 4:11 PM:
{
"event_type": "state_changed",
"data": {
"entity_id": "automation.garage_lights_counter_state_handler",
"old_state": {
"entity_id": "automation.garage_lights_counter_state_handler",
"state": "on",
"attributes": {
"last_triggered": "2020-03-09T20:10:12.641937+00:00",
"id": "garage_light_automation_2",
"friendly_name": "Garage Lights Counter State Handler"
},
"last_changed": "2020-03-09T20:08:45.919139+00:00",
"last_updated": "2020-03-09T20:10:12.642501+00:00",
"context": {
"id": "77aa1bc4d38f4acf956628cdf19ff127",
"parent_id": "1609617444f944449db733710284721a",
"user_id": null
}
},
"new_state": {
"entity_id": "automation.garage_lights_counter_state_handler",
"state": "on",
"attributes": {
"last_triggered": "2020-03-09T20:11:15.062080+00:00",
"id": "garage_light_automation_2",
"friendly_name": "Garage Lights Counter State Handler"
},
"last_changed": "2020-03-09T20:08:45.919139+00:00",
"last_updated": "2020-03-09T20:11:15.062627+00:00",
"context": {
"id": "6aed3a96d82346c0904506c0331dc216",
"parent_id": "4dc67bcebc074630bed88021a84277c1",
"user_id": null
}
}
},
"origin": "LOCAL",
"time_fired": "2020-03-09T20:11:15.062709+00:00",
"context": {
"id": "6aed3a96d82346c0904506c0331dc216",
"parent_id": "4dc67bcebc074630bed88021a84277c1",
"user_id": null
}
}
Event 7 fired 4:11 PM:
{
"event_type": "state_changed",
"data": {
"entity_id": "input_number.garage_timer_input",
"old_state": {
"entity_id": "input_number.garage_timer_input",
"state": "4.0",
"attributes": {
"initial": -1,
"editable": false,
"min": -1,
"max": 10000,
"step": 1,
"mode": "slider",
"unit_of_measurement": "minutes",
"friendly_name": "Garage Timer",
"icon": "mdi:clock-outline"
},
"last_changed": "2020-03-09T20:11:15.017914+00:00",
"last_updated": "2020-03-09T20:11:15.017914+00:00",
"context": {
"id": "77aa1bc4d38f4acf956628cdf19ff127",
"parent_id": "1609617444f944449db733710284721a",
"user_id": null
}
},
"new_state": {
"entity_id": "input_number.garage_timer_input",
"state": "3.0",
"attributes": {
"initial": -1,
"editable": false,
"min": -1,
"max": 10000,
"step": 1,
"mode": "slider",
"unit_of_measurement": "minutes",
"friendly_name": "Garage Timer",
"icon": "mdi:clock-outline"
},
"last_changed": "2020-03-09T20:11:15.042965+00:00",
"last_updated": "2020-03-09T20:11:15.042965+00:00",
"context": {
"id": "4dc67bcebc074630bed88021a84277c1",
"parent_id": "77aa1bc4d38f4acf956628cdf19ff127",
"user_id": null
}
}
},
"origin": "LOCAL",
"time_fired": "2020-03-09T20:11:15.043045+00:00",
"context": {
"id": "4dc67bcebc074630bed88021a84277c1",
"parent_id": "77aa1bc4d38f4acf956628cdf19ff127",
"user_id": null
}
}
Event 6 fired 4:11 PM:
{
"event_type": "state_changed",
"data": {
"entity_id": "input_number.garage_timer_input",
"old_state": {
"entity_id": "input_number.garage_timer_input",
"state": "5.0",
"attributes": {
"initial": -1,
"editable": false,
"min": -1,
"max": 10000,
"step": 1,
"mode": "slider",
"unit_of_measurement": "minutes",
"friendly_name": "Garage Timer",
"icon": "mdi:clock-outline"
},
"last_changed": "2020-03-09T20:10:12.628256+00:00",
"last_updated": "2020-03-09T20:10:12.628256+00:00",
"context": {
"id": "1609617444f944449db733710284721a",
"parent_id": "5869fcfcafff406b900e899d59baf3fe",
"user_id": null
}
},
"new_state": {
"entity_id": "input_number.garage_timer_input",
"state": "4.0",
"attributes": {
"initial": -1,
"editable": false,
"min": -1,
"max": 10000,
"step": 1,
"mode": "slider",
"unit_of_measurement": "minutes",
"friendly_name": "Garage Timer",
"icon": "mdi:clock-outline"
},
"last_changed": "2020-03-09T20:11:15.017914+00:00",
"last_updated": "2020-03-09T20:11:15.017914+00:00",
"context": {
"id": "77aa1bc4d38f4acf956628cdf19ff127",
"parent_id": "1609617444f944449db733710284721a",
"user_id": null
}
}
},
"origin": "LOCAL",
"time_fired": "2020-03-09T20:11:15.017994+00:00",
"context": {
"id": "77aa1bc4d38f4acf956628cdf19ff127",
"parent_id": "1609617444f944449db733710284721a",
"user_id": null
}
}
Event 3 fired 4:10 PM:
{
"event_type": "state_changed",
"data": {
"entity_id": "automation.garage_lights_door_event_handler",
"old_state": {
"entity_id": "automation.garage_lights_door_event_handler",
"state": "on",
"attributes": {
"last_triggered": "2020-03-09T20:01:04.209209+00:00",
"id": "garage_light_automation_1",
"friendly_name": "Garage Lights Door Event Handler"
},
"last_changed": "2020-03-09T20:08:45.891661+00:00",
"last_updated": "2020-03-09T20:08:45.891661+00:00",
"context": {
"id": "c2c0a769d1bf4e84b9776529d6d9dc7a",
"parent_id": null,
"user_id": null
}
},
"new_state": {
"entity_id": "automation.garage_lights_door_event_handler",
"state": "on",
"attributes": {
"last_triggered": "2020-03-09T20:10:12.659551+00:00",
"id": "garage_light_automation_1",
"friendly_name": "Garage Lights Door Event Handler"
},
"last_changed": "2020-03-09T20:08:45.891661+00:00",
"last_updated": "2020-03-09T20:10:12.660096+00:00",
"context": {
"id": "1609617444f944449db733710284721a",
"parent_id": "5869fcfcafff406b900e899d59baf3fe",
"user_id": null
}
}
},
"origin": "LOCAL",
"time_fired": "2020-03-09T20:10:12.660176+00:00",
"context": {
"id": "1609617444f944449db733710284721a",
"parent_id": "5869fcfcafff406b900e899d59baf3fe",
"user_id": null
}
}
Event 2 fired 4:10 PM:
{
"event_type": "state_changed",
"data": {
"entity_id": "automation.garage_lights_counter_state_handler",
"old_state": {
"entity_id": "automation.garage_lights_counter_state_handler",
"state": "on",
"attributes": {
"last_triggered": "2020-03-09T20:04:17.152427+00:00",
"id": "garage_light_automation_2",
"friendly_name": "Garage Lights Counter State Handler"
},
"last_changed": "2020-03-09T20:08:45.919139+00:00",
"last_updated": "2020-03-09T20:08:45.919139+00:00",
"context": {
"id": "2f9cbb56d97646aca75b9e6805632f50",
"parent_id": null,
"user_id": null
}
},
"new_state": {
"entity_id": "automation.garage_lights_counter_state_handler",
"state": "on",
"attributes": {
"last_triggered": "2020-03-09T20:10:12.641937+00:00",
"id": "garage_light_automation_2",
"friendly_name": "Garage Lights Counter State Handler"
},
"last_changed": "2020-03-09T20:08:45.919139+00:00",
"last_updated": "2020-03-09T20:10:12.642501+00:00",
"context": {
"id": "77aa1bc4d38f4acf956628cdf19ff127",
"parent_id": "1609617444f944449db733710284721a",
"user_id": null
}
}
},
"origin": "LOCAL",
"time_fired": "2020-03-09T20:10:12.642578+00:00",
"context": {
"id": "77aa1bc4d38f4acf956628cdf19ff127",
"parent_id": "1609617444f944449db733710284721a",
"user_id": null
}
}
Event 1 fired 4:10 PM:
{
"event_type": "state_changed",
"data": {
"entity_id": "input_number.garage_timer_input",
"old_state": {
"entity_id": "input_number.garage_timer_input",
"state": "-1.0",
"attributes": {
"initial": -1,
"editable": false,
"min": -1,
"max": 10000,
"step": 1,
"mode": "slider",
"unit_of_measurement": "minutes",
"friendly_name": "Garage Timer",
"icon": "mdi:clock-outline"
},
"last_changed": "2020-03-09T20:04:17.076674+00:00",
"last_updated": "2020-03-09T20:04:17.076674+00:00",
"context": {
"id": "360463d62db146d1afc2a125128974e1",
"parent_id": "2a0240a56056459e910cc4e214fbbecf",
"user_id": null
}
},
"new_state": {
"entity_id": "input_number.garage_timer_input",
"state": "5.0",
"attributes": {
"initial": -1,
"editable": false,
"min": -1,
"max": 10000,
"step": 1,
"mode": "slider",
"unit_of_measurement": "minutes",
"friendly_name": "Garage Timer",
"icon": "mdi:clock-outline"
},
"last_changed": "2020-03-09T20:10:12.628256+00:00",
"last_updated": "2020-03-09T20:10:12.628256+00:00",
"context": {
"id": "1609617444f944449db733710284721a",
"parent_id": "5869fcfcafff406b900e899d59baf3fe",
"user_id": null
}
}
},
"origin": "LOCAL",
"time_fired": "2020-03-09T20:10:12.628349+00:00",
"context": {
"id": "1609617444f944449db733710284721a",
"parent_id": "5869fcfcafff406b900e899d59baf3fe",
"user_id": null
}
}