Hello, dear community. This is my first attempt at automation, and so far, it’s failing. I have three Tuya wifi motion sensors, two Tuya door sensors, and a Tuya light switch.
I have one automation for door sensors and one for motion sensors. I want the light to turn on whenever one of the doors opens and stay like that for 4 minutes regardless of whether the door closes afterward. The other one is for motion sensors. I want the light to keep on as long as a motion is detected on either of the three sensors and keep it on for 4 minutes before turning it off.
My problem is that sometimes(most of the time), the light doesn’t turn on even though the motion sensor sees the movement and reports it to HA. Sometimes, it doesn’t turn to either also, regardless of the fact that the HA registers the change in the sensor state.
Here’s the code for motion sensor:
alias: Garage Lights Control by Motion
description: >-
Keep garage lights on when motion is detected and turn off after no motion for
4 minutes.
trigger:
- platform: state
entity_id:
- binary_sensor.senzor_prisutnosti_garaza_1_motion
- binary_sensor.senzor_prisutnosti_garaza_2_motion
- binary_sensor.senzor_prisutnosti_garaza_3_motion
to: "on"
condition: []
action:
- service: switch.turn_on
target:
entity_id: switch.garage_switch_1
data: {}
- wait_for_trigger:
- platform: state
entity_id: binary_sensor.senzor_prisutnosti_garaza_1_motion
to: "off"
for: "00:04:00"
- platform: state
entity_id: binary_sensor.senzor_prisutnosti_garaza_2_motion
to: "off"
for: "00:04:00"
- platform: state
entity_id: binary_sensor.senzor_prisutnosti_garaza_3_motion
to: "off"
for: "00:04:00"
continue_on_timeout: false
- service: switch.turn_off
target:
entity_id: switch.garage_switch_1
data: {}
mode: restart
And the code for the doors:
alias: Otvaranje vrata u garaži
description: ""
trigger:
- type: opened
platform: device
device_id: bbc129be15f4a821e9a7fc00da804cfa
entity_id: c39d4fe6099929ba1d35227f2f705eca
domain: binary_sensor
- type: opened
platform: device
device_id: c6643925d5f0e5e81315e950fb62591b
entity_id: 06e8656446a0ca0e58d3c6d721ed4106
domain: binary_sensor
condition:
- condition: device
type: is_off
device_id: 998d3dba3138453c8ccba3f1c83eba52
entity_id: 52836c3bf856f372bb65f50b46dedd93
domain: switch
action:
- type: turn_on
device_id: 998d3dba3138453c8ccba3f1c83eba52
entity_id: 52836c3bf856f372bb65f50b46dedd93
domain: switch
- delay:
hours: 0
minutes: 2
seconds: 0
milliseconds: 0
- type: turn_off
device_id: 998d3dba3138453c8ccba3f1c83eba52
entity_id: 52836c3bf856f372bb65f50b46dedd93
domain: switch
mode: single
Thank you all for your time in advance.
Nik