Hi @daknightuk,
Looks good, I will though suggest you only have one automation handling both situations. You can do that using the âchooseâ option, to handle different situations in different conditions.
Be aware that seconds: â15â for the time pattern means each time the seconds is 15, this is once per minute. But I guess you want it to be every 15 seconds then use - seconds: '/15â
The update interval may not be shorter than the interval needed for your light sensor to discover and update changes, otherwise you end up in changes up and down passing your target before your sensor discovers that, then move the other way and so on, and youâll never rest at your desired target.
And as you do the check every 15 seconds, no need to loop, as the light doesnât change much during that period. So just adjust 10% up or down, wait 15 Seconds and see if further action is needed.
I made some test and recognized that moving by brightness percentage is not a good idea, as the steps are small at low levels and large at high levels. This gives a less consistent adjustment and your range might need to be adjusted according to your target. So I prefer using absolute steps instead
Furthermore you need not defining utll, you can by the use of templates make comparison to your target + /- 10 which I suggest to have equal intervals on both sides of you target instead of you only add 20 to the upper level.
One more thing, I recommend that you gather your parameters in the variables section, so it is easy to adjust these one central place.
Finally, when you want to add Occupancy, you can do that in the condition of the automation. We can get back to that later.
So here is my suggestion for the automation:
alias: Adjust brightness on the office bulb
description: ''
trigger:
- platform: time_pattern
seconds: '/15'
condition: []
action:
- choose:
- conditions:
- condition: template
value_template: >-
{{ states('sensor.officelightlevel')|float <
states('input_number.office_light_target')|float - range/2 }}
sequence:
- service: light.turn_on
target:
entity_id: light.office_bulb
data:
brightness_step: '{{ my_brightness_step }}'
- conditions:
- condition: template
value_template: >-
{{ states('sensor.officelightlevel')|float >
states('input_number.office_light_target')|float + range/2 }}
sequence:
- service: light.turn_on
target:
entity_id: light.office_bulb
data:
brightness_step: '{{ -1 * my_brightness_step }}'
default: []
mode: single
variables:
range: 20
my_brightness_step: 10
Please try it and let me know if it works, or still gives you any challenges.
Let me also know if you have any questions trying to understand the code which is crucial
for being able to maintain it afterwards ![:slight_smile: :slight_smile:](https://community.home-assistant.io/images/emoji/twitter/slight_smile.png?v=10)