As @tom_I has stated you really need to format your automations. Yaml is very picky about format and without doing this it is hard for people to help you!
I modified this from what I do for my robot vac…
alias: Turn on and off lights
description: turn off and on lights
trigger:
- platform: time
at: '21:00:00'
- platform: time
at: '02:30:00'
condition: []
action:
- choose:
- conditions:
- condition: time
after: '21:00:00'
weekday:
- wed
- fri
- sat
before: '23:59:00'
sequence:
- type: turn_on
device_id: cf0b4ecc3f7da16788d36ba282f0452a
entity_id: switch.upstairs_light_inside
domain: switch
- conditions:
- condition: time
after: '02:30:00'
weekday:
- thu
- sat
- sun
before: '02:31:00'
sequence:
- type: turn_off
device_id: cf0b4ecc3f7da16788d36ba282f0452a
entity_id: switch.upstairs_light_inside
domain: switch
default: []
mode: single
you can make input variables that can substitute for the hard coded times and are set in the lovelace interface.
input_datetime:
up_light_start:
name: Upstairs Start Time
has_date: false
has_time: true
# initial: 21:59:00 # <- value is set if you want it to always reset to this value on reboot
up_light_end:
name: Upstairs End Time
has_date: false
has_time: true
# initial: 23:56:00
No, not the way it’s currently written. There needs to be an explicit service call to turn off the light but the automation only contains a service call to turn on the light. In addition, it triggers at 21:00 but the Time Condition checks if the current time is after 02:30. Naturally, the time can’t be after 02:30 if it just triggered at 21:00 so the automation’s action will never be executed.
You can’t test it in the Template Editor because the trigger variable only exists when an automation is triggered.
However, you can simulate it in the Template Editor like this:
{% set object_id = 'air_purifier_on' %}
switch.turn_{{ object_id.split('_')[2] }}
The split method transforms the string air_purifier_on
into a list containing three items ['air', 'purifier', 'on']
Lists are zero-indexed so the index of the last item in the list is 2