Home automating lighting, while preserving centralised, yet analogue system

Hi everyone,

I would like to make the lighting in my home smart but am inexperienced with ESPHome and Home Assistant.
At het moment the lights in my house are managed by relays and low voltage momentary switches.
I would like to keep this as is because it is a stable system.

Parallel to this system I would like to add a esp32 that controls everything via HA / google home.

Example:

I Would add a optocoupler module in parallel to the 230V of the light source and connect this to gpio pin D6. This would give information to the module if the light is on or off.

Via pin D11 I could control the light switch via the SV-5A1R1P-N PNP module 3.3V signal to 24V.

I think the hardware side is ok but I am unable to correctly program the ESP32 with ESPHome so that in HA it shows up as a light with push button.

I could just create a push button in ESPHome separate of the light state but I want ESPHome to know that this button via D11 controls the light on D6.

Can anyone put me in the right direction?

Thanks

You need something like:

binary_sensor:
- platform: gpio
  pin:
    number: D6
    mode: INPUT_PULLUP
    inverted: True
  name: "${plug_name} lighton"
  on_press:
    - switch.toggle: opto

switch:
- platform: gpio
  name: "${plug_name} opto"
  pin: D11
  id: opto

in your ESPHOME.

You can skip the on_press part not needed in your case

Thank you for the response but not really what I’m looking for.

The input on D6 should only be used as the status of the light and not activate the a switch.

The input via D11 has to be like a button giving a pulse to change the state of the relay (Same as the physical button would do)

but the “system” has to be aware that the status of D6 will change with a pulse of button on D11.

Hope this gives more clarity to my problem.

Still searching myself, thanks for the input.

@thomas.beutels

switch:
  - platform: gpio
    pin:
      number: D11
      inverted: True
    name: "Front Lights"
    id: relay1
    icon: "mdi:lightbulb"
    on_turn_on:
    - delay: 500ms
    - switch.turn_off: relay1

binary_sensor:
  - platform: gpio
    pin: 
      number: D6
      mode:
        input: true
        pullup: false
    name: "Light Status"
    device_class: light
    filters:
      - delayed_on: 20ms

@thomas.beutels the 1-Bit AC 220V Optocoupler Isolation Module Voltage Detect Board Adaptive 3-5V For PLC 24V Level TTL Level you are using only measures 220v but can be powered from 3.3 to 24v. I don’t see anywhere in the description that it can measure less than 220v.

The reason I am interested as this is exactly what I am thinking of doing! I might buy one and test!

@JulianDH thank you for the code, I’m going to test it this evening.
Do you want to use it for Dimming? Because I don’t think this is possible.

If you want to use it with 120V you could change the big resistor on the high voltage side.

You can find more info on this from bigclivedotcom on youtube.

After testing i would order this 24 channel module for a more compact setup.

I realised I misread your schematic. The 24V was close to the L line … so I though you were measuring 24V. But I see clearly it is AC Live! And this module looks perfect. Thank you for the link.

My lighting is 220V and controlled by Wise Box scene setting (Wise Scene Box Receiver Clear Lid 240V 4x500W | Wireless Radio Technology); the circuits are 3.3v momentary for on/off and hold to dim. It can also be controlled by way of RF … which is what my circuit is set up to do; it activates a RF transmits which has been programmed to control a few circuits between four different boxes. The only thing I am missing is a sensor to tell me when a circuit is on… and of course you are right …it probably will not work if the circuit has been already dimmed… more fiddling and testing!

Ok, still waiting on the final components but i think i got the code working.

Found some help here:

ESPHome code

switch:
  - platform: gpio
    name: “schakelaar keuken”
    pin:
      number: D11
    id: relay_keuken
    on_turn_on:
    - delay: 500ms
    - switch.turn_off: relay_keuken

binary_sensor:
  - platform: gpio
    name: “status keuken”
    pin:
      number: D6
      inverted: True
      mode:
        input: true
        pullup: true
    id: status_keuken
    device_class: light
    filters:
      - delayed_on: 20ms

Configuration.yaml code

switch:
  - platform: template
    switches:
      keuken:
        friendly_name: “Licht keuken”
        value_template: “{{ is_state( ‘binary_sensor.status_keuken’, ‘on’) }}”
        turn_on:
          service: switch.toggle
          target:
            entity_id: switch.schakelaar_keuken
        turn_off:
          service: switch.toggle
          target:
            entity_id: switch.schakelaar_keuken
        icon_template: >-
          {% if is_state(‘binary_sensor.status_keuken’, ‘on’) %}
            mdi:lightbulb-on-outline
          {% else %}
            mdi:lightbulb-outline
          {% endif %}