Pretty complex light automation

This is my light automation, that got quite complex over the time. But now, it fits all my needs (all my current needs…).
I use it for >50 lights at the moment - some are on/off lights, most are dimmable and some are RGB color lights.

Be warned: It uses a lot of helper entities for brightness, blocking and so on. By that, it gets very flexible. I use a package for each light, so by “search and replace” I can easily copy the config of one light as a starting point for another one.

Description of the inputs and helper will follow in the next post, due to character limitaiton

blueprint:
  name: Automation for Dim and Switch Lights
  description: Pretty complex automation with a lot of helper entities
  domain: automation
  input:
    light_entity:
      name: Light
      description: The light that shall be controlled.
      selector:
        target:
          entity:
            domain: light
    automation_switch:
      name: Automation Switch
      description: Switching the automation function on or off without deactivating the HA automation
      selector:
        target:
          entity:
            domain: input_boolean
    trigger:
      name: Helper Trigger
      description: Binary Sensor that represents occupancy
      selector:
        target:
          entity:
            domain: binary_sensor
    helper_effective_brightness:
      name: Helper Effective Brightness
      description: Helper Entity (sensor), that keeps the current effective brightness
      selector:
        target:
          entity:
            domain: sensor
    helper_basic_brightness:
      name: Helper Basic Brightness
      description: Helper Entity (sensor), that keeps the current basic brightness
      selector:
        target:
          entity:
            domain: sensor
    helper_is_too_dark:
      name: Helper showing if too dark
      description: Helper Entity (binary sensor), that indicates if it is too dark
      selector:
        target:
          entity:
            domain: binary_sensor
    helper_is_too_bright:
      name: Helper showing if too bright
      description: Helper Entity (binary sensor), that indicates if it is too bright
      selector:
        target:
          entity:
            domain: binary_sensor
    helper_auto_switched:
      name: Helper Auto-Switched
      description: Variable that stores information if light was switched by automation
      selector:
        target:
          entity:
            domain: input_boolean
    helper_manually_switched_on:
      name: Helper Manually Switched On
      description: Variable that stores information if light was switched on manually
      selector:
        target:
          entity:
            domain: input_boolean
    helper_manually_switched_off:
      name: Helper Manually Switched Off
      description: Variable that stores information if light was switched off manually
      selector:
        target:
          entity:
            domain: input_boolean
    helper_switching_off_entities:
      name: Helper Switching Off Entities
      description: Sensor for number of active switching off entities
      selector:
        target:
          entity:
            domain: sensor
    helper_keeping_on_entities:
      name: Helper Keeping On Entities
      description: Binary Sensor that indicates if a keeping on entity is active
      selector:
        target:
          entity:
            domain: binary_sensor
    helper_keeping_off_entities:
      name: Helper Keeping Off Entities
      description: Binary Sensor that indicates if a keeping off entity is active
      selector:
        target:
          entity:
            domain: binary_sensor
    helper_keeping_fix_entities:
      name: Helper Keeping Fix Entities
      description: Binary Sensor that indicates if a keeping fix entity is active
      selector:
        target:
          entity:
            domain: binary_sensor

mode: queued
max: 20
max_exceeded: silent

variables:
  helper_effective_brightness: !input helper_effective_brightness
  helper_basic_brightness: !input helper_basic_brightness
  light_entity: !input light_entity

