hi,
I have an IKEA Tradfri with motion sensor. I am looking for some help. I would like to set the brightness level of the lamp based on the time of day. For example:
7AM - 7PM: 255
7PM - 11PM: 127
11PM - 7AM: 31
So, whenever the motion sensor triggers during the day the light turns on and has the brightness according to the listed values.
My problem is that it seems I can not set the brightness of the light without turning it on. So the best thing I can think of is to create a time based trigger that runs a simple 3 step script:
turn on light with right brightness
wait 1 sec (just to be sure the light turned on)
turn off light
But, I feel this is a stupid workaround and hope someone has some another idea.
In the automation that turns the light on, you could use a template with an if block to set the brightness in the action based on the value of now(). Iâd give a more specific example but Iâm having a hard time finding out what format now() returns.
If somehow the light is turned on outside of Hass (ZWave has features allowing device-to-device control, itâs possible zigbee does as well), you could set a trigger, which changes the brightness of the light when it turns on. To wit:
automation foo:
trigger:
platform: state
entity_id: light.foo
from: 'off'
to: 'on'
action:
service: light.turn_on
entity_id: light.foo
data_template:
brightness: {% if block here %}
The thing is that the Tradfri will turn on the light and not an automation in HA (like you said device-to-device control).
Thanks for the suggestion to adjust the brightness when the light is indeed turned on.
I am curious though whether the limitation to set brightness without turning on the light is an imitation of the HA Light Platform (feature request!) or that z-wave/zigbee/e.a light platforms simply do not support this and hence mo point of building it in HA. Anyone know?
You could do a simple condition if the state of the light is on. And another automation that if you turn it on between the times it goes to the brightness youâd like it as.
The problem with this is youâd have a lot of automations for each of your Lights.
So another way but more complex would be to write some jinja code to loop through all of your Lights and any that are on, set to the desired brightness. You could do 2 triggers, one for time of day and the other if the light state from off to on.
With trigger.entity_id I would probably be able to create a single automation, so that wouldnât be so bad, but I would have liked to create a time based triggers to set the brightness without turning on the lights.
Thanks for your response.
If I check this code in the home assistant template editor, I get the correct result depending of time of day
Example result:
data_template:
brightness: 200
but if I check the config using HA, I get the following error:
Error loading /home/homeassistant/.homeassistant/configuration.yaml: while scanning for the next token found character â%â that cannot start any token in â/home/homeassistant/.homeassistant/automations.yamlâ, line 70, column 20
which corresponds to the first â%â in my data template. What am I doing wrong? Am I overseeing the obvious?
there are so many examples out there without the quotes⌠I was under the impression that the values should be without single quotes. But it seems it doesnât hurt to use them most of the timeâŚ
Error loading /home/homeassistant/.homeassistant/configuration.yaml: while scanning for the next token found character â%â that cannot start any token in â/home/homeassistant/.homeassistant/automations.yamlâ, line 71, column 8
So the only way to get it to work for me is keeping it in one line and using the single quotesâŚ
The easiest way to fix this would be to create 3 scenes for :
7AM - 7PM: 255
7PM - 11PM: 127
11PM - 7AM: 31
and then in the automation create new automation calling the scens at specific time of the day.