Automation with hours

If I want to create automation

01-13 brightness 30
13-00 brightness 100

how I do it?

that’s what I have now

- id: '1576344116316'
  alias: 'Guest toilet Door sensor '
  description: ''
  trigger:
  - entity_id: binary_sensor.door_window_sensor_158d00035ac62a
    from: 'off'
    platform: state
    to: 'on'
  condition: []
  action:
  - data:
      entity_id: light.64341605b4e62d5e979e
    service: light.turn_on

I have different areas of the house with different brightness throughout the day
All on the same segments but different levels.
I can also (at any switch) force full brightness
So for the bathroom group
Any light comes on it comes on at service template brightness: “{{ states(‘input_number.in_light_bathroom_level’) }}”
And I have the segments trigger the different values at different times of the day.
If a light is on at a segment change then it too is changed but on a 180 second transition

what the right template ?

how its look ?

action:
  - data_template:
      entity_id: light.64341605b4e62d5e979e
      brightness: >-
        {% if now().strftime("%H") | int > 13 %}
          100
        {% else %}
          30
        {% endif %}
    service: light.turn_on

May have some typos as I’m on the phone roght now. (Seriously HA addicted :rofl:)

1 Like

For what ?
Switching the light on ?
The segments of the day ?
The storage values ?
Transitions on segment changes ?

Here is the light on automation and the segment changes driven by sensor boolean’s

automation:
    #name: Light Bath Off Delay
  - alias: au_light_bath_offdelay
    trigger:
      - platform: state
        entity_id: light.fibdim2_bath_level
        from: 'off'
        to: 'on'
    condition:
      - condition: state
        entity_id: input_boolean.ib_light_bath_timer_enable
        state: 'on'
    action:
      - service: light.turn_on
        entity_id: light.fibdim2_bath_level
        data_template:
          brightness_pct: >
            {{ states('input_number.in_aalight_bth_lvl') | int }}
          transition: >
            {{ states('input_number.in_aalight_segment_transition') | int }}
      - service: script.turn_off
        entity_id: script.sc_light_bath_timer
      - service: script.sc_light_bath_timer

script:
  sc_light_bath_timer:
    alias: Light Bath Timer Script
    sequence:
    - delay: "00:{{ states('input_number.in_light_bath_timer') | int }}:00"
    - service: light.turn_off
      entity_id: light.fibdim2_bath_level

  - alias: au_light_adjust_brightness_bthr
    trigger:
      - platform: state
        entity_id: input_number.in_aalight_bth_lvl
    condition:
      - condition: state
        entity_id: light.fibdim2_bath_level
        state: 'on'
    action:
      - service: light.turn_on
        entity_id: light.fibdim2_bath_level
        data_template:
          brightness_pct: "{{ states('input_number.in_aalight_bth_lvl') | int }}"
          transition: "{{ states('input_number.in_aalight_segment_transition') | int }}"