trigger:
  - platform: state
    entity_id: !input automation_switch
    id: app_switch
    to: 'on'
  - platform: homeassistant
    event: start
    id: ha_start
  - platform: state
    entity_id: !input trigger
    id: motion_on
    from: "off"
    to: "on"
  - platform: state
    entity_id: !input trigger
    id: motion_off
    from: "on"
    to: "off"
  - platform: state
    entity_id: !input helper_switching_off_entities
    id: switching_off_entities
  - platform: state
    entity_id: !input helper_is_too_dark
    id: too_dark
    to: "on"
  - platform: state
    entity_id: !input helper_is_too_bright
    id: too_bright
    to: "on"
  - platform: state
    entity_id: !input light_entity
    id: light_on_or_off
    to: ~
  - platform: state
    entity_id: !input helper_keeping_on_entities
    id: keeping_on_ended
    to: "off"
  - platform: state
    entity_id: !input helper_keeping_off_entities
    id: keeping_off_ended
    to: "off"
  - platform: state
    entity_id: !input helper_keeping_fix_entities
    attribute: brightness
    id: keeping_fix_brightness_changed
    to: ~
  - platform: state
    entity_id: !input helper_effective_brightness
    attribute: special_brightness
    to: ~
    id: no_of_special_brightness_changed

