Newbie trying to setup light control based on cloud cover, time of day, and Lutron occupancy sensors

Good morning! I’m sort of with a goal to have different areas (kitchen, family room, hallway, stairs, etc.) turn on when various conditions are met. I’ve done some searching and haven’t found anything on point, but maybe someone out there has seen something similar for a newbie to tinker with… Staring at the automation screen drinking coffee has been unproductive.

  • Say it’s 11pm to sunrise, motion means lights in an area come on at 25%

  • Say it’s sunrise to sunset, motion means lights come on to 40% if cloud cover is 35% or less, but brighter like 60% if cloudcover is higher

  • Say sunset to 11pm, motion means lights come on to 70%

  • Then, the time to remain on once motion has not been detected would be like 10 mins

Any input to help point me in a solid direction is totally appreciated.

i would use multiple automation

- alias: Entrance motion light on before sunrise
  trigger:
    platform: state
    entity_id:
      - binary_sensor.motion_sensor_xxx
    to: 'on'
  condition:
    - condition: sun
      before: sunrise
  action:
    - service: light.turn_on
      target:
        entity_id: light.entrance
      data:
        brightness: 255

- alias: Entrance motion light on after sunset
  trigger:
    platform: state
    entity_id:
      - binary_sensor.motion_sensor_xxx
    to: 'on'
  condition:
    - condition: sun
      after: sunset
  action:
    - service: light.turn_on
      target:
        entity_id: light.entrance
      data:
        brightness: 255
        
- alias: Entrance no motion light off
  trigger:
    platform: state
    entity_id:
      - binary_sensor.motion_sensor_xxx
    to: 'off'
    for:
      minutes: 10
  action:
    - service: light.turn_off
      entity_id: light.entrance_light

before sunrise = midnight to runrise
after sunset = sunset to midnight
adjust bright to level you want max =255
Weather forecast for cloud cover wont be accurate, i would use luminance sensor in the motion sensor for that purpose. Look in the developer tools state to see you got any luminance sensor in those?

I agree with huu, cloud cover won’t be very accurate, but you can play with it by using OpenWeather integration if you like.

Here is my luminance automation, I use OR condition because i want the light to turn on regardless if it day time or night, as long as it dark. And when it night time it will turn on regardless if it bright or not to unaffected by nearby light and itself. Probably you can customize it for your weather condition, use AND if you want all condition met.

- alias: Entrance motion light on
  trigger:
    platform: state
    entity_id:
      - binary_sensor.motion_sensor_xxx
    to: 'on'
  condition:
    condition: or
    conditions:
      - condition: state
        entity_id: sun.sun
        state: "below_horizon"
      - condition: numeric_state
        entity_id: sensor.xxx_illuminance
        below: 800 
  action:
    - service: light.turn_on
      entity_id: light.entrance_light

Thank you @huu and @MickW69 for the input thus far.

Sadly, I have Lutron Caseta as the house’s smart light and sensor setup. Lutron’s sensor doesn’t include luminance. I was able to get the deCONZ Zigbee controller working and added some Aqara sensors using it for the water leaks and humidity readings. I’m trying to find a similar sensor to toss on that for light levels.

My wife would kill me if I put this gawdy thing up: Motion Sensor & Detector of Smart Home 2020 | Aqara

It seems Aqara made one for Xaomi - “Xiaomi Mijia Smart Light Sensor Detection Sensor Zigbee 3.0 Intelligent Linkage GZCGQ01LM Work With Mijia Smart Multimode Gateway.” Maybe it works? New device support request: Xiaomi Mijia Zigbee 3.0 Smart Home Light Sensor · Issue #2380 · dresden-elektronik/deconz-rest-plugin · GitHub

Any other small/compact/simple/wife-approved options out there that are better?

The aqara motion sensor you mention is small enough to be wife friendly (the diameter of the round part is about CR 2032 battery) but it also need a aqara hub so it an added cost. Since you are already in the Lutron ecosystem there is a “Lutron Daylight Sensor” you can use. Not sure about the size or if it will fit in to your existing setup or compatibility with HA.

note; The new aqara light sensor is not compatible with existing gateway. Need a newer “Smart Hub”

Yeah, so the Lutron sensor is part of a different ecosystem that isn’t connected smart home oriented. If aqara isn’t compatible with my setup, I may buy one of the Xaiomi’s to try out. It may just be that I go motion sensor only. I was trying to cut out electricity usage, albeit LEDs are low footprint, in rooms with lots of windows if it’s sunny out basically.

I ordered Hue sensors. Expensive but seems like the best option and won’t need the Hue hub from what I’ve read. Like everything else useful they are backordered so working on a solution with cloudcover for now.

How’s this look? (I think I got spacing correct but Google Docs is a real pain in the rear trying to correct me)

- id: '1899958999001'
  alias: 'Kitchen lights on with some cloud cover’
    trigger:
    platform: state
    entity_id:
      - binary_sensor.kitchen_occupancy
    to: on
    condition:
      condition: and
    conditions:
    - condition: numeric_state
      entity_id: sensor.openweathermap_cloud_coverage
      domain: sensor
      above: 20
      below: 50
    - condition: sun
      before: sunset
      before_offset: '-01:00:00'
    - condition: time
      after: '09:00'
  action:
    - service: light.turn_on
      target:
      entity_id: light.kitchen_main_lights
      data:
      brightness: 100 # 255 is max
    - service: light.turn_on
      target:
      entity_id: light.kitchen_under_cabinet
      data:
      brightness: 100 # 255 is max
  mode: single
- id: '1899958999002'
  alias: 'Kitchen lights off’
  trigger:
    platform: state
    entity_id:
      - binary_sensor.kitchen_occupancy
    to: 'off'
    for:
      minutes: 10
  action:
    - service: light.turn_off
      entity_id: light.kitchen_main_lights
    - service: light.turn_off
      entity_id: light.kitchen_under_cabinet

I guess technically the on should be occupied since it’s an occupancy sensor. Other than that, how bad off am I?

Read otherwise. ( occupancy: on means occupied, off means not occupied (clear)) So the above remains out to see how bad y’all think it is. Thanks a lot!

I tried running it though YAML Checker and it came out with an error. But, the error is something that is written the same way and copied from an automation with the GUI. Adding it via File Editor is coming up with the same error as well.

bad indentation of a mapping entry at line 172, column 23:
before_offset: ‘-01:00:00’
^

Just adjusting indentation. Your first “trigger:” outdent same level as “alias:”

light off'
lights off’
cloud cover'
cloud cover’
- id: '1899958999001'
  alias: 'Kitchen lights on with some cloud cover'
  trigger:
    platform: state
    entity_id:
      - binary_sensor.kitchen_occupancy
    to: on
    condition:
      condition: and
      conditions:
        - condition: numeric_state
          entity_id: sensor.openweathermap_cloud_coverage
          domain: sensor
          above: 20
          below: 50
        - condition: sun
          before: sunset
          before_offset: '-01:00:00'
        - condition: time
          after: '09:00'
  action:
    - service: light.turn_on
      target:
        entity_id: light.kitchen_main_lights
      data:
        brightness: 100
    - service: light.turn_on
      target:
        entity_id: light.kitchen_under_cabinet
      data:
        brightness: 100
      mode: single
      
- id: '1899958999002'
  alias: 'Kitchen lights off'
  trigger:
    platform: state
    entity_id:
      - binary_sensor.kitchen_occupancy
    to: 'off'
    for:
      minutes: 10
  action:
    - service: light.turn_off
      entity_id: light.kitchen_main_lights
    - service: light.turn_off
      entity_id: light.kitchen_under_cabinet

Try Notepad++

Just curious, what the purpose “domain: sensor” and “mode: single”

@huu thank you! It didn’t kick back an error so let’s see how it works out today. :slight_smile:

In re domain and mode, I just saw those in my original automations and thought they were necessary. I assume they are meaningless by your question? lol

oh not sure if ‘09:00’ need to be 09:00:00

Working on the rest of my kitchen schema to cover 24 hours. I’m not sure how the late night and morning one’s look. I say this because the after/before times are on different days?

