#A time-based automation with brightness changing multiple times

1 messages · Page 1 of 1 (latest)

kindred cedar
#

I'm trying to make an automation for all my lights, based on time of day and the brightness outside. In the night (23:00 to 5:00) i obviously want it to be dim, say 10%. In the morning (5:00 to 7:00) 20%. From 7:00 till 10:00 30%. from 10:00 till 18:00 70%. from 18:00 till 20:00 30%. from 20:00 till 22:00 20%. These changes should not affect whether the light is on or not.

  1. How would you approach this? Whenever i click into automations i feel a bit overwhelmed with all the options and i'm sure i'm not doing it the best way (right now i have one automation for each time period and i change brightness by toggling and directly after toggling again, changing the brightness).

I would also like to throw in some brightness from outside, since im from Denmark and the outside brightness changes very much throughout a year (in summer, sunrise could be at 5:00, then i don't need the lights to be at 10%. On the other hand at winter, sunrise could be at 12:00).- I got Aqara motion detectors in every room and i can see they have a lux value.
2. If i use a motion detector that also controls a light in the same room, as a state/variable (insert correct name) for what percentage to turn the lights on at, wouldn't the automation be affected by the "wrong" reading by the motion sensor, when the lights are turned on and it's suddenly very bright? Will i need a separate (motion) sensor to only point out of the window, so i get a correct reading of the brightness outside?

broken wyvern
#

So my preferred method for doing this is using either the schedule helper (https://www.home-assistant.io/integrations/schedule/) or the schedule state custom integration if I want to be fancy (https://github.com/aneeshd/schedule_state) - both let you assign values to time slots fairly easily, but schedule state lets you play around with templated values, conditional time periods etc.
These are both nice because it means you only need one automation to set your brightness, you just look for the schedule (state) entity to change state, and then set the brightness to whatever the stored brightness is.

Having a separate brightness sensor can be useful, but for this it's not actually perfect - for example I could imagine in summer where it's bright outside, you might have curtains pulled making it quite dark indoors still.
What you can do is use a template sensor pointing at your brightness sensor, but only update it when the lights in the room are off - something like: {{ states('sensor.living_room_brightness') if is_state('light.living_room', 'off') else this.state }} - here "this.state" just returns the current value of the template sensor whenever the lights are on, which should be the last measurement the brightness sensor before the lights turned on

kindred cedar
#

Thank you! Can you either post a picture of an example of your method - or maybe point me in the direction of a video telling me more about how to use the schedule helper and the schedule state custom integration?

broken wyvern
#

So as a very basic example for schedule state that would do your original ask:

- platform: schedule_state
  name: light_brightness_schedule
  default_state: 100
  events:
    - start: "23:00"
      end: "5:00"
      state: 10
      allow_wrap: True
    - start: "5:00"
      end: "23:00"
      state: 20
    - start: "7:00"
      end: "20:00"
      state: 30
    - start: "10:00"
      end: "18:00"
      state: "{{ [70, some_value_calculated_from(states('sensor.living_room_lights_off_brightness') | float)] | min }}"

You can make it return the value of input_numbers if you want to dynamically control the brightness in each timeslot, later timeslots override earlier ones, so although it is returning 30 from 7:00 to 20:00, that gets overwritten by that template between 10:00 and 18:00

You then have an automation that just has trigger: state change on sensor.light_brightness_schedule (not_to unknown/unavailable) and action: set light brightness = states(sensor.light_brightness_schedule) | int

Alternatively, you could ignore all of this and use Adaptive Lighting - https://github.com/basnijholt/adaptive-lighting

kindred cedar
#

That is very interesting! I've taken a look at adaptive lighting and will give it a try, but i think i want more granular control of the brightness and color. Where do i put the YAML code? Just in the configuration.yaml file? I've never done any actual coding, it has all been in the GUI

broken wyvern
#

ah ok, yeah it needs to go in the configuration.yaml under the sensors: section

#

the downside to schedule_state is no pretty UI to edit it

#

there's scheduler as well, but I haven't used that. it seems popular and has a UI though