I’d love to get someone’s eyes on this, basically I had four automations (that worked) for setting the brightness of the led’s in our closets based on the period of the day (template sensor).
For sake of mainenance and ease of use I wanted to boil it down to one automation with if/else in the action, can’t get it to work as I expected, the config validates fine but nothing happens when triggered. Any idea what I’m doing wrong? THanks in advance!
Glad you sorted it out. I didnt notice the data template.
Yes, you just replace your template with mine under brightness, but dont even bother since it worked for you.
I am not an expert in templating… On the contrary, I also struggle with it… I hope I made myself understandable and I also hope this template is the correct
First part worked from the bat, I had to switch syntax style to parenthesis and use numeric state to get it to work but you certainly put me on the right path. And reminded me I should read the documentation, some trial and error and looking into the templating docs I arrived at this; which does what I expected:
message: >
"Period of day changed to: {{ states('sensor.period_of_day') }}. Setting closets brightness to {{ ((state_attr('light.closets', 'brightness') | float / 255)*100) | round(0)}}%"
Well, You were far more insightful than me at least, IDK it was called templating so that certainly put me in the right direction, far better off then when we started this ordeal, thanks so much for your help.
You can test your templating by clicking on the left menu in HA and click the templates button on the bottom.
In there you can paste your templates and it should turn an immediate result. If something is wrong, it will mark the error!
Try it yourself.
Try pasting your code and see what happens.
"Period of day changed to: {{ states('sensor.period_of_day') }}. Setting closets brightness to {{ ((state_attr('light.closets', 'brightness') | float / 255)*100) | round(0)}}%"
Your automation ensures the closet lights are on throughout the day and night and simply adjusts their brightness according to the period of day. What sort of closets are these that need to be illuminated 24 hours a day?
Thanks for the comment.
There’s actually a light-sensor built in them. So they light up on open/close, just wanted to add this as an additional layer to minimize disturbance when my SO opens to fetch clothes while I’m sleeping in the morning. Mainly though it’s cause our baby still sleeps in our bed.
So technically I wouldn’t have needed to turn on, only change brightness. Suggestion on improvement?
A light sensor? Perhaps you meant to say a motion sensor?
Doesn’t the automation turn on the light at the beginning of each new period of the day?
action:
- service: light.turn_on # <---- Turns *on* light to a specified brightness
entity_id: light.closets
data:
brightness: >-
For example, when period of day changes from night to dawn, the automation turns the light on to brightness: 126. If there’s no motion detected, the light’s motion sensor will then turn the light off.
Or when commanded to turn on, does this light refuse to turn on if it detects no motion?
** EDIT **
What is the brand and model of this light? I’m interested in learning more about how it works.
I think it detects weak light, it’s off if you obscure the sensor with your thumb, but on if it’s any brigher than that, it never turns off from lack of motion at least. It’s an ikea norrfly controlled by a tradfri driver.
We rely entirely on doors/open or not to turn it on/off. It doesn’t turn on in there if the closet is closed. Needless to say it was a dumb light I’d need a more elaborate automation. So yeah if I actually in any way turned the light off with the doors open then they’d turn on at new phase of day, but that doesnt happen.
How would I by the way ONLY change the brightness, what’s the service for that?
Thanks for the explanation and the model name. I think I understand how it works now. You’re right, it’s a light sensor that turns the light on when it detects even low levels of ambient light. Within a dark closet, the sensor ensures the light is off.
So even if you send it a command to turn on, it won’t if the light level is too low. That’s perfect for the given application (closet lighting).
To my knowledge, the only light services are light.turn_on, light.turn_off, and light.toggle.
Hm, tried to use your solution and all I get is “Invalid config for [automation]: [data_template] is an invalid option for [automation]. Check: automation->data_template”
That’s weird because this is my original automation (only for turning the light on), and it’s been working for a year without indentations. I tried to indentate but the error is still the same. Thanks!
- id: '1579121918984'
alias: Turn the light on when motion is detected
description: ''
trigger:
- device_id: f6cc3037fbff4755acecd446a3d127bc
domain: binary_sensor
entity_id: binary_sensor.aqara_body_sensor_occupancy
platform: device
type: motion
condition: []
action:
- device_id: 82a6b5963a144b74800cdefd9af6ead1
domain: light
entity_id: light.tradfri_bulb_light
type: turn_on