So my goal is if someone opens the door, it should turn on the light, but if someone hits the button to turn it off, it stays off until the door closes and opens again.
But right now unless I close the door, the light can’t stay off.
I have read [Solved] Door sensor works properly on open and close, but turns the light back on if the door is left open, but I used esphome.
Down below is the yaml for this automation, and the esphome config.
And the switch.relay1_3 is the light I want to fix.
alias: >-
Outside Light and Ender3 Light. If the door open or close, And Beep if want to
notify me for anything.
description: ""
trigger:
- platform: state
entity_id:
- binary_sensor.outside_door_sensor
from: "off"
to: "on"
for:
hours: 0
minutes: 0
seconds: 1
id: Door Open
- platform: state
entity_id:
- binary_sensor.outside_door_sensor
from: "on"
to: "off"
for:
hours: 0
minutes: 0
seconds: 5
id: Door Close
- platform: state
entity_id:
- sensor.ender3btt_cb1_current_print_state
from: null
to: printing
for:
hours: 0
minutes: 0
seconds: 1
id: Printing
- platform: state
entity_id:
- sensor.ender3btt_cb1_current_print_state
from: printing
to: complete
for:
hours: 0
minutes: 0
seconds: 1
id: Printing Is Complete
- platform: state
entity_id:
- sensor.ender3btt_cb1_current_print_state
from: null
to: error
for:
hours: 0
minutes: 0
seconds: 1
id: Error!!! Error!!!
- platform: state
entity_id:
- sensor.ender3btt_cb1_current_print_state
from: null
to: cancelled
for:
hours: 0
minutes: 0
seconds: 1
id: Please Check Why It Cancel Print.
- platform: state
entity_id:
- sensor.ender3btt_cb1_current_layer
from: null
to: "3"
for:
hours: 0
minutes: 0
seconds: 1
id: Third Layer Check
- platform: mqtt
topic: Ender3/Power/Ender3Light/On
id: MQTTEnder3LightOn
- platform: mqtt
topic: Ender3/Power/Ender3Light/Off
id: MQTTEnder3LightOff
condition: []
action:
- choose:
- conditions:
- condition: trigger
id: Door Open
- condition: time
after: "18:00:00"
before: "08:00:00"
sequence:
- type: turn_on
device_id: 41a5dd6fed360beeb0c6985937310867
entity_id: switch.relay1_3
domain: switch
- condition: or
conditions:
- condition: state
entity_id: sensor.ender3btt_cb1_current_print_state
state: printing
- condition: state
entity_id: sensor.ender3btt_cb1_current_print_state
state: complete
for:
hours: 0
minutes: 15
seconds: 0
enabled: false
- type: turn_on
device_id: 41a5dd6fed360beeb0c6985937310867
entity_id: b49f720203db3484376143c054bd8c90
domain: switch
- conditions:
- condition: trigger
id: Door Close
sequence:
- type: turn_off
device_id: 41a5dd6fed360beeb0c6985937310867
entity_id: switch.relay1_3
domain: switch
- condition: not
conditions:
- condition: state
entity_id: sensor.ender3btt_cb1_current_print_state
state: printing
- type: turn_off
device_id: 41a5dd6fed360beeb0c6985937310867
entity_id: b49f720203db3484376143c054bd8c90
domain: switch
- conditions:
- condition: or
conditions:
- condition: trigger
id:
- Printing
- condition: trigger
id:
- MQTTEnder3LightOn
sequence:
- type: turn_on
device_id: 41a5dd6fed360beeb0c6985937310867
entity_id: b49f720203db3484376143c054bd8c90
domain: switch
- conditions:
- condition: trigger
id:
- Printing Is Complete
sequence:
- service: button.press
data: {}
target:
entity_id: button.ender3_btt_cb1_macro_beep_six_times
- conditions:
- condition: or
conditions:
- condition: trigger
id:
- Error!!! Error!!!
- condition: trigger
id:
- Please Check Why It Cancel Print.
sequence:
- type: turn_on
device_id: f9ad33f77fc54d0000033e9f5a98d273
entity_id: cb976f711eb7d95d9b6f92a66d2adc8f
domain: switch
- conditions:
- condition: trigger
id:
- Third Layer Check
sequence:
- service: notify.mobile_app_samsung_a23
data:
message: "Third Layer Check!! "
data:
actions:
- action: URI
title: Open
uri: /for-outside/for-outside
- conditions:
- condition: trigger
id: Door Open
- condition: time
after: "08:00:00"
before: "06:00:00"
sequence:
- condition: or
conditions:
- condition: state
entity_id: sensor.ender3btt_cb1_current_print_state
state: printing
- condition: not
conditions:
- condition: state
entity_id: sensor.ender3btt_cb1_current_print_state
state: complete
for:
hours: 0
minutes: 15
seconds: 0
- conditions:
- condition: trigger
id:
- MQTTEnder3LightOff
sequence:
- type: turn_off
device_id: 41a5dd6fed360beeb0c6985937310867
entity_id: b49f720203db3484376143c054bd8c90
domain: switch
mode: restart
substitutions:
esphome_name: outside
esphome:
name: ${esphome_name}
platform: ESP32
board: nodemcu-32s
wifi:
networks:
- ssid: !secret wifi_ssid
password: !secret wifi_password
ap:
ssid: "${esphome_name} ESPHome Fallback Hotspot"
password: !secret wifi_ap_password
text_sensor:
- platform: wifi_info
ip_address:
name: ${esphome_name} IP Address
ssid:
name: ${esphome_name} Connected SSID
bssid:
name: ${esphome_name} Connected BSSID
mac_address:
name: ${esphome_name} Mac Wifi Address
scan_results:
name: ${esphome_name} Latest Scan Results
captive_portal:
# Enable logging
logger:
level: debug
# Enable Home Assistant API
api:
encryption:
key: "!secret HAAPi"
ota:
password: "!secret OTA"
time:
- platform: homeassistant
esp32_ble_tracker:
switch:
- platform: gpio
name: "${esphome_name}-Onboard-LED"
pin: 2
- platform: restart
name: ${esphome_name}-restart
id: restart_switch
- platform: gpio
name: Relay1
id: "Relay1"
pin: 5
restore_mode: RESTORE_DEFAULT_OFF
- platform: gpio
name: Relay2
id: "Relay2"
pin: 13
restore_mode: RESTORE_DEFAULT_OFF
sensor:
- platform: uptime
name: "${esphome_name}_Uptime Sensor"
- platform: wifi_signal
name: "${esphome_name} WiFi Signal"
update_interval: 60s
remote_transmitter:
pin: 18
carrier_duty_percent: 50%
#remote_receiver:
# id: IR_Receiver
# pin:
# number: 19
# mode:
# input: true
# pullup: true
# inverted: True
# dump: all
# tolerance: 55%
binary_sensor:
- platform: gpio
name: ${esphome_name} OnBoard Button
pin:
number: GPIO0
mode: INPUT_PULLUP
inverted: True
on_press:
- switch.toggle: "Relay1"
- switch.toggle: "Relay2"
filters:
- delayed_on: 100ms
- platform: gpio
id: Button1
#name: ${esphome_name} Button1
pin:
number: GPIO25
mode: INPUT_PULLUP
inverted: True
on_press:
then:
- switch.toggle: Relay1
# on_multi_click:
# - timing:
# - ON for at least 1s
# then:
# - switch.turn_on: Relay1
filters:
- delayed_on: 100ms
- platform: gpio
id: Button2
#name: ${esphome_name} Button2
pin:
number: GPIO27
mode: INPUT_PULLUP
inverted: True
on_press:
then:
- switch.toggle: Relay2
# on_multi_click:
# - timing:
# - ON for at least 1s
# then:
# - switch.turn_on: Relay2
filters:
- delayed_on: 100ms
- platform: status
name: "${esphome_name} Status"
- platform: gpio
name: ${esphome_name} Door Sensor
pin:
number: GPIO21
mode: INPUT_PULLUP
filters:
- delayed_on: 200ms