- id: '1899958999005'
  alias: 'Kitchen lights evening time'
  trigger:
    platform: state
    entity_id:
      - binary_sensor.kitchen_occupancy
    to: on
    condition:
      condition: and
      conditions:
        - condition: sun
          after: sunset
          after_offset: '-01:00:00'
        - condition: time
          before: '22:30'
  action:
    - service: light.turn_on
      target:
        entity_id: light.kitchen_main_lights
      data:
        brightness: 85
    - service: light.turn_on
      target:
        entity_id: light.kitchen_under_cabinet
      data:
        brightness: 80
      mode: single

- id: '1899958999006'
  alias: 'Kitchen lights late night'
  trigger:
    platform: state
    entity_id:
      - binary_sensor.kitchen_occupancy
    to: on
    condition:
      - condition: time
        after: '10:30'
        before: '06:00'
  action:
    - service: light.turn_on
      target:
        entity_id: light.kitchen_main_lights
      data:
        brightness: 85
    - service: light.turn_on
      target:
        entity_id: light.kitchen_under_cabinet
      data:
        brightness: 80
      mode: single

- id: '1899958999007'
  alias: 'Kitchen lights morning'
  trigger:
    platform: state
    entity_id:
      - binary_sensor.kitchen_occupancy
    to: on
    condition:
      - condition: time
        after: '06:00'
        before: '09:00'
  action:
    - service: light.turn_on
      target:
        entity_id: light.kitchen_main_lights
      data:
        brightness: 85
    - service: light.turn_on
      target:
        entity_id: light.kitchen_under_cabinet
      data:
        brightness: 80
      mode: single

Yes it can span across day, but you late night suppose to be after 22:30:00 (not 10:30?) before 06:00:00 = 10:30pm to 6am next day.

And your everning time… after sunset (=6pm to midnight) and before 22:30;00 (=10:30pm to midnite) since it an AND condition it would only true between 10:30pm to midnight (eg if sunset at 6pm)

After 6am before 9am will be only between 3 hours 6 - 9 am on that same fay

Scroll down to “ time conditions “ section here for a good explanation of before and after conditions

Great catch on my error on the 1030/2030! Thank you. Fixed that.

I reviewed the link you provided and, to my novice eyes, the condition for 1 hour before sunset until 2230 seems to look correct. Am I missing something? The objective is to use the brightness level set for motion for the evening hours starting an hour before sunset because it’s quite dark at that point inside the house.

    condition:
      condition: and
      conditions:
        - condition: sun
          after: sunset
          after_offset: '-01:00:00'
        - condition: time
          before: '22:30'

Hmm reading that again i think the before 22:30:00 means from midnight to 22:30 ie it span the whole day time… this section


Note that if only before key is used, the condition will be true from midnight until the specified time.
If only after key is used, the condition will be true from the specified time until midnight

right?

Ah, so maybe add an after just to hold it, and the sunset is always going to be later so it controls?

    condition:
      condition: and
      conditions:
        - condition: sun
          after: sunset
          after_offset: '-01:00:00'
        - condition: time
          after: '16:00'
          before: '22:30'

I was looking at it like this: an AND condition is used, so if the time constraint is out of bounds with sunset then it won’t turn on and is rendered false to continue to the action.

yes when AND is use then only true when both are over lap in tis case sunset to 10:30pm

Well this is fun. I added all that jazz in and now I get this message:

2021-08-16 10:49:20 ERROR (MainThread) [homeassistant.config] Invalid config for [automation]: [mode] is an invalid option for [automation]. Check: automation->action->1->mode. (See /config/configuration.yaml, line 9).

Line 9 is: group: !include groups.yaml

groups.yaml is blank.

My entire automation yaml is:

