Successfully Automating Smart Lights with Time-Based Adjustments

I recently embarked on a project to automate the lighting in my home using smart bulbs and an automation system. The goal was to create a seamless experience where the lights adjust their brightness based on the time of day, ensuring energy efficiency and comfort. The Challenge: I wanted the lights in my bathroom to dim during the night and brighten during the day. I set up an automation using a motion sensor and light sensor, but encountered an error when implementing a time-based brightness adjustment. The system kept throwing an error related to invalid service data for the light.turn_on service. The Solution: After some research and trial and error, I realized the issue was with how the brightness value was being passed in the automation script. The initial code used a template with conditional statements that returned a string instead of an integer, causing the error. I fixed this by ensuring the brightness value was correctly formatted as an integer. Here’s the corrected automation script for anyone interested: yaml alias: WC Lights on when motion on trigger: - platform: state entity_id: binary_sensor.wc_pir to: ‘on’ condition: - condition: and conditions: - condition: template value_template: ‘{{ states.light.wc_ylavalo.attributes.brightness < 5 }}’ - condition: numeric_state entity_id: sensor.wc_ldr below: 100 action: - service: light.turn_on data: entity_id: light.wc_ylavalo brightness: >- {% if now().strftime(‘%H’)|int >= 22 %} 100 {% elif now().strftime(‘%H’)|int < 7 %} 10 {% else %} 255 {% endif %} The Outcome: The automation now works perfectly! The lights dim to 10% brightness at night, provide 100% brightness just before bedtime, and reach full brightness during the day. It’s a small but significant improvement that adds convenience and efficiency to my daily routine. If anyone else is working on similar projects, I’d love to hear about your experiences or any tips you might have. Happy automating! :rocket: