SOLVED: ESPHome in Sonoff - register relay as a light in HA?

I have a Sonoff Basic with ESPHome in it, that I’m using to control a light. In HA it’s registered as a switch, is there a way to have it register as a light instead?

My current config looks like this:

esphome:
  name: gang
  platform: ESP8266
  board: esp01_1m

wifi:
  ssid: SSID
  password: NotShown

api:

logger:
  baud_rate: 0

ota:
  password: "VerySecret"

time:
  - platform: homeassistant
    id: homeassistant_time

text_sensor:
  - platform: version
    name: "Gang ESPHome Version"
  - platform: wifi_info
    ip_address:
      name: "Gang ip"
    ssid:
      name: "Gang ssid"

binary_sensor:
  - platform: gpio
    pin:
      number: GPIO0
      mode: INPUT_PULLUP
      inverted: True
    name: "Gang Sonoffc Button"
    on_press:
      - switch.toggle: relay

switch:
  - platform: gpio
    name: "Gang"
    pin: GPIO12
    id: relay

status_led:
  pin:
    number: GPIO13
    inverted: yes

But it is a switch and not a light. Lights generally have colour and dim capabilities, switches are on and off.
You can change the icon of the identity so it is more recognizable if you want.

1 Like

You can use the Light Switch in HA, but it’s one more entity.

1 Like

Would this work ?

1 Like

Thankyou all three for the input!

I think that would work, then I just need to figure out the output part, I can’t seem to get the syntax correct here :blush:
For now I’ve set it up with a lightswitch in HA, as per @VDRainer’s suggestion.

Let me google that for you

2 Likes

Thankyou for the googling expertise :smile:

So, the resulting config is:

substitutions:
  device_name: hallway
  # Higher value gives lower watt readout
  current_res: '0.00290'
  # Lower value gives lower voltage readout
  voltage_div: '940'

esphome:
  name: '${device_name}'
  platform: ESP8266
  board: esp01_1m

wifi:
  ssid: SSID
  password: PASSWORD

api:

logger:
  baud_rate: 0

ota:
  password: "PASSWORD"

time:
  - platform: homeassistant
    id: homeassistant_time

text_sensor:
  - platform: version
    name: '${device_name} ESPHome Version'
  - platform: wifi_info
    ip_address:
      name: '${device_name} ip'
    ssid:
      name: '${device_name} ssid'

binary_sensor:
  - platform: gpio
    pin:
      number: GPIO0
      mode: INPUT_PULLUP
      inverted: True
    name: '${device_name} Button'
    on_press:
      - light.toggle: lightbar

output:
  - platform: gpio
    id: relay
    pin: GPIO12

light:
  - platform: binary
    id: lightbar
    name: '${device_name}'
    output: relay
    

status_led:
  pin:
    number: GPIO13
    inverted: yes

sensor:
  - platform: uptime
    name: '${device_name} Uptime'
    unit_of_measurement: days
    update_interval: 300s
    accuracy_decimals: 1
    filters:
      - multiply: 0.000011574

  - platform: wifi_signal
    name: '${device_name} WiFi Signal'
    accuracy_decimals: 0
    update_interval: 300s

I can see that in the example the !secret method is used, but if I try that, it will not compile, so is that not through ESPHome?

2 Likes

Secrets is a method to store passwords and alike in another file.
secrets.yaml

1 Like

Yes, I’m using it already in my normal configs, but when I use it in ESPHome I get errors marked?

If you want to use secrets.yaml in ESPHome you have to create another secrets.yaml file next to your normal configuration files. If you are on hassio I don’t know if it is supported on the dash board directly or you have to put the file with another means like the configurator add on.

1 Like

A symlink should work if you want to keep all your secrets in one place.

1 Like

It doesn’t look like it, which is a bummer, I really want to keep it in Hass.io, trying to keep it manageble, at least somewhat, by others than just me.
@nickrout , ok, that would make it much cleaner, if just the editor supported it :thinking:

It’s coming https://github.com/esphome/esphome/pull/672

1 Like

@glmnet Sounds great :slight_smile: