Hi all,
I’m from Australia and have these DETA Grid Connect Smart Switchs that I replaced the stock chip with an ESP into and got working with esphome!
They no longer come with an esp8266 however it is easy enough to swap for an esp as it has the same pinout.
Video explains how to replace chip
Reference 1
Reference 2
I also individually wired up the leds for the buttons as outputs, as before they were tied to the light status.
I also managed to fit in a motion sensor and have that as an input to one of the ESP pins.
This is the config I landed with (exposes 3 lights and PIR + status led to HA) - click to view
substitutions:
device_name: deta3gangswitch
friendly_name: "3 Gang Switch"
device_ip: 192.168.1.100
#################################
esphome:
platform: ESP8266
board: esp12e
name: ${device_name}
esp8266_restore_from_flash: true
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
manual_ip:
static_ip: ${device_ip}
gateway: 192.168.1.1
subnet: 255.255.255.0
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "ESPHOME"
password: "12345678"
api:
password: !secret api_password
ota:
password: !secret ota_password
logger:
# The web_server & sensor components can be removed without affecting core functionaility.
web_server:
port: 80
sensor:
- platform: wifi_signal
name: ${device_name} Wifi Signal Strength
update_interval: 60s
- platform: uptime
name: ${device_name} Uptime
#################################
# status_led:
# pin:
# number: GPIO0
# inverted: True
output:
# 1st button
- platform: gpio
pin: GPIO5
id: relay1
# 2nd button
- platform: gpio
pin: GPIO14
id: relay2
# 3rd button
- platform: gpio
pin: GPIO12
id: relay3
# 1st button led
- platform: esp8266_pwm
pin: GPIO1
id: led1
# 2nd button led
- platform: esp8266_pwm
pin: GPIO13
id: led3
# 3rd button led
- platform: esp8266_pwm
pin: GPIO15
id: led2
light:
# Status LED
- platform: status_led
name: "Status Led"
pin:
number: GPIO0
inverted: True
id: statusLed
# 1st button
- platform: binary
name: "${friendly_name} 1st"
output: relay1
id: light1
on_turn_on:
- light.turn_on:
id: light_led1
on_turn_off:
- light.turn_off:
id: light_led1
# 2nd button
- platform: binary
name: "${friendly_name} 2nd"
output: relay2
id: light2
on_turn_on:
- light.turn_on:
id: light_led2
on_turn_off:
- light.turn_off:
id: light_led2
# 3rd button
- platform: binary
name: "${friendly_name} 3rd"
output: relay3
id: light3
on_turn_on:
- light.turn_on:
id: light_led3
on_turn_off:
- light.turn_off:
id: light_led3
# 1st led
- platform: monochromatic
name: "${friendly_name} 1st led"
output: led1
id: light_led1
default_transition_length: 0s
effects:
- pulse:
- pulse:
name: "Fast Pulse"
transition_length: 0.5s
update_interval: 0.5s
- pulse:
name: "Slow Pulse"
# transition_length: 1s # defaults to 1s
update_interval: 2s
- pulse:
name: "Fast Strobe"
transition_length: 0s # defaults to 1s
update_interval: 0.5s
- pulse:
name: "Slow Strobe"
transition_length: 0s # defaults to 1s
update_interval: 1s
# 2nd led
- platform: monochromatic
name: "${friendly_name} 2nd led"
output: led2
id: light_led2
default_transition_length: 0s
effects:
- pulse:
- pulse:
name: "Fast Pulse"
transition_length: 0.5s
update_interval: 0.5s
- pulse:
name: "Slow Pulse"
# transition_length: 1s # defaults to 1s
update_interval: 2s
- pulse:
name: "Fast Strobe"
transition_length: 0s # defaults to 1s
update_interval: 0.5s
- pulse:
name: "Slow Strobe"
transition_length: 0s # defaults to 1s
update_interval: 1s
# 3rd led
- platform: monochromatic
name: "${friendly_name} 3rd led"
output: led3
id: light_led3
default_transition_length: 0s
effects:
- pulse:
- pulse:
name: "Fast Pulse"
transition_length: 0.5s
update_interval: 0.5s
- pulse:
name: "Slow Pulse"
# transition_length: 1s # defaults to 1s
update_interval: 2s
- pulse:
name: "Fast Strobe"
transition_length: 0s # defaults to 1s
update_interval: 0.5s
- pulse:
name: "Slow Strobe"
transition_length: 0s # defaults to 1s
update_interval: 1s
# Buttons
binary_sensor:
# 1st button
- platform: gpio
pin:
number: GPIO16
mode: INPUT
inverted: True
name: "${friendly_name} 1st Button"
#toggle relay on push
on_press:
- light.toggle: light1
# 2nd button
- platform: gpio
pin:
number: GPIO4
mode: INPUT_PULLUP
inverted: True
name: "${friendly_name} 2nd Button"
#toggle relay on push
on_press:
- light.toggle: light2
# 3rd button
- platform: gpio
pin:
number: GPIO3
mode: INPUT_PULLUP
inverted: True
name: "${friendly_name} 3rd Button"
#toggle relay on push
on_press:
- light.toggle: light3
# Motion PIR
- platform: gpio
pin:
number: GPIO2
mode: INPUT_PULLUP
inverted: True
name: "PIR Sensor"
device_class: motion
on_press:
then:
- light.turn_on: statusLed
on_release:
then:
- light.turn_off: statusLed
switch:
- platform: restart
name: "${friendly_name} REBOOT"
I have always wanted smart lights but have been looking for a solution that:
- Is an Australian approved product
- Has a motion sensor to auto off after X time
- Ability to change modes on the switch between automatic and manual
- Has an LED per switch that can be dimmable / flash (ie not attached to light output) to show current mode.
- Connects to Home Assistant
I think with the above hardware + included mods and esphome I finally found a good solution.
(Better solution would be above product if it came with a motion sensor inbuilt )
Now to the meat of my post, I need help deciding on the logic for automatic/manual of the switch.
I have developed the below flow chart which I think captures all the modes.
The LED
in the flowchart refers to the blue led on the switch.
The Light
refers to the light (load) connected to the switch.
Diagram (click for larger image)
I would ideally like to keep the logic local (in esphome automations) and not rely on Home Assistant (node red) for the local switch logic.
I would however like to have HA change the mode status (ie turn the light on / off / place it into off_Standby
etc)
Some things I need to figure out:
-
What kind of data type the main logic (
off_Standby
,on_Standby
,Off_Manual
,On_Manual
). I am thinking of using thetext_sensor
in esphome. I code in typescript and would usually reach for an enum here. -
How will I go about letting HA change the modes? (Node red). I would like to have the traditional light (on/off) entity in HA on the frontend, somehow mapped to the above modes. Thinking via a proxy sensor in the esphome config that will simply trigger different modes based on on/off action from HA. And maybe via node red too, For example if its daytime put it into
Off_Manual
, when it gets to night place it intooff_Standby
). -
I would like to use motion sensors from other switches to be an input to the logic of a switch. (ie a 2 way switch at two ends of a hall, where any end has motion to turn on the hallway light).
I think I will expose the motion sensor via the normal binary_sensor to HA, then on the switch config using the Home Assistant Sensor to get status of other motion sensors in other switches.
What do you think?
Has anyone looked at achieving something similar?
How should I go about coding this logic in the esphome config; automations/lambda? (Don’t need someone to do it for me, just general tips/ideas of approach - I have’t got to this step myself yet)
Just wanted to get my ideas fleshed out before writing up the config.