Change Lights and Switches


In YAML files tabs are very important, always check indentation

Prerequisites:

Change from Lights to Switches

In your Esphome config find the following (or any out_XY you’d like to change): In this example we’d change Light02 to Switch02.

light:
  - platform: binary
    name: 'Light 01'
    output: out_01
    id: light_01
  - platform: binary
    name: 'Light 02'
    output: out_02
    id: light_02

Remove this section:

- platform: binary
  name: 'Light 02'
  output: out_02
  id: light_02

Now add switch section to your config (in the bottom for example):

switch:

Add switch

Under switch section add output:

- platform: output
  name: 'Switch 02'
  output: out_02
  id: switch_02

In the end it would look like:

switch:
  - platform: output
    name: 'Switch 02'
    output: out_02
    id: switch_02

Change Input behaviour for Light

Now config propably won’t compile as input would try to switch Light02. Let’s change it.

Find Input which toggles your light:

- platform: gpio
  name: 'IN_02'
  id: in_02
  pin:
    pcf8574: pcf_inputs_1to14
    number: 1
    mode:
      input: true
    inverted: true
  on_press:
    then:
      - light.toggle: light_02

Either remove lines:

on_press:
  then:
    - light.toggle: light_02

or change them to toggle switch:

on_press:
  then:
    - switch.toggle: light_02

Change from Switches to Lights

In your Esphome config find the following (or any out_XY you’d like to change): In this example we’d change Switch02 to Light02 .

switch:
  - platform: output
    name: 'Switch 01'
    output: out_01
    id: switch_01
  - platform: output
    name: 'Switch 02'
    output: out_02
    id: switch_02

Remove this section:

- platform: output
  name: 'Switch 02'
  output: out_02
  id: switch_02

Now add lights section to your config (in the bottom for example):

light:

Add light

Under light section add output:

- platform: binary
  name: 'Light 02'
  output: out_02
  id: light_02

In the end it would look like:

light:
  - platform: binary
    name: 'Light 02'
    output: out_02
    id: light_02

Change Input behaviour for Switch

Now config propably won’t compile as input would try to switch Switch02. Let’s change it.

Find Input which toggles your switch:

- platform: gpio
  name: 'IN_02'
  id: in_02
  pin:
    pcf8574: pcf_inputs_1to14
    number: 1
    mode:
      input: true
    inverted: true
  on_press:
    then:
      - switch.toggle: switch_02

Either remove lines:

on_press:
  then:
    - switch.toggle: switch_02

or change them to toggle light:

on_press:
  then:
    - light.toggle: light_02