123
(Taras)
April 26, 2022, 12:16pm
21
Remove everything referring to the light.
123:
- alias: 'Automatic Bathroom Light'
id: automatic_bathroom_light
mode: queued
trigger:
- id: 'motion'
platform: state
entity_id: binary_sensor.badezimmer_bewegungsmelder_neu
from: 'off'
to: 'on'
- id: 'unoccupied'
platform: state
entity_id: binary_sensor.badezimmer_bewegungsmelder_neu
to: 'off'
for: '00:02:00'
- id: 'brightness'
platform: state
entity_id: light.badezimmer_deckenleuchte
attribute: brightness
- id: 'timeout'
platform: state
entity_id: input_boolean.badezimmer
to: 'off'
for: '00:20:00'
- id: 'light_off'
platform: state
entity_id: light.badezimmer_deckenleuchte
from: 'on'
to: 'off'
condition: "{{ is_state('sun.sun', 'below_horizon') }}"
action:
- variables:
light: light.badezimmer_deckenleuchte
auto_off: input_boolean.badezimmer
occupancy: binary_sensor.badezimmer_bewegungsmelder_neu
luminance: sensor.badezimmer_beleuchtungsstaerke
lo: 26
mid: 125
brightness: >
{{ lo if now() > today_at('23:30') or
now().time() < (state_attr('sun.sun', 'next_rising') | as_datetime | as_local).time() else mid }}
- choose:
- conditions:
- "{{ trigger.id == 'motion' }}"
- "{{ is_state(light, 'off') }}"
- "{{ states(luminance) | int(0) < 15 or is_state(fan, 'on') }}"
sequence:
- service: light.turn_on
target:
entity_id: '{{ light }}'
data:
brightness: '{{ brightness }}'
- conditions:
- "{{ trigger.id == 'unoccupied' }}"
- "{{ is_state(light, 'on') }}"
- "{{ is_state(auto_off, 'on') }}"
sequence:
- service: light.turn_off
target:
entity_id: '{{ light }}'
data:
transition: 5
- conditions:
- "{{ trigger.id == 'brightness' }}"
- "{{ is_state(auto_off, 'on') }}"
- "{{ trigger.from_state.state == trigger.to_state.state }}"
- "{{ trigger.to_state.attributes.brightness > brightness + 2 or trigger.to_state.attributes.brightness < brightness - 2 }}"
sequence:
- service: input_boolean.turn_off
target:
entity_id: '{{ auto_off }}'
- conditions:
- "{{ trigger.id == 'timeout' or (trigger.id == 'light_off' and is_state(auto_off, 'off')) }}"
sequence:
- service: input_boolean.turn_on
target:
entity_id: '{{ auto_off }}'
- condition: "{{ is_state(occupancy, 'off') and is_state(light, 'on') }}"
- service: light.turn_off
target:
entity_id: '{{ light }}'
- conditions:
- "{{ trigger.id == 'light_off' }}"
sequence: []
default: []
You mean fan? I´ve deleted everything from fan. Is it right?
123
(Taras)
April 26, 2022, 12:59pm
23
If thereâs no light switch then the automation should not refer to a light (although I donât understand why you want this). Thatâs why I suggested you remove all references to the light in the automation.
Perhaps I have not expressed myself well. I would like to use the automation also in another room where there is only a motion sensor (with light level sensor) and a light. Otherwise, could I just use a virtual switch instead of the âwall switchâ?