7 Day timer

I have had a play and designed a mqtt 7 day timer and using node red to enable a virtual switch

mqtt in retain false - cmnd/myhome/auto_lighting/hallway/switch
mqtt out retain true - state/myhome/auto_lighting/hallway/switch

step 1
add to config folder named " timer_motion_hallway.yaml"

#############################################################################################################################

####################################################################################################     INPUT SLIDERS  #####
##  START TIME ###################################################################
input_number:
    timer_1_start_hour:
        name: Hours
        icon: mdi:timer
        #initial: 6
        min: 0
        max: 23
        step: 1
    timer_1_start_minutes:
        name: Minutes
        icon: mdi:timer
        #initial: 30
        min: 0
        max: 59
        step: 1

  ##  FINISH TIME #################################################################
    timer_1_finish_hour:
        name: Hours
        icon: mdi:timer
        #initial: 6
        min: 0
        max: 23
        step: 1
    timer_1_finish_minutes:
        name: Minutes
        icon: mdi:timer
        #initial: 30
        min: 0
        max: 59
        step: 1

##  DAYS / WEEKENDS ##############################################################
input_boolean:
    timer_1_mon:
        name: Monday
        #initial: off
        icon: mdi:calendar
    timer_1_tue:
        name: Tuesday
        #initial: off
        icon: mdi:calendar
    timer_1_wed:
        name: Wednesday
        #initial: off
        icon: mdi:calendar
    timer_1_thu:
        name: Thursday
        #initial: off
        icon: mdi:calendar
    timer_1_fri:
        name: Friday
        #initial: off
        icon: mdi:calendar
    timer_1_sat:
        name: Saturday
        #initial: off
        icon: mdi:calendar
    timer_1_sun:
        name: Sunday
        #initial: off
        icon: mdi:calendar

##########################################################################################################################

####################################################################################################     SENSOR  #########
sensor:
##  START TIME ###################################################################
    - platform: template
      sensors:
         timer_1_start_time:
              friendly_name: 'Start Time'
              value_template: >-
                  {{ "%0.02d:%0.02d" | format(states("input_number.timer_1_start_hour") | int, states("input_number.timer_1_start_minutes") | int) }}

##  FINISH TIME #################################################################
    - platform: template
      sensors:
         timer_1_finish_time:
              friendly_name: 'Finish Time'
              value_template: >-
                  {{ "%0.02d:%0.02d" | format(states("input_number.timer_1_finish_hour") | int, states("input_number.timer_1_finish_minutes") | int) }}

switch:
  # Motion Hallway
    - platform: mqtt
      name: "Motion Hallway"
      state_topic: "state/myhome/auto_lighting/hallway/switch"
      command_topic: "cmnd/myhome/auto_lighting/hallway/switch"
    #  availability_topic: "tele/myhome/garden/hottub/4ch/LWT"
      qos: 2
      payload_on: "on"
      payload_off: "off"
    #  payload_available: "Online"
    #  payload_not_available: "Offline"
      retain: false

##########################################################################################################################

####################################################################################################     GROUPS  #########
#group:
#    timer_1:
#        name: Timer 1
#        entities:
#            - switch.motion_halway
#            - sensor.timer_1_start_time
#            - input_number.timer_1_start_hour
#            - input_number.timer_1_start_minutes
#            - sensor.timer_1_finish_time
#            - input_number.timer_1_finish_hour
#            - input_number.timer_1_finish_minutes
#            - input_boolean.timer_1_mon
#            - input_boolean.timer_1_tue
#            - input_boolean.timer_1_wed
#            - input_boolean.timer_1_thu
#            - input_boolean.timer_1_fri
#            - input_boolean.timer_1_sat
#            - input_boolean.timer_1_sun
#
##########################################################################################################################

