I have about 12 sensors, and in essence, 12 automations. I’ve included 3 of them below… how can I merge this all into one automation?
At one point I was attempting to use a script that tried to combine them all, but if multiple sensors were in the ON state at the same time, i ran into issues where the wrong sensor’s datetime would be updated.
- alias: Kitchen Window Last Opened
trigger:
- platform: state
entity_id: binary_sensor.kitchen_window
from: 'off'
to: 'on'
action:
- service: input_datetime.set_datetime
data_template:
entity_id: >
input_datetime.kitchen_window_open
time: '{{ (as_timestamp(now()) | timestamp_custom("%H:%M:%S", true)) }}'
date: '{{ (as_timestamp(now()) | timestamp_custom("%Y-%m-%d", true)) }}'
- alias: Bedroom Window Last Opened
trigger:
- platform: state
entity_id: binary_sensor.bedroom_window
from: 'off'
to: 'on'
action:
- service: input_datetime.set_datetime
data_template:
entity_id: >
input_datetime.bedroom_window_open
time: '{{ (as_timestamp(now()) | timestamp_custom("%H:%M:%S", true)) }}'
date: '{{ (as_timestamp(now()) | timestamp_custom("%Y-%m-%d", true)) }}'
- alias: Front Window Last Opened
trigger:
- platform: state
entity_id: binary_sensor.front_window
from: 'off'
to: 'on'
action:
- service: input_datetime.set_datetime
data_template:
entity_id: >
input_datetime.front_window_open
time: '{{ (as_timestamp(now()) | timestamp_custom("%H:%M:%S", true)) }}'
date: '{{ (as_timestamp(now()) | timestamp_custom("%Y-%m-%d", true)) }}'