binary_sensor:
  - platform: template
    sensors:
    ## day segment bs
      bs_light_day:
        entity_id: sensor.time
        value_template: >
          {% set rising = state_attr('sun.sun', 'rising') %}
          {% set elevation = state_attr('sun.sun', 'elevation') | float %}
          {% set daystart = states('input_number.in_aalight_day') | float %}
          {% set eveningstart = states('input_number.in_aalight_evening') | float %}
          {% set day = (rising and elevation > daystart) or (not rising and elevation > eveningstart) %}
          {{ day }}
        friendly_name: Day Lights
        icon_template: "{{ 'mdi:white-balance-sunny' }}"
    ## evening segment bs
      bs_light_evening:
        entity_id: sensor.time
        value_template: >
          {% set time = states('sensor.time') %}
          {% set rising = state_attr('sun.sun', 'rising') %}
          {% set elevation = state_attr('sun.sun', 'elevation') | float %}
          {% set daystart = states('input_number.in_aalight_day') | float %}
          {% set eveningstart = states('input_number.in_aalight_evening') | float %}
          {% set nightstart = states('input_datetime.id_aalight_night') [0:5] %}
          {% set nightstart = '23:59' if nightstart == '00:00' else nightstart %}
          {% set day = (rising and elevation > daystart) or (not rising and elevation > eveningstart) %}
          {% if '12:00' < nightstart <= '24:00' %}
            {% set r1 = time >= nightstart %}
            {% set r2 = elevation <= daystart and time < '12:00'%}
          {% else %}
            {% set r1 = false %}
            {% set r2 = elevation <= daystart and time >= nightstart %}
          {% endif %}
          {% set night = r1 or r2 %}
          {% set evening = not (day or night) %}
          {{ evening }}
        friendly_name: Evening Lights
        icon_template: "{{ 'mdi:weather-sunset-down' }}"
    ## night segment bs
      bs_light_night:
        entity_id: sensor.time, binary_sensor.bs_light_day, binary_sensor.bs_light_evening
        value_template: >
          {% set time = states('sensor.time') %}
          {% set elevation = state_attr('sun.sun', 'elevation') | float %}
          {% set daystart = states('input_number.in_aalight_day') | float %}
          {% set nightstart = states('input_datetime.id_aalight_night') [0:5] %}
          {% set nightstart = '23:59' if nightstart == '00:00' else nightstart %}
          {% if '12:00' < nightstart <= '24:00' %}
            {% set r1 = time >= nightstart %}
            {% set r2 = elevation <= daystart and time < '12:00'%}
          {% else %}
            {% set r1 = false %}
            {% set r2 = elevation <= daystart and time >= nightstart %}
          {% endif %}
          {% set night = r1 or r2 %}
          {{ night }}

I’ve also thrown in the delay off timer script.
Note: you will have to create a LOT of input numbers to store the various levels
My day segments are driven by sun elevation and input datetime’s

1 Like

He asked for mine but I seriously think he would be better off with yours :rofl:

I also like the way you neatly avoided the gap in his timing request
Though yours will ONLY give him a brighness at the ‘switch on time’ and for it’s whole ‘on’ duration (which is where mine kinda grew from) :+1:

1 Like

You can do that a bit simpler:

      brightness: "{{ 100 if now().hour >= 13 else 30 }}"
1 Like

Nice :grinning: i tried with hour, but dumb me tried now().hour() for whatever reason. In general I still prefer multiline instead of single line templates, just find it easier to read and maintain.

I wanted to ask for the gap and then just ignored it :stuck_out_tongue:

I just provided an answer to his initial question, didn’t want to overwhelm him, as I assumed that he is a relatively new HA user.

I’m always amazed at what you (and the other usual suspects, you know which persons I’m talking about :laughing:) are doing with templates and automations and combinations of input_booleans, sensors and whatever, clever and elegant, you have my respect. When I started with home assistant, I tried some automations and at one point I got stuck and my code was getting more and more, for what I thought were really simple things. Then I discovered AppDaemon and said to myself “Screw this s***! Learn Python and do it with AppDaemon.” Ohh boy was this a good decision! Never looked back, now I’m only using automations in my Test environment (more of a “HA forum help environment” :rofl: set this up just to test code snippets from people looking for help, to not spam my prod or dev environment.).

Sorry OP for spaming your post with uninteresting blabla.

Ahhhh noooooo !
I am but a simple novice trying to emulate the ‘notables’ you refer to (they also are uncomfortable with any exceptional honorifics (it just sets them up for a fall) (we all put our pant legs on, one at a time (cept for Phil and Taras :rofl: )))

I just want to keep my install as ‘vanilla’ as possible and EVERYONE has to use yaml in somepart of their config. The overhead for nodered and appdaemon is horrendous.
And “IF” it can be done with native yaml, why not ?
flamingm0e (for example) is a flaming nodered zelot (no offence moe :rofl: ) but each to his own
It’s one of the beauties of HA

I’ll add my appologies to the OP too

@henaa , let us know if you got what you need, even if you just mark it as solved. If you have further questions/issues we’ll see what we can do

I must say I’m a huge AppDaemon fanboy :rofl: Can reload my automations without any HA restart, can reuse code, can do complex automations without any workarounds, almost no limitation, can use time travel to simulate events/automations and and and, you need to try it at some point :stuck_out_tongue_winking_eye: And now that we have HACS, I can even release my apps and people don’t need to know python, just some basic YAML for the config.