PIR activated Light brightness between certain hours

Would appreciate any help for this novice esphome user. Having trouble getting the below config to work to:

Turn on light full brightness between 5am & 7am and between 4pm & 9pm.

Turn on light 20% brightness between 9pm & 5am.

Off all other times.

Appreciate any tips :slight_smile:


esphome:
  name: smart-toilet
  friendly_name: Toilet Light
  platform: ESP8266
  board: d1_mini
  on_boot:
    priority: 600
    # turn on the light when powered on
    then:
      - light.turn_on:
          id: toilet_light
          brightness: 100%
          red: 100%
          green: 70%
          blue: 45%

# Enable logging
logger:

# Enable Home Assistant API
api:

# Enable over the air updates
ota:
  platform: esphome

wifi:
  networks:
    - ssid: !secret 1_wifi_ssid
      password: !secret 1_wifi_password
    - ssid: !secret 2_wifi_ssid
      password: !secret 2_wifi_password
      manual_ip:
        static_ip: 192.168.0.231**strong text**
        gateway: 192.168.0.1
        subnet: 255.255.255.0

preferences:
  flash_write_interval: "48h"

time:
  - platform: sntp
    id: toilet_time
  
sensor:
  - platform: uptime
    name: "toilet light"  

  - platform: dht
    pin: D2 
    temperature:
      name: "Shower Vent Temperature"
    humidity:
      name: "Shower Vent Humidity"
    update_interval: 10s
    model: AM2302 

  - platform: wifi_signal # Reports the WiFi signal strength/RSSI in dB
    name: "Toilet WiFi"
    id: wifi_signal_db
    update_interval: 60s
    entity_category: "diagnostic"
    
binary_sensor:
  - platform: gpio
    pin:
      number: D5
    name: "PIR Toilet"
    id: toilet_pir
    device_class: motion
    filters: 
      - delayed_on: 100ms
    on_press: 
      then:
        - if: 
            condition:
              or:
                - lambda: 'return id(toilet_time).now().hour >= 5 && id(toilet_time).now().hour < 8;'
                - lambda: 'return id(toilet_time).now().hour >= 16 && id(toilet_time).now().hour < 21;'
            then: 
              - light.turn_on: 
                  id: toilet_light
                  brightness: 100%
                  transition_length: 0.5s
        - if:
            condition:
              - lambda: 'return id(toilet_time).now().hour >= 21 && id(toilet_time).now().hour < 5;'
            then:
              - light.turn_on: 
                  id: toilet_light
                  brightness: 20%
                  transition_length: 0.5s

switch:
  - platform: restart
    name: "Toilet Light Reboot"

light:
  - platform: neopixelbus
    type: GRB
    variant: WS2812X
    pin: GPIO3
    num_leds: 20
    name: "Toilet Light"
    id: toilet_light
    restore_mode: ALWAYS_ON
    default_transition_length: 10ms
    on_turn_on: 
      then:
        - delay: 
            minutes: 2
        - light.turn_off: toilet_light

How could hour be >21 and <5?
or might work better.
Not 100% sure, but I expect that hour is treated just as a number.

1 Like

Have you looked at Blackies blueprint “Sensor Light” - it’s really powerful, does what you want and more. I use it in our main bathroom, hallway and pantry.

Hallway varies/switches by LUX, and 3x motion sensors, plus difference brightnesses and lamps for time variable. Bathroom varies by time, triggers by motion+presence sensors. Pantry is always the same, triggered by motion only.

Al have wirless bypass buttons on the wall too.

There is heaps of cool options built into it.

1 Like

Thanks mate,

that’s done the trick! Such a “simple” one but just needed someones sound logic… lol

Cheers