- id: '1628687582995'
  alias: Close Velux shades if too hot 89F
  description: ''
  trigger:
  - type: temperature
    platform: device
    device_id: 45a6ae64e81ca2ca86450430756e47f8
    entity_id: sensor.openweathermap_temperature
    domain: sensor
    above: 88
    below: 200
    for:
      hours: 0
      minutes: 10
      seconds: 0
      milliseconds: 0
  condition:
  - condition: time
    after: '10:00'
    before: '16:45'
  - condition: sun
    before: sunset
    before_offset: -02:00:00
  action:
  - device_id: 6e376a903f839357f22bd95fddfec877
    domain: cover
    entity_id: cover.velux_left
    type: set_position
    position: 50
  - device_id: 60693a2a7d78a5b42abd34fa7988ff1f
    domain: cover
    entity_id: cover.velux_right_2
    type: set_position
    position: 52
  mode: single
- id: '1628687689731'
  alias: Keep Velux Shades open if 25-86F
  description: ''
  trigger:
  - type: temperature
    platform: device
    device_id: 52a7c56c24bf78a8eba58757bac2625e
    entity_id: sensor.temperature_14
    domain: sensor
    above: 25
    below: 86
  condition:
  - condition: sun
    before: sunset
    before_offset: -00:15:00
  - condition: time
    after: '11:00'
    before: '19:00'
  action:
  - device_id: 6e376a903f839357f22bd95fddfec877
    domain: cover
    entity_id: cover.velux_left
    type: set_position
    position: 100
  - device_id: 60693a2a7d78a5b42abd34fa7988ff1f
    domain: cover
    entity_id: cover.velux_right_2
    type: set_position
    position: 100
  mode: single
- id: '1628687741304'
  alias: Morning open velux shades
  description: ''
  trigger:
  - platform: sun
    event: sunrise
    offset: -00:10:00
  condition: []
  action:
  - device_id: 6e376a903f839357f22bd95fddfec877
    domain: cover
    entity_id: cover.velux_left
    type: set_position
    position: 100
  - device_id: 60693a2a7d78a5b42abd34fa7988ff1f
    domain: cover
    entity_id: cover.velux_right_2
    type: set_position
    position: 100
  mode: single
- id: '1628687781331'
  alias: Nightly Close velux shades
  description: ''
  trigger:
  - platform: sun
    event: sunset
    offset: +01:00:00
  condition: []
  action:
  - device_id: 6e376a903f839357f22bd95fddfec877
    domain: cover
    entity_id: cover.velux_left
    type: set_position
  - device_id: 60693a2a7d78a5b42abd34fa7988ff1f
    domain: cover
    entity_id: cover.velux_right_2
    type: set_position
  mode: single
- id: '1692801842292'
  alias: Master Bath Hygrostat On
  trigger:
    platform: state
    entity_id: binary_sensor.bathroom_hygrostat
    to: 'on'
  action:
  - service: switch.turn_on
    entity_id: switch.mast_bath_dehumidifier
- id: '1692801842293'
  alias: Master Bath Hygrostat Off
  trigger:
    platform: state
    entity_id: binary_sensor.bathroom_hygrostat
    to: 'off'
  action:
  - service: switch.turn_off
    entity_id: switch.mast_bath_dehumidifier
- id: '1628851499528'
  alias: 'Close Garage Door if Phones Are NOT Home'
  description: ''
  trigger:
  - platform: device
    device_id: 3388b53564883d13ea40679464a714a5
    domain: cover
    entity_id: cover.garage_door
    type: opened
    for:
      hours: 0
      minutes: 30
      seconds: 0
      milliseconds: 0
  condition:
  - condition: and
    conditions:
    - condition: device
      device_id: b3537ca6e6de81866dad95f9a3e4bf2c
      domain: device_tracker
      entity_id: device_tracker.pixel_5
      type: is_not_home
    - condition: device
      device_id: f05b8bb0f7b5f1d39e70ddc602b08f7a
      domain: device_tracker
      entity_id: device_tracker.pixel_5_gaby
      type: is_not_home
  action:
  - device_id: 3388b53564883d13ea40679464a714a5
    domain: cover
    entity_id: cover.garage_door
    type: close
  mode: single


