Quantcast
Channel: Configuration - Home Assistant Community
Viewing all articles
Browse latest Browse all 95919

Light off automation with new "on" events resetting the countdown

$
0
0

@devitus wrote:

Hi everyone,

I hope you can help me with the following.

I’ve got an automatioon that turns off garage lights (via Sonoff 2-channel light switch) after a certain period of time, however current logic is flawed.

There are two triggers in the automation that turns on the garage lights:

  1. Via contact sensor on the garage back door (binary_sensor.garage_back_door)
  2. Via motion sensor in the garage (binary_sensor.garage_motion)

Code below for the automation that turns on the lights (ID values scrapped just in case, not sure if those should be shared):

- id: '123123123123123'
  alias: Garage Lights On
  description: ''
  trigger:
  - entity_id: binary_sensor.garage_back_door
    from: 'off'
    platform: state
    to: 'on'
  - entity_id: binary_sensor.garage_motion
    from: 'off'
    platform: state
    to: 'on'
  condition: []
  action:
  - entity_id: switch.sonoff_1000884e8a_1
    service: switch.turn_on
  - delay: 00:00:01
  - entity_id: switch.sonoff_1000884e8a_2
    service: switch.turn_on

And this is the automation that turns the lights off:

- id: '123123123123123'
  alias: Garage Lights Off
  description: ''
  trigger:
  - entity_id: binary_sensor.garage_motion
    from: 'on'
    platform: state
    to: 'off'
    for: 0:00:30
  condition: []
  action:
  - entity_id: switch.sonoff_1000884e8a_1
    service: switch.turn_off
  - delay: 00:00:01
  - entity_id: switch.sonoff_1000884e8a_2
    service: switch.turn_off

The problem is that this automation is only triggered when the motion sensor’s (binary_sensor.garage_motion) status changes from “on” to “off” (I have another automation that switches it to “off” state in 5 seconds from coming to “on”). So if the lights had been turned on via sensor on the garage back door (binary_sensor.garage_back_door), or manually via the switch without ever setting off the motion sensor, then the 30 second countdown would never start, and the lights would remain on indefinitely.

Ideally, I’d like any time the lights are turned on to trigger a 30-second coundown, and for every subsequent “turn on” even to reset that countdown back to 30 seconds every time. However, as far as I know, automations can only be triggered by a changed state (“on” to “off”, or “off” to “on”), so sending a new “on” request to a device that’s already “on” would effectively do nothing.

What’s would be the most efficient way of achieving the above?

Thanks in advance for your help!

Posts: 3

Participants: 2

Read full topic


Viewing all articles
Browse latest Browse all 95919

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>