Hi everybody,
I am replacing my regular light switches step by step with motion sensors. Ideally, lights will only be on when somebody is in the room and turn off by itself. This works fine, however, I need to also control the brightness.
During the day, it should be rather high, in the evening low, and at night at minimal (so that you can see but it won’t wake you up).
Below the code I use and some explanation
attempt for binary sensors, not working
binary_sensor:
- platform: tod
name: "Tagsüber"
after: sunrise
before: sunset
- platform: tod
name: "Nachts"
after: sunset
before: sunrise
after_offset: "+01:30:00"
- platform: tod
name: "Abends"
after: sunset
after_offset: "-01:30:00"
problem:
In developer tools
=> states
I can see binary_sensor.tagsuber
, but both binary_sensor.abends
and binary_sensor.nachts
are missing. I just created them, so perhaps they will not appear since the first time they have been triggered (though I highly doubt this!)?
attempted automation (which I cannot try because not all of those sensors above work yet)
automation:
- alias: "[Licht] Helligkeit"
trigger:
- platform: state
entity_id:
- binary_sensor.motion_flur_occupancy
- binary_sensor.motion_schlafzimmer_occupancy
- binary_sensor.motion_kueche_occupancy
to: "on"
action:
- service: light.turn_on
entity_id: >
{% set myroom = trigger.to_state.object_id.split('_')[1] %}
light.{{myroom}}_light
data:
brightness: >
{% if state_attr('binary_sensor.tagsuber', 'true') %}
180
{% elif state_attr('binary_sensor.abends'), 'true' %}
80
{% elif state_attr('binary_sensor.nachts'), 'true' %}
15
{% else %}
30
{% endif %}
This is supposed to
- trigger when either motion sensor is triggered
- as both lights and motion sensors follow a pattern (
binary_sensor.motion_<room>_occupancy
andlight.<room>_light
), automatically decide which light to turn on - therefore set variable and automatically use it per sensor/light
- check whether it is daytime (
tagsuber
, evening (abends
), or nighttime (nachts
); depending on what daytime it is, set brightness to appropriate level (these numbers are just examples, still have to figure out the right values)
Why do this?
==> I do not want to manually modify the time when the seasons change, so I cannot use, for example, at: "18:30:00
as a value for evening time; it is dark much earlier in winter and much later in summer, so I need to use sunrise
/sunset
and an offset to determine when it is what.
Should my automation work if I get the binary_sensors to work? I currently do this per room without templates, so I am not 100% sure, but if it works, I will adapt my automation for the off
automation as well (which is pretty much identical, except that the motion sensor needs to be off
for a certain period of time (to assure that if it turns off and right back on because somebody is still inn there nothing is triggered).
Thanks for your ideas