Some advice - almost completed migrating from SmartThings one more to go.. ESP32

It’s been a fairly steep learning curve but I’ve really enjoyed the journey! But… one more device to come. I’m running HASSIO on a RPI4.

Let me explain.

I’ve got an ESP32 board wired to some hand made electronics doing positive side switching (mosfets/transistors) for 10 lights down my hallway. I wrote custom code for SmartThings to integrate following this model:

  • One of the GPIO pins is seen as a single switch (i.e. light) - this pin is not really in use it’s a “spare” so it’s only for faking being a single light vs 10.
  • When this pin is turned on or off I react in code and sequence the lights as I see fit

I’ve made some inroads looking as ESPHome (great work BTW) with some sonoff switches already integrated, done some reading but wanted to ask for some advice:

  • If I want to follow the same model is ESPHome the way to go? Can I override the appropriate methods and follow the same model so that that HA sees this as a single device and I can write my own sequencing? Or is this not the way?

I cannot give you detailed advice, still I think that the “Custom component” part of ESP home should solve your problems.
https://esphome.io/custom/custom_component.html
Here you can take custom C++ code and have it running with ESPHome. It can also talk to the ESPHome firmware part to use all ESPHome goodies.
So f.ex. you would write your code for the 10 lights and connect it to ESPHome. Then, whenever you have your ESP32 connected to HA with the ESPHome firmware, HA will find 10 lights and you can control these asevery other light in HA.

Still this is not the easiest programming/configuration you can have in ESPHome :wink:

1 Like

Having read through the docs and given it some thought I’ve tried the following:

switch:
- platform: gpio
  pin: GPIO16
  name: "Relay #1"
  id: relay1

- platform: gpio
  pin: GPIO17
  name: "Relay #2"
  id: relay2

- platform: gpio
  pin: GPIO18
  name: "Relay #3"
  id: relay3

- platform: gpio
  pin: GPIO19
  name: "Relay #4"
  id: relay4

- platform: gpio
  pin: GPIO21
  name: "Relay #5"
  id: relay5

- platform: gpio
  pin: GPIO22
  name: "Relay #6"
  id: relay6

- platform: gpio
  pin: GPIO23
  name: "Relay #7"
  id: relay7

- platform: gpio
  pin: GPIO25
  name: "Relay #8"
  id: relay8

- platform: gpio
  pin: GPIO26
  name: "Relay #9"
  id: relay9

- platform: gpio
  pin: GPIO27
  name: "Relay #10"
  id: relay10

#This is our 'fake switch' used to trigger our sequences when turned on or off
- platform: gpio
  pin: GPIO33
  name: "RunawayLights"
  id: runwaylights
  on_turn_on:
    - logger.log: "Switch Turned On!"
    - script.execute: my_on_script
  on_turn_off:
    - logger.log: "Switch Turned Off!"
    - script.execute: my_off_script


script:
- id: my_on_script
  then:
      - switch.turn_on: relay1
      - delay: 2s
      - switch.turn_on: relay2
      - delay: 2s
      - switch.turn_on: relay3
      - delay: 2s
      - switch.turn_on: relay4
      - delay: 2s
      - switch.turn_on: relay5
      - delay: 2s
      - switch.turn_on: relay6
      - delay: 2s
      - switch.turn_on: relay7
      - delay: 2s
      - switch.turn_on: relay8
      - delay: 2s
      - switch.turn_on: relay9
      - delay: 2s
      - switch.turn_on: relay10
  #- delay: 1s
    #- switch.turn_off: my_switch

- id: my_off_script
  then:
      - switch.turn_off: relay1
      - delay: 2s
      - switch.turn_off: relay2
      - delay: 2s
      - switch.turn_off: relay3
      - delay: 2s
      - switch.turn_off: relay4
      - delay: 2s
      - switch.turn_off: relay5
      - delay: 2s
      - switch.turn_off: relay6
      - delay: 2s
      - switch.turn_off: relay7
      - delay: 2s
      - switch.turn_off: relay8
      - delay: 2s
      - switch.turn_off: relay9
      - delay: 2s
      - switch.turn_off: relay10
    #  - delay: 1s
    #- switch.turn_off: my_switch   

So my thoughts here are to keep the model of having the ‘fake switch’ and trigger scripts when this is turned on or off for the rest of the switches. This should allow me to set up sequences with minimal efforts. Just got a new board to trial this with…

…annnnd this does indeed work :slight_smile:

2 Likes