How to add a time range to this automation

Hi,

  1. How to add a time range to this automation (6:00 to 20:00)(on), (20:00 to 6 off) ?
  2. Connect 2 automations to one ?
- id: '1596892163396'
  alias:  Hydro Garden NFT B auto on
  description: Tasmota 2
  trigger:
  - entity_id: switch.tasmota_2
    for: 0:30:00
    from: 'on'
    platform: state
    to: 'off'
  condition: []
  action:
  - device_id: 831fc1d4d8524948b8a02a0a63e5f499
    domain: switch
    entity_id: switch.tasmota_2
    type: turn_on


- id: '1594928190862'
  alias: Hydro Garden NFT B auto off
  description: 'Tasmota 2 '
  trigger:
  - entity_id: switch.tasmota_2
    for: 0:00:20
    from: 'off'
    platform: state
    to: 'on'
  condition: []
  action:
  - device_id: 831fc1d4d8524948b8a02a0a63e5f499
    domain: switch
    entity_id: switch.tasmota_2
    type: turn_off

Without fully understanding what you are trying to do, and scanning your automation, I believe the first one will turn the tasmota on when it’s been turned from on to off for 30 min, and the second turns it off, when it’s been turned from off to on for 20 seconds.

If you simply want to turn it on at 6am and off at 8pm, don’t use these. Create two new ones and trigger on time and use that to turn the switch on (or off).

Use time triggers, and then split the action with trigger.now.hour

Here is an example you could apply. Based on the hours of your trigger it Chooses one of two possible actions.

trigger:
  - platform: time
    at: "08:00:00"
  - platform: time
    at: "22:00:00"
action:
  choose:
    - conditions:
        - condition: template 
           value_template: >
             {{ trigger.now.hour == 8 }}
      sequence:
        - service:  light.turn_on
          entity_id: light.demo
    - conditions:
        - condition: template
          value_template: >
            {{ trigger.now.hour == 22 }}
      sequence:
        - service: light.turn_off
          entity_id: light.demo

If you wanted to integrate your previously written automations add two more - conditions: and use {{ trigger.to_state.state == 'on' }} or off respectively.

Although choose offers new flexibility, service_template still works well when there’s only a need to choose between services (and the service’s options remain the same).

trigger:
  - platform: time
    at: "08:00:00"
  - platform: time
    at: "22:00:00"
action:
  service_template: "light.turn_{{ 'on' if trigger.now.hour == 8 else 'off' }}"
  entity_id: light.demo
1 Like