SOLVED...Bathroom Lights dim automatically. Great...but what if I need them to be full brightness right now?!?!

I believe you mean on → off → on.

When you walk into the bathroom in the evening, you turn on the switch and it brightens to some level less than 100%. That’s the user’s first ‘hands-on’ with the switch. Now the user must operate the switch two more times: turn off, then turn back on. That’s a total of three operations to get the light to maximum brightness.

Here’s the catch. The timer-based solution requires the user to perform the on/off/on sequence within a short time span (all done within ~ 3 seconds). What the user cannot do is turn on the light and hesitate before deciding the light needs to be brighter. By that point, the additional off->on operation is too late. Now they have to start from scratch which means they have to turn the light off first, then turn it on/off/on (that’s four operations, five if you count the first turn-on). To compensate, you can extend the timer’s duration to, perhaps, 5 seconds. However, you don’t want to extend it for too long because that can make it susceptible to other problems.

I don’t think you are describing it right for the automations I suggested. That is why I edited my post to start the timer with ‘off’. Less taps.

Three taps, minimum.

  1. Turn on. Brightness is less than 100%.
  2. Turn off. Timer is started.
  3. Turn on. Brightness is set to 100%.

I agree that the rest of what I explained (more than 3 taps) applies only if the timer is started at the first turn-on (which is how the automation is shown). Changing it to start the timer when the switch is turned off is a good idea.

Okay so these templates are still a bit of a mystery to me. I’ve used a few, but I’m still learning whenever a new one comes up…
Can you explain the above part to me? do I need to add something in the parentheses?

I would really appreciate the explanation

If timer is inactive then:

  • If time is between 20h and 7h, turn on the light with brightness 15
  • Any other time, turn on the light with brightness 50.

Ha FunkyBoT beat me to it :slight_smile: Just a small addition about this line:

{% elif now().hour > 20 or now().hour < 7 %}

Home Assistant’s day ends at 00:00 every night. So the first part (>20) covers from 21:00 - 00:00. The second part (<7) covers from 00:00 - 07:00.

Reading you correctly, I think you’ll want something like:

{% if is_state('timer.brightness_timer','active') %}
100
{% elif 18 >= now().hour < 23 %}
50
{% elif now().hour >= 23 or now().hour < 7 %}
15
{% else %}
100
{% endif %}

You don’t need to add anything between the parentheses. Now() is just the syntax for the current date and time. Now().hour is the syntax for the number of the hour right now.

1 Like

If I want the first “if” time to be between 7:30pm and 11pm can I do this?

{% elif 19.5 >= now().hour < 23 %}

or would it be like this?

{% elif 19:30 >= now().hour < 23 %}

Or some other way?

Your first example wouldn’t work the way you think it might and the second example wouldn’t work at all.

The function now().hour returns the current hour as an integer value. So if the current time is 21:45 then now().hour will report 21.

What it won’t do is report 21.75. now().hour reports the current, not some sort of floating-point representation of the time. That’s why your first example:

19.5 >= now().hour < 23

won’t work correctly. If the current time is 19:45, it lies between 19:30 and 23:00. However, it won’t in your template because now().hour will report 19:45 as 19.

The second example contains invalid syntax. 19:30 is not an integer value so you can’t use it in a comparison with other integer values.

Yea that’s what I was afraid of.

So I kind of got this to work, but the code isn’t nearly as sexy as what you have all been showing me.

The following template did not work as expected. Whenever I turned to light on after 7pm, it just came on to 100%.

  - service: light.turn_on
    entity_id: light.master_bathroom
    data_template:
      brightness_pct: >
        {% if is_state('input_boolean.dim_cancel','on') %}
        100
        {% elif 19 >= now().hour < 23 %}
        50
        {% elif now().hour >= 23 or now().hour < 6 %}
        15
        {% else %}
        100
        {% endif %}

It’s highly probable that I don’t/didn’t have something setup properly, but I couldn’t figure it out.

However with these automations, timer and input boolean…I’ve managed to make this work.

edit: (see the august 13th post for all code in one place).

#############
#automations#
#############

- alias: 'dim_timer_started'
  trigger:
  - platform: event
    event_type: timer.started
    event_data:
      entity_id: timer.dim_cancel
  action:
  - service: input_boolean.turn_on
    entity_id: input_boolean.dim_cancel

