That would get the light turned on… I think maybe… a combination of or’ed and and’ed conditions to check light state and either turn on or turn off and set time conditions to set the brightness…
No… my goal is to get in bed and click the switch to turn the lights off or on. And depending upon the time of day set a given brightness level to the lights.
The tempate above was to give me the brightness control during the deep night hours so I do not turn a light on to 850 lumens right outside the kids room. But, I do see where toggle does not support setting brightness.
Again I’m pretty sure you can’t have 2 different services in one automation. I don’t think what you want is possible. Again I suggest getting into chat on Discord with Dale.
It’s just a hotline to the best support and it’s immediate. I use both. Especially for an issue like this talking with some of the Devs is great. Dale is an expert at automations and if he’s there he’ll fix you up.
Because light.toggle does not accept a brightness, you have to use a condition to check if the light is on after the toggle service is called, and then call light.turn_on with the time-based brightness.
Here is a working approach that still uses just one automation:
action:
- service: script.turn_on
data_template:
entity_id: >
{% if is_state('light.stair_top', 'on') %}
script.turn_light_off
{% else %}
script.turn_light_on
{% endif %}
variables:
# You can change this variable to make this whole thing dynamic if you feel like it
myentity: light.stair_top
mybrightness: >
{%- if now().hour >= 6 and now().hour <=21 %}
{{254}}
{% else %}
{{64}}
{% endif %}
However, for this one implementation, it is not necessary to have multiple scripts plus one automation. Also, it is worth mentioning that one limitation to using scripts is that in the rare instance that the automation tries to fire twice simultaneously, you will get a “Script is already running” warning, preventing the second firing of the automation to fail.
There are a few minor changes that need to be made for your config to work properly, and a couple of others that I would recommend for “best practices.”
While it is acceptable to use whitespace control inside the template itself (i.e. {%-, -%}), it is a much cleaner approach to just use >- when you have only one output segment. If you had multiple if statements in the same template that each output something, it would then be recommended to use whitespace control inside of the template itself.
Remove Jinja2 output delimiters from before and after the brightness values (254 and 64)
I only recommended this because he was getting errors in regards to setting the value. The error was explicitly returning a string of the integer instead of the integer. I wasn’t sure if that was causing the problem so I was trying to have it force the object as an integer.