hello need some help its all valid but doesn’t turn on and off in the allocated input time
`
id: alarm_1_on_weekend
alias: “start time 1 (weekend)”
trigger:
- platform: time
minutes: ‘/1’
seconds: 0
condition:
- condition: state
entity_id: input_boolean.alarm_1_weekend
state: ‘on’
- condition: time
weekday:
- sat
- sun
#- condition: template
# value_template: ‘{{ now().strftime("%H:%M") > states.sensor.alarm_1_start_time.state }}’
action:
- service_template: ‘{% if (states(’‘now().strftime("%H:%M")’’) | float)
>= (states(’‘states.sensor.alarm_1_start_time.state’’) | float)
<= (states(’‘states.sensor.alarm_1_finish_time.state’’) | float) %} switch.turn_on
{% else %} switch.turn_off {% endif %}’
data:
entity_id:
- switch.test
hide_entity: false
initial_state: ‘off’
`
finity
October 27, 2018, 9:58pm
2
You need to format your code properly per the instructions in the big blue box at the top of the page.
full yaml file
#############################################################################################################################
#################################################################################################### INPUT SLIDERS #####
## START TIME ###################################################################
input_number:
alarm_1_start_hour:
name: Hours
icon: mdi:timer
initial: 6
min: 0
max: 23
step: 1
alarm_1_start_minutes:
name: Minutes
icon: mdi:timer
initial: 30
min: 0
max: 59
step: 1
## FINISH TIME #################################################################
alarm_1_finish_hour:
name: Hours
icon: mdi:timer
initial: 6
min: 0
max: 23
step: 1
alarm_1_finish_minutes:
name: Minutes
icon: mdi:timer
initial: 30
min: 0
max: 59
step: 1
## DAYS / WEEKENDS ##############################################################
input_boolean:
alarm_1_weekday:
name: Weekdays
initial: off
icon: mdi:calendar
alarm_1_weekend:
name: Weekends
initial: off
icon: mdi:calendar
#alarm_2_weekday:
# name: Weekdays
# initial: off
# icon: mdi:calendar
#alarm_2_weekend:
# name: Weekends
# initial: off
# icon: mdi:calendar
##########################################################################################################################
#################################################################################################### SENSOR #########
sensor:
## START TIME ###################################################################
- platform: template
sensors:
alarm_1_start_time:
friendly_name: 'Start Time'
value_template: >-
{{ "%0.02d:%0.02d" | format(states("input_number.alarm_1_start_hour") | int, states("input_number.alarm_1_start_minutes") | int) }}
## FINISH TIME #################################################################
- platform: template
sensors:
alarm_1_finish_time:
friendly_name: 'Finish Time'
value_template: >-
{{ "%0.02d:%0.02d" | format(states("input_number.alarm_1_finish_hour") | int, states("input_number.alarm_1_finish_minutes") | int) }}
switch:
- platform: mqtt
name: "test"
state_topic: "/testing"
command_topic: "/cmnd/testing"
# availability_topic: "tele/myhome/garden/hottub/4ch/LWT"
qos: 1
payload_on: "1"
payload_off: "0"
# payload_available: "Online"
# payload_not_available: "Offline"
retain: true
##########################################################################################################################
#################################################################################################### GROUPS #########
group:
alarm_1:
name: Timer 1
entities:
- switch.test
- sensor.alarm_1_start_time
- input_number.alarm_1_start_hour
- input_number.alarm_1_start_minutes
- sensor.alarm_1_finish_time
- input_number.alarm_1_finish_hour
- input_number.alarm_1_finish_minutes
- input_boolean.alarm_1_weekday
- input_boolean.alarm_1_weekend
#alarm_2:
# name: Timer 2
# entities:
# - sensor.alarm_2_time
# - input_number.alarm_2_hour
# - input_number.alarm_2_minutes
# - input_boolean.alarm_2_weekday
# - input_boolean.alarm_2_weekend
##########################################################################################################################
#################################################################################################### AUTOMATION #####
automation:
## START TIME WEEKDAY ########################################################## START
- id: alarm_1_on_weekdays
alias: "start time 1 (week)"
trigger:
- platform: time
minutes: '/1'
seconds: 0
condition:
- condition: state
entity_id: input_boolean.alarm_1_weekday ####################### DONT TOUCH will be mon,tue,wed
state: 'on'
- condition: time
weekday:
- mon
- tue
- wed
- thu
- fri
#- condition: template
# value_template: '{{ now().strftime("%H:%M") > states.sensor.alarm_1_start_time.state }}'
action:
- service_template: '{% if (states(''now().strftime("%H:%M")'') | float)
> (states(''states.sensor.alarm_1_start_time.state'') | float) %} switch.turn_off
{% else %} switch.turn_on {% endif %}'
data:
entity_id:
- switch.test
hide_entity: false
initial_state: 'off'
# - event: alarm_1_event
# event_data:
# name: Alarm 1 on
# type: Weekdays
## START TIME WEEKENDS #######################################################
- id: alarm_1_on_weekend
alias: "start time 1 (weekend)"
trigger:
- platform: time
minutes: '/1'
seconds: 0
condition:
- condition: state
entity_id: input_boolean.alarm_1_weekend ####################### DONT TOUCH will be mon,tue,wed
state: 'on'
- condition: time
weekday:
- sat
- sun
#- condition: template
# value_template: '{{ now().strftime("%H:%M") > states.sensor.alarm_1_start_time.state }}'
action:
- service_template: '{% if (states(''now().strftime("%H:%M")'') | float)
>= (states(''states.sensor.alarm_1_start_time.state'') | float)
<= (states(''states.sensor.alarm_1_finish_time.state'') | float) %} switch.turn_on
{% else %} switch.turn_off {% endif %}'
data:
entity_id:
- switch.test
hide_entity: false
initial_state: 'off'
#event: alarm_1_event
#event_data:
# name: Alarm 1 on
# type: Weekends
## FINISH TIME WEEKDAYS ######################################################## FINISH
- id: alarm_1_off_weekdays
alias: "finish time 1 (week)"
trigger:
- platform: time
minutes: '/1'
seconds: 0
condition:
- condition: state
entity_id: input_boolean.alarm_1_weekday ####################### DONT TOUCH will be mon,tue,wed
state: 'on'
- condition: time
weekday:
- mon
- tue
- wed
- thu
- fri
- condition: template
value_template: '{{ now().strftime("%H:%M") == states.sensor.alarm_1_finish_time.state }}'
# >-##############################################
action:
- service: switch.turn_off
data:
entity_id:
- switch.test
# - event: alarm_1_off
# event_data:
# name: Alarm 1 off
# type: Weekdays
## FINISH TIME WEEKENDS #######################################################
- id: alarm_1_off_weekend
alias: "finish time 1 (weekend)"
trigger:
- platform: time
minutes: '/1'
seconds: 0
condition:
- condition: state
entity_id: input_boolean.alarm_1_weekend ####################### DONT TOUCH will be mon,tue,wed
state: 'on'
- condition: time
weekday:
- sat
- sun
- condition: template
value_template: '{{ now().strftime("%H:%M") == states.sensor.alarm_1_finish_time.state }}'
action:
- service: switch.turn_off
data:
entity_id:
- switch.test
#- event: alarm_1_off
# event_data:
# name: Alarm 1 off
# type: Weekends
tom_l
October 27, 2018, 11:02pm
4
service_template: '{% if (states(''now().strftime("%H:%M")'') | float)
>= (states(''states.sensor.alarm_1_start_time.state'') | float)
<= (states(''states.sensor.alarm_1_finish_time.state'') | float) %} switch.turn_on
{% else %} switch.turn_off {% endif %}'
First of all your logic might not be correct. You have now >= start <= end
. Pretty sure you want start <= now <= end
i.e. use the switch turn on service if the time is currently between the alarm start and end times.
Second you are converting your time strings like 23:45 to floating point. Pretty sure this won’t work. Try converting to timestamps then maybe floating point if required. Use the dev tools template editor to test. I don’t have access to mine at the moment so can’t do it for you.