ESP8266 code to use pins D4 & D8 as switch

Hi. I have setup an ESP 8266 to read temp and humidity and control a single relay. I was successful with a single relay. I am trying to use Home assistant to code an ESP8266 to control a 2nd relay. The relays are using Pins D4 & D8. I want to know what code should be added to control the second relay.
My code looks like this currently but am getting errors when I try to validate it.
‘’’
sensor:

  • platform: dht
    pin: D2
    temperature:
    name: “Living Room Temperature”
    humidity:
    name: “Living Room Humidity”
    update_interval: 5s

switch:

  • platform: gpio
    name: “Living Room Lights”
    pin: D4

switch:

  • platform: gpio
    name: “Awning Lights”
    pin: D8
    ‘’’
    Please could someone assist me with this problem.

Thanks

Hi and welcome to the forum. Please have a read of point 11 here then edit your post accordingly: How to help us help you - or How to ask a good question

What error?

You only need one switch:, just list them both below one of the:

switch:
  - platform: gpio
    name: Living Room Lights
    pin: D4

  - platform: gpio
    name: Awning Lights
    pin: D8

Hi
I tried that but when I validate it there are errors.
I am will try to post the error here

Try formatting your code, it should look like this:

sensor:
  - platform: dht
    pin: D2
    temperature:
      name: "Living Room Temperature"
    humidity:
      name: "Living Room Humidity"
    update_interval: 5s

switch:
  - platform: gpio
    name: Living Room Lights
    pin: D4

  - platform: gpio
    name: Awning Lights
    pin: D8

Hi. Your code works. The issue was the inverted commas in the name. I copied your code and pasted and see that there are no inverted commas.

Thank a million. You are a star.

really appreciate it.

You might want to reconsider your choice of D8.

1 Like

Thanks for the info,
best regards