- alias: 'dim_timer_finished'
  trigger:
  - platform: event
    event_type: timer.finished
    event_data:
      entity_id: timer.dim_cancel
  action:
  - service: input_boolean.turn_off
    entity_id: input_boolean.dim_cancel

#########################
#Master Bath Evening Dim#
#########################
- id: mbath_evening
  alias: MBathroom Evening
  initial_state: true
  trigger:
  - platform: state
    entity_id: light.master_bathroom
    from: 'off'
    to: 'on'
  condition:
  - condition: time
    after: '19:30:00'
    before: '23:00:00'
  action:
  - service: light.turn_on
    entity_id: light.master_bathroom
    data:
      brightness_pct: 50
  - condition: state
    entity_id: input_boolean.dim_cancel
    state: 'on'
  - service: light.turn_on
    entity_id: light.master_bathroom
    data:
      brightness_pct: 100

(I’ve setup another automation for the overnight dim level as well).

################
#input booleans#
################

input_boolean:
  dim_cancel:
    name: Auto Dimming Cancel
    initial: off
#######
#timer#
#######
timer:
  dim_cancel:
    duration: '00:00:02'

As I stated, this code could probably be much sexier and more condensed with the templates, but for now this is working for me.
I’ll probably come back to the templating issue in time.

Thank you everyone for your input! Super helpful!

Try this:

{% elif now().hour >= 19 and now().hour < 23 %}
1 Like

Going to try tonight…
sorry I dropped off the earth for a bit.
Life happens.

Okay so in case anyone else is reading this, I did get this working.

Within the ISY, I set default on levels during specific hours. So in the evenings/night the lights turn on at 50% and overnight they come on at 15%

Then with every event of the lights turning off at the switch, the 2 second timer is started. If the lights get turned on while the timer is active, they come on at full brightness.

The only down side is if you want to go back to dim levels, you have to turn off the lights and wait at least 2 seconds to turn them back on. Not a huge deal really, but I can’t think of any other way around this.

Overall I’m super happy with this setup (as is my wife…score!). I actually kind of like the “secret handshake” of it all. I would like all the automation-ing to be within HA, but the default on levels being in the ISY is actually pretty great. They come on directly to the preferred level rather than on at full brightness, then quickly changing to the preferred dim level.

So thank you 123 Taras, Emphyrio, FunkyBoT, and sparkydave for all your help with this.

If anyone wants to see the code, let me know. It’s pretty straightforward, actually, but I’m happy to post it here.

2 Likes

It would be good if you did post it here for anyone looking in the future. I’d be interested to see the code to see if it can help improve/complement what I have

So here is the code. The actual dimming of the lights in the evening and the overnight hours happens in my ISY program as I stated earlier.

This dimming could be achieved with one automation with a template action (if you read above, I never could get that to work…not smart enough with templates) or a couple different automations.



######This goes in your automation file or under automation: in your config file


#########################
#Bathroom Dimming, Timer#
#########################

############Timer turns on every time the light turns off between 730p and 6a
- id: mbath_eve_begin_timer
  alias: MBathroom Evening Begin Timer
  initial_state: true
  trigger:
  - platform: state
    entity_id: light.master_bathroom
    from: 'on'
    to: 'off'
  condition:
  - condition: time
    after: '19:30:00'
    before: '06:00:00'
  action:
  - service: timer.start
    entity_id: timer.dim_cancel


######If light turns on and timer is active, then it sets the lights to 100%
- id: mbath_evening
  alias: MBathroom Evening
  initial_state: true
  trigger:
  - platform: state
    entity_id: light.master_bathroom
    from: 'off'
    to: 'on'
  condition:
  - condition: state
    entity_id: timer.dim_cancel
    state: 'active'
  action:
  - service: light.turn_on
    entity_id: light.master_bathroom
    data:
      brightness_pct: 100


#########This goes in your config file##########



###########Timer Code 2 seconds
timer:
  dim_cancel:
    duration: '00:00:02'

Hope this helps anyone reading. I’m really loving this automation. Thanks again everyone that helped out.

3 Likes

Thanks so much for the solution, it works flawless. I’m using a slightly modified version of the code to turn all my garden lights on using the alfresco light switch. So I can just turn the alfresco lights on/off with the standard wall switch with a tasmotized sonoff basic or by turning the switch off and on again within 2 seconds all the garden lights will come on too. Now wife is happy as well :grinning: