I am trying to step the brightness of a light source through an automation by using data_template. I cannot use transition: since this particular light source does not support it.
I do not get any change in brightness when running the below automation. What could I do wrong?
- id: '1570867369747'
alias: Time
trigger:
- at: '23:15'
platform: time
condition:
- condition: state
entity_id: input_boolean.automation_sunrise
state: 'on'
action:
- service: light.turn_on
data_template:
entity_id: light.hall_tak
brightness: >
{% if states.light.hall_tak.attributes.brightness < 50 %}
{% set steps = (250 - states.light.hall_tak.attributes.brightness) // 20 %}
{% for i in range(1, steps+1) %}
{{ states.light.hall_tak.attributes.brightness + i*20 }}
{% endfor %}
{% endif %}
I get configuration valid! when running check config under server control.
It looks like this when running the code through template under development tools.
There is no else. So when states.light.hall_tak.attributes.brightness is below 50, no valid brightness is produced. Could this be your issue? Also, is the condition met?
Edit: silly me, it is much more obvious. Your template code produces a list of brightness values. But this does not mean the service call gets repeated. Your code should loop the action light.turn_on. I am unaware of a method to achieve that in yaml. It can be done in Python code / App Daemon I believe.
I just searched the forum, AppDaemon seems the obvious route. But perhaps this link will inspire you, using a combination of script and automation. I like the idea
For inspiration; create an automation that repeatedly calls a script, each time passing higher brightness. Then stop the automation when the desired value is reached. It might be triggered by an input boolean, that you disable when the last brightness is reached.
I don’t have it in code, but perhaps this is something you can run with?
you gotta have a service with a delay between each brightness level for this to work. Your best option is a python script or hardcode each brightness level as a ramp up in a single script. With your current automation, your light will just turn on to 246 without any progression.
Thanks for the link but I think python is too advanced for me at this point. I need to better understand yaml before taking the python step.
Without knowing the details this should be possible to do in yaml, combining automation and script as you propsed above?
Is it too much to ask that you write an automation and script example for me? That I would be able to understand and modify myself. For example I dont get how to pass information between the automation and script. As pedro points out there needs to be a delay as well.
Agree, delay is needed. Hardcoded wont work since I want to start at current brightness that will differ over time. Was hoping to find a solution without python.
I like a good challenge. Plus I also have an automation that could use a step by step brightness increase. Currently it’s just a giant script, every step written out without looping.
Can you explain in words what you are trying to achieve? If I’m interpreting correctly, around sunrise you want the brightness to increase to 250, in steps of 20, starting from the current brightness. But only if the current brightness is less than 50. Is that your intention? The trigger time of 23:15 does not seem to fit the profile
It is prototype code so I understand it does not make sense
What I want could be desceibed as; one hour before sundown I want a light to stepwise increase its brightness starting at the current brightness and stop at maximum brightness. The increase should be slow, it could take in total 60 seconds so that a person in the room hardly notices that it is increased.
It is kind if the same functionality as transition: provides but my light source does not support it.
It would be great if the transition time could be changed in the code to select something else than 60 seconds. It would also be great if the end brightness could be chosen in the code to be something else than maximum brightness.
Okay, those two things would have taken me a long time to figure out.
I tried the automation and scripts but get strange behavior, first brightness step is 15 and second is 5. After that the brightness does not change. I need to look into the details further.
For troubleshooting purposes is it possible to print values somewhere while the scripts is running so that I can see what is happening?
Is it possible to see if a script is running, to make sure it is not stuck in an endless loop or something?