Light brightness between certain hours

I have following binary sensor controlling a HA service to toggle a light:

  - platform: gpio
    name: "2e Kinderkamer"
    device_class: light
    pin:
      number: GPIO13
      inverted: True
      mode: INPUT_PULLUP
    filters:
      -  delayed_on: 50ms
      -  delayed_off: 50ms
    on_press:
      then:
        - homeassistant.service:
            service: light.toggle
            data:
              entity_id: light.wout

Now i would like this light to turn on to a certain brightness when the time is between certain hours at night. But i’m clueless how i could implement this with esphome.
I can always do a HA automation but would prefer it in esphome!

See the examples on this page:

I read that doc., problem is i’m no good automations and lambda’s.

Anyway i came up with this peiced together from other community threads:

  - platform: gpio
    name: "2e Kinderkamer"
    device_class: light
    pin:
      number: GPIO13
      inverted: True
      mode: INPUT_PULLUP
    filters:
      -  delayed_on: 50ms
      -  delayed_off: 50ms
    on_press:
      then:
        - if:
           condition:
             - lambda: 'return id(ha_time).now().hour > 21;'
           then:
             homeassistant.service:
               service: light.toggle
               data:
                 entity_id: light.wout
                 brightness: "30"
        - if:
           condition:
             - lambda: 'return id(ha_time).now().hour < 12;'
           then:
             homeassistant.service:
               service: light.toggle
               data:
                 entity_id: light.wout
                 brightness: "30"
                 
    on_double_click:
      min_length: 50ms
      max_length: 350ms
      then:
        - homeassistant.service:
            service: light.turn_on
            data:
              entity_id: light.wout

The time based brightness seems to work , just need to test a bit still if the double click to 100% brightness works as intended.

and edited to the following to include else statement:

    on_press:
      then:
        if:
          condition:
            or:
              - lambda: 'return id(ha_time).now().hour > 21;'
              - lambda: 'return id(ha_time).now().hour < 7;'
          then:
            homeassistant.service:
              service: light.toggle
              data:
                entity_id: light.wout
                brightness: "30"
          else:
            homeassistant.service:
              service: light.toggle
              data:
                entity_id: light.wout
                 
    on_double_click:
      min_length: 50ms
      max_length: 350ms
      then:
        - homeassistant.service:
            service: light.turn_on
            data:
              entity_id: light.wout
3 Likes