action:
  - choose:
  # path 1
    - conditions:
      - condition: or
        conditions:
          - condition: trigger
            id: app_switch
          - condition: trigger
            id: ha_start
      sequence:
      - service: input_boolean.turn_off
        target:
          entity_id: !input helper_auto_switched
      - choose:
        - conditions:
          - condition: trigger
            id: ha_start
          sequence:
          - wait_template: "{{ states(light_entity) in ['on','off'] }}"
        default: []
      - choose:
        - conditions:
          - condition: state
            entity_id: !input helper_keeping_fix_entities
            state: 'off'
          sequence:
          - choose:
            - conditions:
              - condition: state
                entity_id: !input trigger
                state: 'on'
              sequence:
              - choose:
                - conditions:
                  - condition: state
                    entity_id: !input helper_is_too_dark
                    state: 'on'
                  sequence:
                  - condition: state
                    entity_id: !input automation_switch
                    state: 'on'
                  - condition: state
                    state: 'off'
                    entity_id: !input helper_keeping_off_entities
                  - condition: state
                    state: 'off'
                    entity_id: !input helper_manually_switched_off
                  - choose:
                    - conditions:
                      - condition: state
                        entity_id: !input light_entity
                        state: 'off'
                      sequence:
                      - service: input_boolean.turn_on
                        target:
                          entity_id: !input helper_auto_switched
                    default: []
                  - choose:
                    - conditions:
                      - condition: template
                        value_template: '{{ state_attr(helper_effective_brightness, "color") == none }}'
                      sequence:
                      - service: light.turn_on
                        target:
                          entity_id: !input light_entity
                        data_template:
                          brightness_pct: >
                            {{ states(helper_effective_brightness) | int(75) }}
                    - conditions:
                      - condition: template
                        value_template: '{{ state_attr(helper_effective_brightness, "color") != none }}'
                      sequence:
                      - service: light.turn_on
                        target:
                          entity_id: !input light_entity
                        data_template:
                          brightness_pct: >
                            {{ states(helper_effective_brightness) | int(75) }}
                          rgb_color: >
                            {{ state_attr(helper_effective_brightness, "color") }}
                    default: []
                # path 2
                - conditions:
                  - condition: state
                    entity_id: !input helper_is_too_bright
                    state: 'on'
                  sequence:
                  - condition: state
                    entity_id: !input automation_switch
                    state: 'on'
                  - condition: state
                    state: 'off'
                    entity_id: !input helper_keeping_on_entities
                  - condition: state
                    state: 'off'
                    entity_id: !input helper_manually_switched_on
                  - choose:
                    - conditions:
                      - condition: state
                        entity_id: !input light_entity
                        state: 'on'
                      sequence:
                      - service: input_boolean.turn_on
                        target:
                          entity_id: !input helper_auto_switched
                    default: []
                  - service: light.turn_off
                    target:
                      entity_id: !input light_entity
                default: []
            - conditions:
              - condition: state
                entity_id: !input trigger
                state: 'off'
              sequence:
              - condition: state
                entity_id: !input automation_switch
                state: 'on'
              - condition: state
                state: 'off'
                entity_id: !input helper_keeping_on_entities
              - choose:
                - conditions:
                  - condition: state
                    entity_id: !input light_entity
                    state: 'on'
                  sequence:
                  - service: input_boolean.turn_on
                    target:
                      entity_id: !input helper_auto_switched
                default: []
              - service: light.turn_off
                target:
                  entity_id: !input light_entity
            default: []
        # path 4
        - conditions:
          - condition: state
            entity_id: !input helper_keeping_fix_entities
            state: 'on'
          sequence:
          - condition: state
            entity_id: !input automation_switch
            state: 'on'
          - choose:
            - conditions:
              - condition: state
                entity_id: !input light_entity
                state: 'off'
              sequence:
              - service: input_boolean.turn_on
                target:
                  entity_id: !input helper_auto_switched
            default: []
          - choose:
            - conditions:
              - condition: template
                value_template: '{{ state_attr(helper_effective_brightness, "color") == none }}'
              sequence:
              - service: light.turn_on
                target:
                  entity_id: !input light_entity
                data_template:
                  brightness_pct: >
                    {{ states(helper_effective_brightness) | int(75) }}
            - conditions:
              - condition: template
                value_template: '{{ state_attr(helper_effective_brightness, "color") != none }}'
              sequence:
              - service: light.turn_on
                target:
                  entity_id: !input light_entity
                data_template:
                  brightness_pct: >
                    {{ states(helper_effective_brightness) | int(75) }}
                  rgb_color: >
                    {{ state_attr(helper_effective_brightness, "color") }}
            default: []
        default: []
    # path 5
    - conditions:
      - condition: trigger
        id: motion_on
      sequence:
      - service: input_boolean.turn_off
        target:
          entity_id: !input helper_manually_switched_off
      - service: input_boolean.turn_off
        target:
          entity_id: !input helper_manually_switched_on
      - condition: state
        entity_id: !input automation_switch
        state: 'on'
      - condition: state
        entity_id: !input helper_keeping_off_entities
        state: 'off'
      - condition: state
        entity_id: !input helper_keeping_fix_entities
        state: 'off'
      - condition: state
        entity_id: !input helper_is_too_dark
        state: 'on'
      - choose:
        - conditions:
          - condition: state
            entity_id: !input light_entity
            state: 'off'
          sequence:
          - service: input_boolean.turn_on
            target:
              entity_id: !input helper_auto_switched
        default: []
      - choose:
        - conditions:
          - condition: template
            value_template: '{{ state_attr(helper_effective_brightness, "color") == none }}'
          sequence:
          - service: light.turn_on
            target:
              entity_id: !input light_entity
            data_template:
              brightness_pct: >
                {{ states(helper_effective_brightness) | int(75) }}
        - conditions:
          - condition: template
            value_template: '{{ state_attr(helper_effective_brightness, "color") != none }}'
          sequence:
          - service: light.turn_on
            target:
              entity_id: !input light_entity
            data_template:
              brightness_pct: >
                {{ states(helper_effective_brightness) | int(75) }}
              rgb_color: >
                {{ state_attr(helper_effective_brightness, "color") }}
        default: []
    # path 6
    - conditions:
      - condition: trigger
        id: motion_off
      sequence:
      - service: input_boolean.turn_off
        target:
          entity_id: !input helper_manually_switched_on
      - service: input_boolean.turn_off
        target:
          entity_id: !input helper_manually_switched_off
      - condition: state
        entity_id: !input automation_switch
        state: 'on'
      - condition: state
        entity_id: !input helper_keeping_on_entities
        state: 'off'
      - condition: state
        entity_id: !input helper_keeping_fix_entities
        state: 'off'
      - choose:
        - conditions:
          - condition: state
            entity_id: !input light_entity
            state: 'on'
          sequence:
          - service: input_boolean.turn_on
            target:
              entity_id: !input helper_auto_switched
        default: []
      - service: light.turn_off
        target:
          entity_id: !input light_entity
    # path 7
    - conditions:
      - condition: trigger
        id: switching_off_entities
      sequence:
      - condition: template
        value_template: '{{ is_number(trigger.to_state.state) }}'
      - condition: template
        value_template: '{{ is_number(trigger.from_state.state) }}'
      - condition: template
        value_template: '{{ (trigger.to_state.state | float(0)) > (trigger.from_state.state | float(1)) }}'
      - condition: state
        entity_id: !input automation_switch
        state: 'on'
      - choose:
        - conditions:
          - condition: state
            entity_id: !input light_entity
            state: 'on'
          sequence:
          - service: input_boolean.turn_on
            target:
              entity_id: !input helper_auto_switched
        default: []
      - service: light.turn_off
        target:
          entity_id: !input light_entity
    # path 8
    - conditions:
      - condition: trigger
        id: too_dark
      sequence:
      - condition: state
        entity_id: !input automation_switch
        state: 'on'
      - condition: state
        entity_id: !input trigger
        state: 'on'
      - condition: state
        entity_id: !input helper_keeping_off_entities
        state: 'off'
      - condition: state
        entity_id: !input helper_keeping_fix_entities
        state: 'off'
      - condition: state
        entity_id: !input helper_manually_switched_off
        state: 'off'
      - choose:
        - conditions:
          - condition: state
            entity_id: !input light_entity
            state: 'off'
          sequence:
          - service: input_boolean.turn_on
            target:
              entity_id: !input helper_auto_switched
        default: []
      - choose:
        - conditions:
          - condition: template
            value_template: '{{ state_attr(helper_effective_brightness, "color") == none }}'
          sequence:
          - service: light.turn_on
            target:
              entity_id: !input light_entity
            data_template:
              brightness_pct: >
                {{ states(helper_effective_brightness) | int(75) }}
        - conditions:
          - condition: template
            value_template: '{{ state_attr(helper_effective_brightness, "color") != none }}'
          sequence:
          - service: light.turn_on
            target:
              entity_id: !input light_entity
            data_template:
              brightness_pct: >
                {{ states(helper_effective_brightness) | int(75) }}
              rgb_color: >
                {{ state_attr(helper_effective_brightness, "color") }}
        default: []
    # path 9
    - conditions:
      - condition: trigger
        id: too_bright
      sequence:
      - condition: state
        entity_id: !input automation_switch
        state: 'on'
      - condition: state
        entity_id: !input helper_keeping_on_entities
        state: 'off'
      - condition: state
        entity_id: !input helper_keeping_fix_entities
        state: 'off'
      - condition: state
        entity_id: !input helper_manually_switched_on
        state: 'off'
      - choose:
        - conditions:
          - condition: state
            entity_id: !input light_entity
            state: 'on'
          sequence:
          - service: input_boolean.turn_on
            target:
              entity_id: !input helper_auto_switched
        default: []
      - service: light.turn_off
        target:
          entity_id: !input light_entity
    # path 10
    - conditions:
      - condition: trigger
        id: light_on_or_off
      - condition: template
        value_template: >
          {{ trigger.from_state.state != 'unavailable' }}
      - condition: template
        value_template: >
          {{ trigger.from_state.state != 'unknown' }}
      - condition: template
        value_template: >
          {{ trigger.from_state.state != 'none' }}
      sequence:
      - choose:
        - conditions:
          - condition: state
            entity_id: !input helper_auto_switched
            state: 'off'
          sequence:
          - choose:
            - conditions:
              - condition: template
                value_template: >
                  {{ trigger.to_state.state == 'on' }}
              - condition: template
                value_template: >
                  {{ trigger.from_state.state == 'off' }}
              sequence:
              - service: input_boolean.turn_on
                target:
                  entity_id: !input helper_manually_switched_on
            # path 11
            - conditions:
              - condition: template
                value_template: >
                  {{ trigger.to_state.state == 'off' }}
              - condition: template
                value_template: >
                  {{ trigger.from_state.state == 'on' }}
              sequence:
              - service: input_boolean.turn_on
                target:
                  entity_id: !input helper_manually_switched_off
            default: []
        # path 12
        - conditions:
          - condition: state
            entity_id: !input helper_auto_switched
            state: 'on'
          sequence:
          - service: input_boolean.turn_off
            target:
              entity_id: !input helper_auto_switched
        default: []
    # path 13
    - conditions:
      - condition: trigger
        id: keeping_off_ended
      sequence:
      - condition: state
        entity_id: !input automation_switch
        state: 'on'
      - condition: state
        entity_id: !input trigger
        state: 'on'
      - condition: state
        entity_id: !input helper_is_too_dark
        state: 'on'
      - condition: state
        entity_id: !input helper_manually_switched_off
        state: 'off'
      - condition: state
        entity_id: !input helper_keeping_fix_entities
        state: 'off'
      - choose:
        - conditions:
          - condition: state
            entity_id: !input light_entity
            state: 'off'
          sequence:
          - service: input_boolean.turn_on
            target:
              entity_id: !input helper_auto_switched
        default: []
      - choose:
        - conditions:
          - condition: template
            value_template: '{{ state_attr(helper_effective_brightness, "color") == none }}'
          sequence:
          - service: light.turn_on
            target:
              entity_id: !input light_entity
            data_template:
              brightness_pct: >
                {{ states(helper_effective_brightness) | int(75) }}
        - conditions:
          - condition: template
            value_template: '{{ state_attr(helper_effective_brightness, "color") != none }}'
          sequence:
          - service: light.turn_on
            target:
              entity_id: !input light_entity
            data_template:
              brightness_pct: >
                {{ states(helper_effective_brightness) | int(75) }}
              rgb_color: >
                {{ state_attr(helper_effective_brightness, "color") }}
        default: []
    # path 14
    - conditions:
      - condition: trigger
        id: keeping_on_ended
      sequence:
      - choose:
        - conditions:
          - condition: state
            entity_id: !input trigger
            state: 'on'
          sequence:
          - condition: state
            entity_id: !input automation_switch
            state: 'on'
          - condition: state
            entity_id: !input helper_is_too_dark
            state: 'off'
          - condition: state
            entity_id: !input helper_manually_switched_on
            state: 'off'
          - condition: state
            entity_id: !input helper_keeping_fix_entities
            state: 'off'
          - choose:
            - conditions:
              - condition: state
                entity_id: !input light_entity
                state: 'on'
              sequence:
              - service: input_boolean.turn_on
                target:
                  entity_id: !input helper_auto_switched
            default: []
          - service: light.turn_off
            target:
              entity_id: !input light_entity
        # path 15
        - conditions:
          - condition: state
            entity_id: !input trigger
            state: 'off'
          sequence:
          - condition: state
            entity_id: !input automation_switch
            state: 'on'
          - condition: state
            entity_id: !input helper_keeping_fix_entities
            state: 'off'
          - choose:
            - conditions:
              - condition: state
                entity_id: !input light_entity
                state: 'on'
              sequence:
              - service: input_boolean.turn_on
                target:
                  entity_id: !input helper_auto_switched
            default: []
          - service: light.turn_off
            target:
              entity_id: !input light_entity
    # path 16
    - conditions:
      - condition: trigger
        id: keeping_fix_brightness_changed
      - condition: state
        entity_id: !input automation_switch
        state: 'on'
      sequence:
      - choose:
        - conditions:
          - condition: template
            value_template: >
              {{ (trigger.to_state.attributes.brightness | int(0)) > 0 }}
          sequence:
          - choose:
            - conditions:
              - condition: state
                entity_id: !input light_entity
                state: 'off'
              sequence:
              - service: input_boolean.turn_on
                target:
                  entity_id: !input helper_auto_switched
            default: []
          - choose:
            - conditions:
              - condition: template
                value_template: '{{ state_attr(helper_effective_brightness, "color") == none }}'
              sequence:
              - service: light.turn_on
                target:
                  entity_id: !input light_entity
                data_template:
                  brightness_pct: >
                    {{ trigger.to_state.attributes.brightness | int(75) }}
            - conditions:
              - condition: template
                value_template: '{{ state_attr(helper_effective_brightness, "color") != none }}'
              sequence:
              - service: light.turn_on
                target:
                  entity_id: !input light_entity
                data_template:
                  brightness_pct: >
                    {{ trigger.to_state.attributes.brightness | int(75) }}
                  rgb_color: >
                    {{ trigger.to_state.attributes.color }}
            default: []
          # path 17
        - conditions:
          - condition: template
            value_template: >
              {{ (trigger.to_state.attributes.brightness | int(0)) == 0 }}
          sequence:
          - choose:
            - conditions:
              - condition: state
                entity_id: !input trigger
                state: 'on'
              sequence:
              - choose:
                - conditions:
                  - condition: state
                    entity_id: !input helper_is_too_dark
                    state: 'on'
                  sequence:
                  - condition: state
                    entity_id: !input helper_keeping_off_entities
                    state: 'off'
                  - condition: state
                    entity_id: !input helper_manually_switched_off
                    state: 'off'
                  - choose:
                    - conditions:
                      - condition: state
                        entity_id: !input light_entity
                        state: 'off'
                      sequence:
                      - service: input_boolean.turn_on
                        target:
                          entity_id: !input helper_auto_switched
                    default: []
                  - choose:
                    - conditions:
                      - condition: template
                        value_template: '{{ state_attr(helper_effective_brightness, "color") == none }}'
                      sequence:
                      - service: light.turn_on
                        target:
                          entity_id: !input light_entity
                        data_template:
                          brightness_pct: >
                            {{ states(helper_effective_brightness) | int(75) }}
                    - conditions:
                      - condition: template
                        value_template: '{{ state_attr(helper_effective_brightness, "color") != none }}'
                      sequence:
                      - service: light.turn_on
                        target:
                          entity_id: !input light_entity
                        data_template:
                          brightness_pct: >
                            {{ states(helper_effective_brightness) | int(75) }}
                          rgb_color: >
                            {{ state_attr(helper_effective_brightness, "color") }}
                    default: []
                # path 18
                - conditions:
                  - condition: state
                    entity_id: !input helper_is_too_dark
                    state: 'off'
                  sequence:
                  - condition: state
                    entity_id: !input helper_keeping_on_entities
                    state: 'off'
                  - condition: state
                    entity_id: !input helper_manually_switched_on
                    state: 'off'
                  - choose:
                    - conditions:
                      - condition: state
                        entity_id: !input light_entity
                        state: 'on'
                      sequence:
                      - service: input_boolean.turn_on
                        target:
                          entity_id: !input helper_auto_switched
                    default: []
                  - service: light.turn_off
                    target:
                      entity_id: !input light_entity
                default: []
            # path 19
            - conditions:
              - condition: state
                entity_id: !input trigger
                state: 'off'
              sequence:
              - condition: state
                entity_id: !input helper_keeping_on_entities
                state: 'off'
              - condition: state
                entity_id: !input helper_manually_switched_on
                state: 'off'
              - choose:
                - conditions:
                  - condition: state
                    entity_id: !input light_entity
                    state: 'on'
                  sequence:
                  - service: input_boolean.turn_on
                    target:
                      entity_id: !input helper_auto_switched
                default: []
              - service: light.turn_off
                target:
                  entity_id: !input light_entity
            default: []
        default: []
    # path 20
    - conditions:
      - condition: trigger
        id: no_of_special_brightness_changed
      sequence:
      - condition: state
        entity_id: !input automation_switch
        state: 'on'
      - condition: state
        entity_id: !input helper_keeping_fix_entities
        state: 'off'
      - condition: state
        entity_id: !input light_entity
        state: 'on'
      - delay: 1
      - choose:
        - conditions:
          - condition: template
            value_template: '{{ state_attr(helper_effective_brightness, "color") == none }}'
          sequence:
          - service: light.turn_on
            target:
              entity_id: !input light_entity
            data_template:
              brightness_pct: >
                {{ states(helper_effective_brightness) | int(75) }}
        - conditions:
          - condition: template
            value_template: '{{ state_attr(helper_effective_brightness, "color") != none }}'
          sequence:
          - service: light.turn_on
            target:
              entity_id: !input light_entity
            data_template:
              brightness_pct: >
                {{ states(helper_effective_brightness) | int(75) }}
              rgb_color: >
                {{ state_attr(helper_effective_brightness, "color") }}
        default: []
    default: []