####################################################################################################     AUTOMATION  #####
automation:
  ## START TIME MON ##########################################################   START
    - id: timer_1_on_mon
      alias: "start timer_1 mon"
      hide_entity: true
      trigger:
          - platform: time
            minutes: '/1'
            seconds: 0
      condition:
          - condition: state
            entity_id: input_boolean.timer_1_mon
            state: 'on'
          - condition: time
            weekday:
                - mon
          - condition: template
            value_template: '{{ now().strftime("%H:%M") == states.sensor.timer_1_start_time.state }}'

      action:
          - service: switch.turn_on
            data:
              entity_id:
                - switch.motion_halway

    ## START TIME TUE #######################################################
    - id: timer_1_on_tue
      alias: "start timer_1 tue"
      hide_entity: true
      trigger:
          - platform: time
            minutes: '/1'
            seconds: 0
      condition:
          - condition: state
            entity_id: input_boolean.timer_1_tue
            state: 'on'
          - condition: time
            weekday:
                - tue
          - condition: template
            value_template: '{{ now().strftime("%H:%M") == states.sensor.timer_1_start_time.state }}'

      action:
          - service: switch.turn_on
            data:
              entity_id:
                - switch.motion_halway

    ## START TIME wed #######################################################
    - id: timer_1_on_wed
      alias: "start timer_1 wed"
      hide_entity: true
      trigger:
          - platform: time
            minutes: '/1'
            seconds: 0
      condition:
          - condition: state
            entity_id: input_boolean.timer_1_wed
            state: 'on'
          - condition: time
            weekday:
                - wed
          - condition: template
            value_template: '{{ now().strftime("%H:%M") == states.sensor.timer_1_start_time.state }}'

      action:
          - service: switch.turn_on
            data:
              entity_id:
                - switch.motion_halway

    ## START TIME thu #######################################################
    - id: timer_1_on_thu
      alias: "start timer_1 thu"
      hide_entity: true
      trigger:
          - platform: time
            minutes: '/1'
            seconds: 0
      condition:
          - condition: state
            entity_id: input_boolean.timer_1_thu
            state: 'on'
          - condition: time
            weekday:
                - thu
          - condition: template
            value_template: '{{ now().strftime("%H:%M") == states.sensor.timer_1_start_time.state }}'

      action:
          - service: switch.turn_on
            data:
              entity_id:
                - switch.motion_halway

    ## START TIME fri #######################################################
    - id: timer_1_on_fri
      alias: "start timer_1 fri"
      hide_entity: true
      trigger:
          - platform: time
            minutes: '/1'
            seconds: 0
      condition:
          - condition: state
            entity_id: input_boolean.timer_1_fri
            state: 'on'
          - condition: time
            weekday:
                - fri
          - condition: template
            value_template: '{{ now().strftime("%H:%M") == states.sensor.timer_1_start_time.state }}'

      action:
          - service: switch.turn_on
            data:
              entity_id:
                - switch.motion_halway

    ## START TIME sat #######################################################
    - id: timer_1_on_sat
      alias: "start timer_1 sat"
      hide_entity: true
      trigger:
          - platform: time
            minutes: '/1'
            seconds: 0
      condition:
          - condition: state
            entity_id: input_boolean.timer_1_sat
            state: 'on'
          - condition: time
            weekday:
                - sat
          - condition: template
            value_template: '{{ now().strftime("%H:%M") == states.sensor.timer_1_start_time.state }}'

      action:
          - service: switch.turn_on
            data:
              entity_id:
                - switch.motion_halway

    ## START TIME sun #######################################################
    - id: timer_1_on_sun
      alias: "start timer_1 sun"
      hide_entity: true
      trigger:
          - platform: time
            minutes: '/1'
            seconds: 0
      condition:
          - condition: state
            entity_id: input_boolean.timer_1_sun
            state: 'on'
          - condition: time
            weekday:
                - sun
          - condition: template
            value_template: '{{ now().strftime("%H:%M") == states.sensor.timer_1_start_time.state }}'

      action:
          - service: switch.turn_on
            data:
              entity_id:
                - switch.motion_halway






    ##  FINISH TIME MON ########################################################   FINISH
    - id: timer_1_off_mon
      alias: "finish timer_1 mon"
      hide_entity: true
      trigger:
          - platform: time
            minutes: '/1'
            seconds: 0
      condition:
          - condition: state
            entity_id: input_boolean.timer_1_mon
            state: 'on'
          - condition: time
            weekday:
                - mon
          - condition: template
            value_template: '{{ now().strftime("%H:%M") == states.sensor.timer_1_finish_time.state }}'

      action:
          - service: switch.turn_off
            data:
              entity_id:
                - switch.motion_halway

    ## FINISH TIME TUE #######################################################
    - id: timer_1_off_tue
      alias: "finish timer_1 tue"
      hide_entity: true
      trigger:
          - platform: time
            minutes: '/1'
            seconds: 0
      condition:
          - condition: state
            entity_id: input_boolean.timer_1_tue
            state: 'on'
          - condition: time
            weekday:
                - tue
          - condition: template
            value_template: '{{ now().strftime("%H:%M") == states.sensor.timer_1_finish_time.state }}'

      action:
          - service: switch.turn_off
            data:
              entity_id:
                - switch.motion_halway

    ##  FINISH TIME wed ########################################################   FINISH
    - id: timer_1_off_wed
      alias: "finish timer_1 wed"
      hide_entity: true
      trigger:
          - platform: time
            minutes: '/1'
            seconds: 0
      condition:
          - condition: state
            entity_id: input_boolean.timer_1_wed
            state: 'on'
          - condition: time
            weekday:
                - wed
          - condition: template
            value_template: '{{ now().strftime("%H:%M") == states.sensor.timer_1_finish_time.state }}'

      action:
          - service: switch.turn_off
            data:
              entity_id:
                - switch.motion_halway

    ##  FINISH TIME thu ########################################################   FINISH
    - id: timer_1_off_thu
      alias: "finish timer_1 thu"
      hide_entity: true
      trigger:
          - platform: time
            minutes: '/1'
            seconds: 0
      condition:
          - condition: state
            entity_id: input_boolean.timer_1_thu
            state: 'on'
          - condition: time
            weekday:
                - thu
          - condition: template
            value_template: '{{ now().strftime("%H:%M") == states.sensor.timer_1_finish_time.state }}'

      action:
          - service: switch.turn_off
            data:
              entity_id:
                - switch.motion_halway

    ##  FINISH TIME fri ########################################################   FINISH
    - id: timer_1_off_fri
      alias: "finish timer_1 fri"
      hide_entity: true
      trigger:
          - platform: time
            minutes: '/1'
            seconds: 0
      condition:
          - condition: state
            entity_id: input_boolean.timer_1_fri
            state: 'on'
          - condition: time
            weekday:
                - fri
          - condition: template
            value_template: '{{ now().strftime("%H:%M") == states.sensor.timer_1_finish_time.state }}'

      action:
          - service: switch.turn_off
            data:
              entity_id:
                - switch.motion_halway

    ##  FINISH TIME sat ########################################################   FINISH
    - id: timer_1_off_sat
      alias: "finish timer_1 sat"
      hide_entity: true
      trigger:
          - platform: time
            minutes: '/1'
            seconds: 0
      condition:
          - condition: state
            entity_id: input_boolean.timer_1_sat
            state: 'on'
          - condition: time
            weekday:
                - sat
          - condition: template
            value_template: '{{ now().strftime("%H:%M") == states.sensor.timer_1_finish_time.state }}'

      action:
          - service: switch.turn_off
            data:
              entity_id:
                - switch.motion_halway

    ##  FINISH TIME sun ########################################################   FINISH
    - id: timer_1_off_sun
      alias: "finish timer_1 sun"
      hide_entity: true
      trigger:
          - platform: time
            minutes: '/1'
            seconds: 0
      condition:
          - condition: state
            entity_id: input_boolean.timer_1_sun
            state: 'on'
          - condition: time
            weekday:
                - sun
          - condition: template
            value_template: '{{ now().strftime("%H:%M") == states.sensor.timer_1_finish_time.state }}'

      action:
          - service: switch.turn_off
            data:
              entity_id:
                - switch.motion_halway

