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