Shelly 2 with build-in timer

I use a Shelly 2.5 to control my two bedside lights. In the config of esp home I’d like to hardcode a timer for the amount of time the light are allowed to be on, independent from HA.

Everything works like a charm but I can’t seem to find a solution for this. I’m using regular switches that toggle the light if used.

You’d make an ESPHome automation and use a delay: Automations and Templates — ESPHome.

Thanks for your answer @parautenbach but I just can’t understand the code. I am using a regular switch and because of that a just can’t “toggle” the light whenever the switch is used, use a delay, and toggle it again. Maybe I am wrong here but isn’t this also being triggered when the light is turned on via the dashboard.

Let’s assume that the light is on. If I use the switch, the light will toggle and turn off. Be off for the time of the delay and toggle back on. Am I correct?

I was searching for a way to check if the light is on, or in my case, the relay is closed. Then start the delay and then switch it off. In that case the delay isn’t used when the relay is open.

I don’t want to be a prick, I just can’t get my head around this code. I must admit I haven’t tried the code you pointed towards. Maybe I’ll try it. I’ll let you know.

Is your switch connected to the Shelly’s switch connection or connected inline before (plug to Shelly) or after (Shelly to device) the Shelly?

It’s connected to the Shelly’s L and SW1 connections. The light is connected though a bridge connection shared with the N connection and the O1 on the Shelly.

Ok, good.

Can you share your ESPHome config (being mindful of redacting sensitive info)?

# basic configuration

# Basic Config
substitutions:
  devicename: bedlampjes-ls

esphome:
  name: ${devicename}
  platform: ESP8266
  board: esp01_1m

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  power_save_mode: HIGH # for ESP8266 LOW/HIGH are mixed up, esphome/issues/issues/1532
  ap:
    ssid: "$devicename AP"
    password: !secret wifi_password
    
captive_portal:

# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: "blurred"
    
ota:

web_server:
  port: 80

i2c:
  sda: GPIO12
  scl: GPIO14

sensor:
  - platform: ade7953_i2c
    irq_pin: GPIO16 # Prevent overheating by setting this
    voltage:
      name: ${devicename} Voltage
    # On the Shelly 2.5 channels are mixed ch1=B ch2=A
    current_a:
      name: ${devicename} Current B
    current_b:
      name: ${devicename} Current A
    active_power_a:
      name: ${devicename} Active Power B
      # active_power_a is normal, so don't multiply by -1
    active_power_b:
      name: ${devicename} Active Power A
      # active_power_b is inverted, so take the absolute value
      filters:
        - lambda: return abs(x);
    update_interval: 60s

  # NTC Temperature
  - platform: ntc
    sensor: temp_resistance_reading
    name: ${devicename} Temperature
    unit_of_measurement: "°C"
    accuracy_decimals: 1
    icon: "mdi:thermometer"
    calibration:
      b_constant: 3350
      reference_resistance: 10kOhm
      reference_temperature: 298.15K
  - platform: resistance
    id: temp_resistance_reading
    sensor: temp_analog_reading
    configuration: DOWNSTREAM
    resistor: 32kOhm
  - platform: adc
    id: temp_analog_reading
    pin: A0

status_led:
  pin:
    number: GPIO0
    inverted: yes

output:
  - platform: gpio
    pin: GPIO4
    id: shelly_25_relay_1
  - platform: gpio
    pin: GPIO15
    id: shelly_25_relay_2

light:
  - platform: binary
    name: "${devicename} Light 1"
    output: shelly_25_relay_1
    id: lightid1
  - platform: binary
    name: "${devicename} Light 2"
    output: shelly_25_relay_2
    id: lightid2

binary_sensor:
  - platform: gpio
    pin:
      number: GPIO13
      #mode: INPUT_PULLUP
      #inverted: True
    name: "${devicename} Switch 1"
    on_state:
      then:
        - light.toggle: lightid1
    internal: true
    id: switchid1
  - platform: gpio
    pin:
      number: GPIO5
      #mode: INPUT_PULLUP
      #inverted: True
    name: "${devicename} Switch 2"
    on_state:
      then:
        - light.toggle: lightid2
    internal: true
    id: switchid2here

I see I never answered you.

light:
  - platform: binary
    name: "${devicename} Light 1"
    output: shelly_25_relay_1
    id: lightid1
    on_turn_on:
      - delay: 60s  # for example
      - light.turn_off: lightid1

Light Component — ESPHome