step2
add to configuration.yaml

packages:
    timer_motion_hallway: !include timer_motion_hallway.yaml

step3
add to group.yaml

Automatic Lighting Timers:
  name: Automatic Lighting Timers
  control: hidden
  entities:
    - group.motion_hallway_group

motion_hallway_group:
  control: hidden
  name: Motion Hallway
  entities:
    - switch.motion_hallway
    - sensor.timer_1_start_time
    - input_number.timer_1_start_hour
    - input_number.timer_1_start_minutes
    - sensor.timer_1_finish_time
    - input_number.timer_1_finish_hour
    - input_number.timer_1_finish_minutes
    - input_boolean.timer_1_mon
    - input_boolean.timer_1_tue
    - input_boolean.timer_1_wed
    - input_boolean.timer_1_thu
    - input_boolean.timer_1_fri
    - input_boolean.timer_1_sat
    - input_boolean.timer_1_sun

hope this helps this people

1 Like

how does it look like in frontend?

The new Google clock apk works with Google assistant to activate times


Is there a way I can make it simple as having these timers under entity’s more info dialog? I would like to have my frontend as clean as possible without having too many timers showing. Reason being if I would make every switches and lights for an individual timer, thats gonna be a mess. Maybe if I do it under more info dialog box it would be less function as this, but as long it does the job, maybe I could figure out later

you can organise it from groups and then they are all hidden from main page

Hello

I do not understand why it does not work
have an error “Component not found: packages”

in config I wrote this

....................................
  # Customization file
  # customize: !include customize.yaml

packages:
   timer_motion_hallway: !include timer_motion_hallway.yaml

.......................................................

and i create a file:
timer_motion_hallway.yaml

in my .homeassistant

I’m new in home assistant can you help me?

Thanks

Best Regards

Hello everyone

Ok work perfect!!!
But with my version of home assistant i have an error. I corrected in this way
i add pattern in time= time_pattern
like this:

automation:
  ## START TIME MON ##########################################################   START
    - id: timer_1_on_mon
      alias: "start timer_1 mon"
      hide_entity: true
      trigger:
          - platform: time_pattern
            minutes: '/1'
            seconds: 0

I think you might like this :
Universal Persistent Timer
It can add a timer to anything including multiple scripts, lights etc. with separate start and stop actions, and will resume in the event of downtime and requires no programming skills once installed. All lights, switches etc can be accessed from auto populated lists; and you can specify days of the week, repetitions, intervals, and much more. Timers can be paused, backed up and give activation notifications etc.
https://youtu.be/rUeTIU1uAP0