ESP Home - Need help understanding what the sensor does

I have used the ESPHome example YAML for a SonOff Mini R4 Extreme and have it working as below in Home Assistant.

The sensor appears to always read as off. Compare above with below,
image

However, when I click on S1 it appears that the state does change, it just does not indicate it in the text.

Given that the reply shows on or off, what is the point of the sensor?

substitutions:
  device_name: smartswitch-front-door

esphome:
  name: ${device_name}

esp32:
  board: esp32dev
  framework:
    type: arduino

# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: !secret ekey-sw-frontdoor

ota:
  - platform: esphome
    password: !secret ota-sw-frontdoor

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

sensor:
  - platform: wifi_signal
    name: ${device_name} Wifi Signal Strength
    update_interval: 90s
    entity_category: "diagnostic"

  - platform: uptime
    name: ${device_name} Uptime
    update_interval: 300s
    entity_category: "diagnostic"

text_sensor:
  - platform: wifi_info
    ssid:
      name: Connected SSID
    ip_address:
      name: IP Address
    dns_address:
      name: DNS Address


esp32_ble_tracker:
  scan_parameters:
#    interval: 1100ms
#    window: 1100ms
    active: true

bluetooth_proxy:
  active: true

#######################################
# Device specific Config Begins Below #
#######################################

status_led:
  pin:
    number: GPIO19
    inverted: true

output:
  # Physical relay on GPIO
  - platform: gpio
    pin: GPIO26
    id: relay_1

light:
  - platform: binary
    id: light_1
    name: ${device_name}
    icon: mdi:ceiling-light-multiple-outline
    restore_mode: restore_default_off
    output: relay_1

binary_sensor:
  - platform: gpio
    pin: GPIO00
    id: button
    filters:
      - invert:
      - delayed_off: 50ms
    on_press:
      - light.toggle:
          id: light_1

  - platform: gpio
    name: s1
    pin: GPIO27
    id: s1
    filters:
      - invert:
      - delayed_off: 50ms
    on_press:
      then:
        - light.turn_on:
            id: light_1
    on_release:
      then:
        - light.turn_off:
            id: light_1

If not really necessary, how do I remove it and if it is necessary how do I get the text to change to reflect the switch state?

Hi, do you have S1 wired on the SonOff Mini R4 Extreme?
image

1 Like

Hi

S1 is an external switch you can connect to the terminals marked S1 and S2 on the device, the sensor just tells you if it is activated or not. It is meant so that you can connect an external switch so you can control the device manually. If you don’t need it you can take that bit of config out altogether out of your YAML. You could also change the name to something more meaningful e.g ‘External Switch’

You could also hide it by adding Internal as True

  - platform: gpio
    name: s1
    internal: True
    pin: GPIO27
    id: s1
    filters:
      - invert:
      - delayed_off: 50ms
    on_press:
      then:
        - light.turn_on:
            id: light_1
    on_release:
      then:
        - light.turn_off:
            id: light_1

Agh yes, that makes sense… the sensor is for the physical connection :slight_smile:

I was testing without it being wired in so forgot about that.

Thanks for that.

On a side note, the LED on the unit does not come on or off but given that it will be in the wall, that is not an issue.

It is down as a status LED see the docs here, so off is good. You could change it to do something else but as you say it is in a wall.