4 Likes

Open your Home Assistant instance and show the blueprint import dialog with a specific blueprint pre-filled.

Description of the inputs, especially the helper entities:

  • light_entity: No surprise, the light entity that shall be automated
  • automation_switch: an input_boolean that switches on/off the function of automating the light (if off, manual actuation of the light is still tracked. That’s why I do not switch the “HA-Automation” off if I want the light to be not automated any more
  • trigger: if on, presence is assumed
  • helper_basic_brightness: value from 0 to 100 that provides a “standard” brightness. I use different values over the time of the day for most lights
    Color lights need an attribure called color that stores an RGB color as list, e.g. [0, 255, 127]
  • helper_effective_brightness: Take the basic brightness helper and modify it if an entity has a certain state. E.g. basic brightness is 50 for the hallway in the evening, but if someone sleeps, then the brightness shall be 10.
    Needs an attribure called special_brightness that shows the number of currently active special_brightness entities (Background: If the basic brightness changes during light on, I don’t want the light brightness to change. But if an entity changes, that causes a special brightness, then I do want the light to change)
    Color lights need an attribure called color that stores an RGB color as list, e.g. [0, 255, 127] like in basic brightness helper
  • helper_is_too_dark: binary sensor that turns on if too dark. Basically compare a minimum illuminance value to a measured illuminance. Just set true if there is no illuminance sensor
  • helper_is_too_bright: binary sensor that turns on if too bright and the light should be switched off
  • helper_auto_switched: input_boolean that stores the information if an action (light on/off) was triggered by this automation. If not, the light was manually switched on/off
  • helper_manually_switched_on: input_boolean that stores the information if the light was turned on manually (then this automation should not turn it off again)
  • helper_manually_switched_off: same as above, but for manually turned off
  • helper_switching_off_entities: Some entities shall make the light turning off - e.g. when sleep mode on, all lights in the sleeping room shall turn off. This helper stores the number of active switching_off_entities
  • helper_keeping_on_entities: if on, the light will stay on even if trigger changes to off
  • helper_keeping_off_entities: if on, the light will stay off even if trigger changes to on. But it will not turn off - therefore the helper_switching_off_entities is needed (the reason is, that I have lights that should not be turned of if something happens, but when they are off once, then they shall stay off)
  • helper_keeping_fix_entities: if on, the light will stay on the defined brightness value (attribute brightness needed) even if the trigger turns off. I use that e.g. for a night light or for background light when watching TV
    Attribute brightness needed (of course this can be dependent on what keeping_fix_entity is active at the moment)
    Attribute color is needed for color lights

A little ovewview of what the automation does:

Some of my lights as examples

Simple on/off light without illuminance sensor:

Standard dimmable light with one special brightness:

Dimmable light with a keeping_fix_entity:

Dimmable light that stays off a certain time of the day:

Color light that changes color during the day:

Another color light:

4 Likes

Hi,
Thanks for the blueprint! It looks like the exact thing I need!
I have tried to set it up but when I save my automation it does not show in the automation list.
I do see it in Automation.yaml file but it is not loading.
What am I doing wrong here?

from automation.yaml

- id: '1664742800437'
  alias: Livingroom_main_Light_Controller
  description: ''
  use_blueprint:
    path: der-optimist/pretty-complex-light-automation.yaml
    input:
      light_entity:
        entity_id: light.livingroom_main_light
      automation_switch:
        entity_id: input_boolean.automation_switch_light_livingroom
      trigger:
        entity_id: binary_sensor.livingroom_motion_sensors
      helper_effective_brightness:
        entity_id: sensor.livingroom_effective_brightness
      helper_basic_brightness:
        entity_id: sensor.livingroom_basic_brightness
      helper_is_too_dark:
        entity_id: binary_sensor.livingroom_is_too_dark
      helper_is_too_bright:
        entity_id: binary_sensor.livingroom_is_too_bright
      helper_auto_switched:
        entity_id: input_boolean.helper_light_auto_switched_livingroom
      helper_manually_switched_on:
        entity_id: input_boolean.helper_light_manually_switched_on_livingroom
      helper_manually_switched_off:
        entity_id: input_boolean.helper_light_manually_switched_off_livingroom
      helper_switching_off_entities:
        entity_id: sensor.helper_switching_off_entities_livingroom
      helper_keeping_on_entities:
        entity_id: binary_sensor.helper_keeping_on_entities_livingroom
      helper_keeping_off_entities:
        entity_id: binary_sensor.helper_keeping_off_entities_livingroom
      helper_keeping_fix_entities:
        entity_id: binary_sensor.livingroom_keeping_fix_entities

I don’t use GUI for creating automations, so I’m not really familiar with that. Do you get an error message when you restart HA?

I did not get any errors, it just did not work. I did it your way using packages and now it works

This looks amazing - but way beyond what I am capable of understanding. Has anyone put together a video explaining how to setup?

1 Like

Hi Dan, I don’t have a video, sorry. Do you have specific question I could try to answer?

Looks like exactly what I want. I am migrating from OpenHab and had a very buggy but similar setup there. I did not separate different state though but had a mode number 1-5 for the whole house that decided the state of the lights in the house.

I had one question though, why do you have two entities for to dark and to bright? It feels like you are just recreating the behavior of the threshold sensor?

As far as I know, the threshold sensor can only use fixed limits. I use time-dependant limits (might be an overkill, I know).
And additionally, with using template sensors I could do something like “use the specified limit, unless there is situation XY, then use Z” - so I’m more flexible for the future.

If you are interested: I have a little update on my GitHub for the blueprint, it takes an additional entity “Stay as you are” now.

I have a white bulb in a motion activated group with color bulbs, could I use this to keep the white bulb off if the other bulbs change to a color-mode?

I don’t understand your question tbh. Are you asking if you can use the color mode of bulb Y as a blocking entity (condition) for bulb X?
If so, I would say yes. You can use anything that you can express in a template as “keeping_off_entity” or “switching_off_entity” or both.

Been implementing this now at home and it works great one thing I have not grasped is what you use the manual on an off for. I assumed they would stop the automation until the lamp was turned off or on again as this is what I did before but that does not seem to be the case, so what do you use them for?

I have also updated the script so that you can have color_temperature as well as color. I have a lot of IKEA lights that does not have color but do have temperature. Are you interested in a PR for that?

The manual on / off means, if a light is turned off via wall button, voice command or HA GUI, then the automation should not turn it on again. And vice versa, if the automation “thinks” it’s bright enough but I turn on the light manually, then the automation shall leave it on.
This “blocking” is reset when there is no presence any more (trigger to off).

The behavior you expected is meanwhile implemented as a “stay as you are” helper - if this entitiy turns on, then the automation does not change the light any more (but the HA automation stays active, so that it can track manual on/offs).
This is done by toggling the helper “automation_switch” that was already there in the first version.

I’m not really familiar with github and PR, but I’m interested in your modification - that sounds good.
Do I have to change anything to make that PR possible, e.g. invite you or something?
Here the file is located:

Found this hidden gem today and wanted to say a big thank you for sharing with us!!