- id: '1899958999001'
  alias: 'Kitchen lights on with some cloud cover'
  trigger:
    platform: state
    entity_id:
      - binary_sensor.kitchen_occupancy
    to: on
    condition:
      condition: and
      conditions:
        - condition: numeric_state
          entity_id: sensor.openweathermap_cloud_coverage
          domain: sensor
          above: 20
          below: 49
        - condition: sun
          before: sunset
          before_offset: '-01:00:00'
        - condition: time
          after: '09:00'
  action:
    - service: light.turn_on
      target:
        entity_id: light.kitchen_main_lights
      data:
        brightness: 35
    - service: light.turn_on
      target:
        entity_id: light.kitchen_under_cabinet
      data:
        brightness: 60
      mode: single
      
- id: '1899958999002'
  alias: 'Kitchen lights off'
  trigger:
    platform: state
    entity_id:
      - binary_sensor.kitchen_occupancy
    to: 'off'
    for:
      minutes: 5
  action:
    - service: light.turn_off
      entity_id: light.kitchen_main_lights
    - service: light.turn_off
      entity_id: light.kitchen_under_cabinet
      
      
      
- id: '1899958999003'
  alias: 'Kitchen lights on with lots of cloud cover'
  trigger:
    platform: state
    entity_id:
      - binary_sensor.kitchen_occupancy
    to: on
    condition:
      condition: and
      conditions:
        - condition: numeric_state
          entity_id: sensor.openweathermap_cloud_coverage
          domain: sensor
          above: 49
        - condition: sun
          before: sunset
          before_offset: '-01:00:00'
        - condition: time
          after: '09:00'
  action:
    - service: light.turn_on
      target:
        entity_id: light.kitchen_main_lights
      data:
        brightness: 45
    - service: light.turn_on
      target:
        entity_id: light.kitchen_under_cabinet
      data:
        brightness: 70
      mode: single
      
      
- id: '1899958999004'
  alias: 'Kitchen lights on with no cloud cover'
  trigger:
    platform: state
    entity_id:
      - binary_sensor.kitchen_occupancy
    to: on
    condition:
      condition: and
      conditions:
        - condition: numeric_state
          entity_id: sensor.openweathermap_cloud_coverage
          domain: sensor
          below: 20
        - condition: sun
          before: sunset
          before_offset: '-01:00:00'
        - condition: time
          after: '09:00'
  action:
    - service: light.turn_on
      target:
        entity_id: light.kitchen_main_lights
      data:
        brightness: 30
    - service: light.turn_on
      target:
        entity_id: light.kitchen_under_cabinet
      data:
        brightness: 30
      mode: single      


- id: '1899958999005'
  alias: 'Kitchen lights evening time'
  trigger:
    platform: state
    entity_id:
      - binary_sensor.kitchen_occupancy
    to: on
    condition:
      condition: and
      conditions:
        - condition: sun
          after: sunset
          after_offset: '-01:00:00'
        - condition: time
          before: '22:30'
  action:
    - service: light.turn_on
      target:
        entity_id: light.kitchen_main_lights
      data:
        brightness: 80
    - service: light.turn_on
      target:
        entity_id: light.kitchen_under_cabinet
      data:
        brightness: 85
      mode: single


- id: '1899958999006'
  alias: 'Kitchen lights late night'
  trigger:
    platform: state
    entity_id:
      - binary_sensor.kitchen_occupancy
    to: on
    condition:
      - condition: time
        after: '20:30'
        before: '06:00'
  action:
    - service: light.turn_on
      target:
        entity_id: light.kitchen_main_lights
      data:
        brightness: 20
    - service: light.turn_on
      target:
        entity_id: light.kitchen_under_cabinet
      data:
        brightness: 50
      mode: single


- id: '1899958999007'
  alias: 'Kitchen lights morning'
  trigger:
    platform: state
    entity_id:
      - binary_sensor.kitchen_occupancy
    to: on
    condition:
      - condition: time
        after: '06:00'
        before: '09:00'
  action:
    - service: light.turn_on
      target:
        entity_id: light.kitchen_main_lights
      data:
        brightness: 60
    - service: light.turn_on
      target:
        entity_id: light.kitchen_under_cabinet
      data:
        brightness: 80
      mode: single