So this is what i am trying to do.
I have an input from a occupancy sensor which operates day and night so I want to create an Automation in ESPHome to control how the lights operate.
So light 1 on Relay 1 to operate when triggered between sun.is_below_horizon: elevation: 5 and sun.is_below_horizon: elevation: 15
light 2 on Relay 2 to operate when triggered when sun.is_below_horizon: elevation: 5 thru to morning.
Input 2 is a manual override to switch both R1 and R2 and button 3 just toggles R1 & R2
I have it partially configured as below but I am not happy with it
esphome:
name: sonoff_dual_r2
platform: ESP8266
board: esp01_1m
wifi:
ssid: "REDACTED"
password: "REDACTED"
power_save_mode: none
manual_ip:
static_ip: 192.168.0.XX
gateway: 192.168.0.2
subnet: 255.255.255.0
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Sonoff Dual R2 Fallback Hotspot"
password: "uJvBFNP0BZA9"
captive_portal:
# Enable logging
logger:
# Enable Home Assistant API
api:
ota:
# Enable Web server.
web_server:
port: 80
# Sync time with Home Assistant.
time:
- platform: homeassistant
id: homeassistant_time
sun:
latitude: XX.410275
longitude: -X.357627
text_sensor:
- platform: version
name: "ESPHome sonoff_dual_r2"
# Example configuration entry
- platform: wifi_info
ip_address:
name: IP Address sonoff_dual_r2
ssid:
name: SSID sonoff_dual_r2
bssid:
name: BSSID sonoff_dual_r2
# Sensors with general information.
sensor:
# Uptime sensor.
- platform: uptime
name: sonoff_dual_r2 Uptime
# WiFi Signal sensor.
- platform: wifi_signal
name: sonoff_dual_r2 WiFi Signal
update_interval: 60s
binary_sensor:
- platform: gpio
pin:
number: GPIO0
mode: INPUT_PULLUP
inverted: True
name: "sonoff_dual_r2 Button 1 AUTO"
on_press:
- if:
condition:
- sun.is_below_horizon:
elevation: 5
then:
- switch.turn_on: relay_1
- if:
condition:
- sun.is_below_horizon:
elevation: 15
then:
- switch.turn_off: relay_1
- if:
condition:
- sun.is_below_horizon:
elevation: 5
- sun.is_below_horizon:
elevation: 15
then:
- switch.turn_on: relay_2
on_release:
then:
- switch.turn_off: relay_1
- switch.turn_off: relay_2
- platform: gpio
pin:
number: GPIO9
mode: INPUT_PULLUP
inverted: True
name: "sonoff_dual_r2 Button 2 Manual Overide"
on_press:
then:
- switch.turn_on: relay_1
- switch.turn_on: relay_2
on_release:
then:
- switch.turn_off: relay_1
- switch.turn_off: relay_2
- platform: gpio
pin:
number: GPIO10
mode: INPUT_PULLUP
inverted: True
name: "sonoff_dual_r2 Button 3"
on_press:
- switch.toggle: relay_1
- switch.toggle: relay_2
- platform: status
name: "sonoff_dual_r2 Status"
switch:
- platform: gpio
name: "Relay 1 sonoff_dual_r2"
pin: GPIO12
id: relay_1
icon: mdi:electric-switch
- platform: gpio
name: "Relay 2 sonoff_dual_r2"
pin: GPIO5
id: relay_2
icon: mdi:electric-switch
status_led:
pin:
number: GPIO13
inverted: false
So the problem is that when I activate trigger and when - sun.is_below_horizon: elevation 15 i get a short (milliseconds) activation of R!.
I was wondering if I could write some Lambda for the sun.is_below_horizon to return a state between >5 and <15 but I just get errors.
Any thoughts?