We have a Light in our pantry
I got thinking about how can I automate The pantry Light
the logic:
pantry light must come on when the Door open
pantry light must go off when the Door closed
but want to add some conditions only turn the pantry light on if the Kitchen lights are on
and if the kitchen lights are turned off the pantry light is turned off even if the door is still open.
shopping list:
Door Sensor
Sonoff Basic ( I like using them )
Put the Door Sensor on the pantry door
put ESP home on the Sonoff
Found this code here somewhere
Thanks to the person who wrote it
substitutions:
name: pantry_lights
ip: ###.###.###.###
friendly_name: Pantry Lights
esphome:
name: ${name}
platform: ESP8266
board: esp01_1m
board_flash_mode: dout
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
reboot_timeout: 0s
fast_connect: true
manual_ip:
static_ip: ${ip}
gateway: ###.###.###.###
subnet: 255.255.255.0
# Enable logging
logger:
# Enable Home Assistant API
api:
reboot_timeout: 0s
ota:
web_server:
port: 80
binary_sensor:
- platform: gpio
pin:
number: GPIO0
mode: INPUT_PULLUP
inverted: True
id: button
# name: "Sonoff Basic Button" # uncomment to expose the button as a binary senor
on_press:
- switch.toggle: relay_template
- platform: gpio
pin:
#number: GPIO3 # (RX Pin) - if using the newer Sonoff Basic with Wires instead of traces
number: GPIO14
mode: INPUT_PULLUP
#inverted: True
id: wall_switch
filters:
- delayed_on: 100ms
- delayed_off: 100ms
# name: "Sonoff Basic Button" # uncomment to expose the button as a binary senor
on_press:
- switch.toggle: relay_template
on_release:
- switch.toggle: relay_template
on_multi_click:
- timing:
- ON for at most 0.5s
- OFF for at most 0.5s
- ON for at most 0.5s
- OFF for at most 0.5s
- ON for at most 0.5s
- OFF for at most 0.5s
- ON for at most 0.5s
- OFF for at least 0.2s
then:
- switch.turn_on: restart_sonoff
switch:
- platform: gpio
pin: GPIO12
id: relay
## https://esphomelib.com/esphomeyaml/components/switch/template.html
## tie the led & relay together & report status regardless of trigger method
- platform: template
name: ${friendly_name}
id: relay_template
lambda: |-
if (id(relay).state) {
return true;
} else {
return false;
}
turn_on_action:
- light.turn_on: status_led
- switch.turn_on: relay
turn_off_action:
- light.turn_off: status_led
- switch.turn_off: relay
# optimistic: true # this will change the toggle switch to individual on/off buttons
- platform: restart
#name: "Reboot Kitchen Sconce Sonoff"
id: restart_sonoff
output:
## https://esphomelib.com/esphomeyaml/components/output/esp8266_pwm.html
## create a PWM pin to control
- platform: esp8266_pwm
id: basic_green_led
pin:
number: GPIO13
inverted: True
light:
## https://esphomelib.com/esphomeyaml/components/light/monochromatic.html
## attach a monochrome light to the PWM pin
- platform: monochromatic
# name: "Sonoff Basic Green LED" # uncomment to expose the led as a light with brightness control
output: basic_green_led
id: status_led
default_transition_length: 1ms # controls the light fade/transition time
text_sensor:
- platform: version
name: ${friendly_name} ESPHome Version
sensor:
- platform: wifi_signal
name: ${friendly_name} WiFi Signal Strength
update_interval: 60s
I have 2 automation
1st ONE
Dealing with opening and closing the Pantry door turning on/off the Pantry light
- id: 90802f0e-3f03-4737-b911-517f97f225f6
alias: Sink pantry light with pantry door
trigger:
- platform: state
entity_id: binary_sensor.pantry_door
action:
- choose:
- conditions:
- condition: state
entity_id: binary_sensor.pantry_door
state: "on"
- condition: state
entity_id: light.kitchen
state: "on"
sequence:
- service: switch.turn_on
entity_id: switch.pantry_lights
- conditions:
- condition: state
entity_id: binary_sensor.pantry_door
state: "off"
sequence:
- service: switch.turn_off
entity_id: switch.pantry_lights
2nd ONE
dealing with the Kitchen light turning on/off and checking the state of the pantry door
- id: c5a0b778-6577-4a5e-8395-a976f664aa4f
alias: Sink pantry light with kitchen lights
trigger:
- platform: state
entity_id: light.kitchen
action:
- choose:
- conditions:
- condition: state
entity_id: binary_sensor.pantry_door
state: "on"
- condition: state
entity_id: light.kitchen
state: "on"
sequence:
- service: switch.turn_on
entity_id: switch.pantry_lights
- conditions:
- condition: state
entity_id: light.kitchen
state: "off"
sequence:
- service: switch.turn_off
entity_id: switch.pantry_lights
yes could have put into One automation
by joining the trigger into one automation
but my thinking is to solve each problem as I see it in my head.
setting back now looking at those conditions they are the same.